开发者

wrong sequence of libserial received data

开发者 https://www.devze.com 2023-03-14 09:53 出处:网络
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, som

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;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消