简体   繁体   中英

wrong sequence of libserial received data

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) f unction, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM