免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1472 | 回复: 0
打印 上一主题 下一主题

[应用] 设计的程序在mini2440开发板执行,程序自行终止,这是为什么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-22 20:35 |只看该作者 |倒序浏览
本帖最后由 心染红尘 于 2015-04-22 20:35 编辑

设计的程序在mini2440开发板执行,程序自行终止,这是为什么?


程序如下:
  1. #ifndef MOTOR_H
  2. #define MOTOR_H

  3. #include<qobject.h>

  4. class Motor : public QObject
  5. {
  6.      Q_OBJECT

  7. public:
  8.    explicit Motor(QObject *parent=0);

  9. public:
  10.    int fd;
  11.    int on[3];

  12. public:
  13.    ~Motor();

  14. public:
  15.    void motor1_on();
  16.    void motor2_on();
  17.    void motor3_on();
  18.    void motor2_off();
  19. };

  20. #endif // MOTOR_H
复制代码

  1. #include"motor.h"

  2. #include<sys/types.h>
  3. #include<sys/stat.h>
  4. #include<fcntl.h>
  5. #include<stdio.h>
  6. #include<sys/ioctl.h>
  7. #include<stdlib.h>
  8. #include<unistd.h>

  9. Motor::Motor(QObject *parent):
  10.        QObject(parent)

  11. {
  12.        on[0]=0;
  13.        on[1]=0;
  14.        on[2]=0;


  15.        fd=open("/dev/motor",0);

  16.      if(fd<0)
  17.        {
  18.            perror("Error:fd<0");
  19.        }   

  20. }


  21. void Motor::motor1_on()
  22. {
  23.      on[0]=(~on[0])&1;
  24.      ioctl(fd,on[0],0);
  25. }

  26. void Motor::motor2_on()
  27. {
  28.      on[1]=(~on[1])&1;
  29.      ioctl(fd,on[1],1);
  30. }

  31. void Motor::motor3_on()
  32. {
  33.      on[2]=(~on[2])&1;
  34.      ioctl(fd,on[2],2);
  35. }

  36. void Motor::motor2_off()
  37. {
  38.      on[1]=(on[1])&1;
  39.      ioctl(fd,on[1],1);
  40. }


  41. Motor::~Motor()
  42. {

  43. }
复制代码
  1. /****************************************************************************
  2. ** Form interface generated from reading ui file 'motordialog.ui'
  3. **
  4. ** Created by User Interface Compiler
  5. **
  6. ** WARNING! All changes made in this file will be lost!
  7. ****************************************************************************/

  8. #ifndef MOTORDIALOG_H
  9. #define MOTORDIALOG_H

  10. #include <qvariant.h>
  11. #include <qwidget.h>

  12. #include "motor.h"

  13. #include <cstdlib>

  14. class QVBoxLayout;
  15. class QHBoxLayout;
  16. class QGridLayout;
  17. class QSpacerItem;
  18. class QPushButton;

  19. class motordialog : public QWidget
  20. {
  21.     Q_OBJECT

  22. public:
  23.     motordialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
  24.     ~motordialog();

  25.     QPushButton* pushButton1;
  26.     QPushButton* pushButton2;
  27.     QPushButton* pushButton3;
  28.     Motor* motor_PP;
  29.     Motor* motor_NP;
  30.     Motor* motor_SON;

  31. public slots:
  32.     virtual void motor_start();
  33.     virtual void motor_stop();
  34.     virtual void motor_exit();
  35.     virtual void motor_delay(int times);

  36. protected:

  37. protected slots:
  38.     virtual void languageChange();

  39. };

  40. #endif // MOTORDIALOG_H
复制代码
  1. /****************************************************************************
  2. ** Form implementation generated from reading ui file 'motordialog.ui'
  3. **
  4. ** Created by User Interface Compiler
  5. **
  6. ** WARNING! All changes made in this file will be lost!
  7. ****************************************************************************/

  8. #include "motordialog.h"

  9. #include <qvariant.h>
  10. #include <qpushbutton.h>
  11. #include <qlayout.h>
  12. #include <qtooltip.h>
  13. #include <qwhatsthis.h>

  14. /*
  15. *  Constructs a motordialog as a child of 'parent', with the
  16. *  name 'name' and widget flags set to 'f'.
  17. */
  18. motordialog::motordialog( QWidget* parent, const char* name, WFlags fl )
  19.     : QWidget( parent, name, fl )
  20. {
  21.     if ( !name )
  22.         setName( "motordialog" );
  23.     setMaximumSize( QSize( 240, 320 ) );

  24.     pushButton1 = new QPushButton( this, "pushButton1" );
  25.     pushButton1->setGeometry( QRect( 40, 60, 131, 31 ) );

  26.     pushButton2 = new QPushButton( this, "pushButton2" );
  27.     pushButton2->setGeometry( QRect( 40, 150, 131, 31 ) );

  28.     pushButton3 = new QPushButton( this, "pushButton3" );
  29.     pushButton3->setGeometry( QRect( 40, 240, 131, 31 ) );
  30.     languageChange();
  31.     resize( QSize(240, 320).expandedTo(minimumSizeHint()) );
  32.     clearWState( WState_Polished );

  33.     // signals and slots connections
  34.     connect( pushButton1, SIGNAL( clicked() ), this, SLOT( motor_start() ) );
  35.     connect( pushButton2, SIGNAL( clicked() ), this, SLOT( motor_stop() ) );
  36.     connect( pushButton3, SIGNAL( clicked() ), this, SLOT( motor_exit() ) );
  37. }

  38. /*
  39. *  Destroys the object and frees any allocated resources
  40. */
  41. motordialog::~motordialog()
  42. {
  43.     // no need to delete child widgets, Qt does it all for us
  44. }

  45. /*
  46. *  Sets the strings of the subwidgets using the current
  47. *  language.
  48. */
  49. void motordialog::languageChange()
  50. {
  51.     setCaption( tr( "MotorControl" ) );
  52.     pushButton1->setText( tr( "START" ) );
  53.     pushButton2->setText( tr( "STOP" ) );
  54.     pushButton3->setText( tr( "EXIT" ) );
  55. }

  56. void motordialog::motor_start()
  57. {
  58.     //qWarning( "motordialog::motor_start(): Not implemented yet" );
  59.     motor_SON->motor1_on();
  60.    // motor_NP->motor3_on();  
  61.     int m=10000;
  62.     while(m)
  63.        {
  64.            m--;
  65.            motor_PP->motor2_on();
  66.            motor_delay(1000);
  67.            motor_PP->motor2_off();
  68.            motor_delay(1000);
  69.        }   
  70. }

  71. void motordialog::motor_stop()
  72. {
  73.     //qWarning( "motordialog::motor_stop(): Not implemented yet" );
  74.      motor_SON->motor1_on();
  75.      motor_PP->motor2_off();   
  76. }

  77. void motordialog::motor_exit()
  78. {
  79.     //qWarning( "motordialog::motor_exit(): Not implemented yet" );
  80.      exit(0);
  81. }


  82. void motordialog::motor_delay(int times)
  83. {
  84.     int i;
  85.     int j;
  86.     for(i=0;i<times;i++)
  87.         {
  88.                 for(j=0;j<times;j++)
  89.                 {
  90.                 }
  91.         }
  92. }


复制代码
点击START,出现以下错误



IMG_20150422_183417.jpg (1.11 MB, 下载次数: 31)

程序界面

程序界面

IMG_20150422_183436.jpg (1.69 MB, 下载次数: 31)

点击后出现错误

点击后出现错误
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP