wrong sequence of libserial received data

自闭症网瘾萝莉.ら 提交于 2019-12-25 02:21:58

问题


I'm now working on a project which uses libserial for serial port communication under Ubuntu. we modified the libserial source code to allow MARK/SPACE parity. but when doing data receiving test, sometimes (about 5% chance) the incoming data sequence is wrong. The first byte can jump to the middle of the incoming buffer or even to the end.

The problem is inside the original SerialPort::SerialPortImpl::HandlePosixSignal( int singnalNumber) function, when the error happens it can not read some byte correctly and the error description is "Resource temporarily unavailable". But since it already get num_of_bytes_available using ioctl, how is it possible to fail?

during my test, I toggle between MARK/SPACE parity frequently. will that cause the problem?

the modified part in SetParity function

for **PARITY_SPACE**

port_settings.c_cflag |= CMSPAR | PARENB;

port_settings.c_cflag &= ~PARODD;

port_settings.c_iflag = 0;

for **PARITY_MARK**

port_settings.c_cflag |= CMSPAR | PARENB;

port_settings.c_iflag = 0;

回答1:


Okay, I finally figured out what was causing the problem. The libserial SerialPort class is not thread-safe. A POSIX signal probably conflicted with the boost thread. I was able to solve the problem by switching to the SerialStream class.



来源:https://stackoverflow.com/questions/6437306/wrong-sequence-of-libserial-received-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!