10 Qter豆
小弟新人,使用Qt serialPort遇到问题,跪求大神指点~~~
问题如下:
外设每2ms左右产生一个数据包(400Byte),通过串口向PC不停发送(波特率460800,1bit stop bit,无校验位),这样每个数据包产生+发送时间大概11ms左右。
PC侧功能如下:
connect(seriPort, SIGNAL(readyRead(), this, SLOT(mySlot()));
QTime time;
int cnt = 0;
mySlot()
{
QByteArray data = seriPort->read(400);
qDebug() << cnt++ << data.length() << time.restart(); // 输出计数,数据长度,距上次零点流逝的时间ms
}
time是QTime类型全局变量。mySlot()把当前时间设为零点,并输出据上次零点逝去的时间,我就是想看看pc侧每次接收400字节数据花费多长时间......当然,期望值肯定是11ms左右。
然后问题来了,实际运行结果是酱婶的:
....
1777 400 86
1778 400 1
1779 400 0
1780 400 1
1781 400 0
1782 400 0
1783 400 0
1784 400 1
1785 400 86
1786 400 1
1787 400 0
1788 400 0
1789 400 0
1790 400 0
1791 400 0
1792 400 0
...
尝试seri->setReadBufferSize(400);也没有效果
跪求:
1)为什么时间不是均匀的11ms,而是86 1 0 1 0 0 0 1这种东东?
2)如何实现均匀的11ms,即,想每次读400Byte用11ms。怎么破??
急等.....
我来回答