标题:请教大神串口通信问题??
作者:yousuozi
日期:2014-06-24 15:24
内容:
请问qt 串口编程使用的第三方类支持/dev/ttymxc4这样的串口名么???
运行时明明显示打开串口成功,但是数据发送不出去呢??
我查看了下开发板上/dev下的串口节点时间,这个/dev/ttymxc4节点每次都是运行完qt程序新建的囧。。。所以我在程序中试着打开一个不存在的串口ttymxc5,竟然也成功了= =。。。。。在开发板/dev下也出现了个ttymxc5的节点!!
所以我觉得,程序是不是压根就没有和硬件联系上,根本就没有打开板子上的串口啊?? 但是程序就是照着范例写的啊 应该木有问题把。。。
请各位大神指教
#include "widget.h"
#include "ui_widget.h"
#include "posix_qextserialport.h"
#include
#include
#include "qextserialbase.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);//shun xu cuo le rong yi fa sheng duan cuo wu
// QString portname = ui->portnamelineEdit->text();
//QString portname="ttymxc4";
//myCom = new Posix_QextSerialPort(portname,QextSerialBase::Polling);
myCom=new Posix_QextSerialPort("/dev/ttymxc4",QextSerialBase::Polling);
isOpen=myCom->open(QIODevice::ReadWrite);
if(!isOpen)
{
QMessageBox::critical(this,tr("open failure"),tr("can not open serial")+"/dev/ttymxc4"+tr("\n this device may not exsit or has been used"),QMessageBox::Ok);
//ui->portnamelineEdit->setText("open"+portname+"successed!");
}
myCom->setBaudRate(BAUD115200);
myCom->setDataBits(DATA_8);
myCom->setParity(PAR_NONE);
myCom->setStopBits(STOP_1);
my ..
#1 [xnlengao 06-24 17:42]
最终还是要跟硬件的串口匹配才行~
#2 回 xnlengao 的帖子 [yousuozi 06-24 20:09]
xnlengao:最终还是要跟硬件的串口匹配才行~ (2014-06-24 17:42)
是的 硬件的串口就是ttymxc4...
直接用echo命令 写ttymxc4串口终端那边有接收
但运行这个qt程序就不行了
#3 [xnlengao 06-25 09:51]
你完整程序就是这样了么?你的sendMyCom()函数呢?如果硬件上没问题 检查一下程序吧~换方法在写一下测试程序~利用linux C写一个也很简单的~
#4 回 xnlengao 的帖子 [yousuozi 06-26 10:35]
xnlengao:你完整程序就是这样了么?你的sendMyCom()函数呢?如果硬件上没问题 检查一下程序吧~换方法在写一下测试程序~利用linux C写一个也很简单的~ (2014-06-25 09:51)
void Widget::sendMyCom()
{
ui->sendlineEdit->setText("12345678");
myCom->write(ui->sendlineEdit->text().toAscii());
}
这样写有问题么??
不知道发不出去是发送函数的问题 是串口的问题 还是调用第三类库不成功的问题囧。。。。
#5 回 xnlengao 的帖子 [yousuozi 06-26 10:38]
xnlengao:你完整程序就是这样了么?你的sendMyCom()函数呢?如果硬件上没问题 检查一下程序吧~换方法在写一下测试程序~利用linux C写一个也很简单的~ (2014-06-25 09:51)
可以直接用C写么?? 怎么在qt中调用c程序??