天嵌 ARM开发社区

 找回密码
 注册
查看: 1867|回复: 7

请问tq2440怎样开多个串口

[复制链接]
xiaomingguo198 发表于 2013-5-17 18:02:14 | 显示全部楼层 |阅读模式
我的板子是tq2440,系统是linux,我想用qtopia做一个界面,但是需要用到两个串口,请问怎样把两个串口打开,需要开多线程吗?
TQ-lkp 发表于 2013-5-17 18:03:21 | 显示全部楼层
这个跟多个线程关系不大,打开两个串口,就调用 两次就行了,传递个串口名不就行了
 楼主| xiaomingguo198 发表于 2013-5-17 18:10:17 | 显示全部楼层
TQ-lkp 发表于 2013-5-17 18:03
这个跟多个线程关系不大,打开两个串口,就调用 两次就行了,传递个串口名不就行了

#if 1
        m_fd = openSerialPort_1();
        if (m_fd < 0)
                {
                QMessageBox::warning(this, tr("Error"), tr("Fail to open serial port1!"));
                return ;
                }
        m_notifier_1 = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
        connect (m_notifier_1, SIGNAL(activated(int)), this, SLOT(remoteDataIncoming_1()));
       // QMessageBox::warning(this, tr("Error"), tr("read"));
#endif
/////////////////////////////////////
#if 1

  connect (this, SIGNAL(close_signal()), this, SLOT(camara_quit()));
  connect (this, SIGNAL(quit_signal()), qApp, SLOT(quit()));
  connect (CloseButton, SIGNAL(clicked()), this, SLOT(camara_quit()));
  connect (SnapButton, SIGNAL(clicked()), this, SLOT(camara_snap()));

  timer = new QTimer(this); // 瀹氫箟QT瀹氭椂鍣&#65533;
  connect (timer, SIGNAL(timeout()), this, SLOT(showMe()));
  timer->start(FRAME_IDLE); // 寮&#65533;鍚?畾鏃跺櫒10ms瀹氭椂)
#endif
}
 楼主| xiaomingguo198 发表于 2013-5-17 18:11:19 | 显示全部楼层
上面代码,分别打开时对的,同时打开就不行了,求解~
 楼主| xiaomingguo198 发表于 2013-5-17 18:12:12 | 显示全部楼层
#if 1
/////////////////////////////////////////////////////////////////
        m_fd = openSerialPort();
                if (m_fd < 0)
                {
                QMessageBox::warning(this, tr("Error"), tr("Fail to open serial port2!"));
                return ;
                }
        m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
        connect (m_notifier, SIGNAL(activated(int)), this, SLOT(remoteDataIncoming()));
       // QMessageBox::warning(this, tr("Error"), tr("read"));
#endif
/////////////////////////////////////////////////////////////////////////////////////////
#if 1
        m_fd = openSerialPort_1();
        if (m_fd < 0)
                {
                QMessageBox::warning(this, tr("Error"), tr("Fail to open serial port1!"));
                return ;
                }
        m_notifier_1 = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
        connect (m_notifier_1, SIGNAL(activated(int)), this, SLOT(remoteDataIncoming_1()));
       // QMessageBox::warning(this, tr("Error"), tr("read"));
#endif
 楼主| xiaomingguo198 发表于 2013-5-17 18:12:58 | 显示全部楼层
对不起,一激动发错了,嘿嘿
是上面的两段代码
TQ-lkp 发表于 2013-5-17 18:23:20 | 显示全部楼层
亲,你能定义两个变量来保存fd吗,两个串口你用同一个变量怎么行?
 楼主| xiaomingguo198 发表于 2013-5-17 19:22:24 | 显示全部楼层
嘿嘿,调出来了,就是速度有些慢~谢谢您~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-30 07:28 , Processed in 1.023372 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表