标题:如何在Qt中进行多串口接收数据编程
作者:4589512
日期:2013-12-27 10:04
内容:
大家好, 如何在QT中进行多个RS485口读数据,
#1 [lindabell 12-27 10:13]
RS485不就是串口吗
多个串口就可以了
#2 [realfan 12-27 12:47]
一个485口对应一个QSerialPort对象
最好用多线程方式读写
#3 [4589512 12-27 16:19]
#include "serialThread.h"
#include
#include "ui_serial.h"
#include "serial.h"
#include
int sendcount1=1;
QString GetHex="";
SerialThread::SerialThread(QString portName,BaudRateType baud, DataBitsType databits, ParityType parity, StopBitsType stopbits, FlowType flow, long timeout)
{
struct PortSettings ttySetting; // s3c2440--{BAUD115200,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,500};
myCom = new Posix_QextSerialPort(portName,ttySetting,QextSerialBase::Polling);
myCom->open(QIODevice::ReadWrite);//以可读写方式打开串口
myCom->setBaudRate(baud);
myCom->setDataBits(databits);
myCom->setParity(parity);
myCom->setStopBits(stopbits);
myCom->setFlowControl(flow);
myCom->setTimeout(timeout);}
//qDeb
#4 [4589512 12-27 16:24]
如果直接建立多一个线程来创建多一个QSerialPort对象,进行操作
eg:SerialThread::SerialThread1(QString portName,BaudRateType baud, DataBitsType databits, ParityType parity, StopBitsType stopbits, FlowType flow, long timeout)
{struct PortSettings ttySetting; // s3c2440--{BAUD115200,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,500};
myCom1 = new Posix_QextSerialPort(portName,ttySetting,QextSerialBase::Polling);
myCom1->open(QIODevice::ReadWrite);//以可读写方式打开串口
myCom1->setBaudRate(baud);
myCom1->setDataBits(databits);
myCom1->setParity(parity);
myCom1->setStopBits(stopbits);
myCom1->setFlowControl(flow);
myCom1->setTimeout(timeout);} 就可以了吧
#5 [4589512 02-27 17:33]
还是搞不定多串口接收数据编程,希望大家给点思路