0

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;
dsolimano
  • 8,870
  • 3
  • 48
  • 63
ruhoo
  • 11
  • 2
  • After test, I find the problem only happens when I put the serial port read/write functions onto a boost thread. And it runs flawlessly when read/write inside the main thread. But I must use the a thread for it, any possible solution? – ruhoo Aug 01 '11 at 10:45

1 Answers1

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.

Chris Frederick
  • 5,482
  • 3
  • 36
  • 44
ruhoo
  • 11
  • 2