jcurl / RJCP.DLL.SerialPortStream

SerialPortStream is an independent implementation of System.IO.Ports.SerialPort and SerialStream for better reliability and maintainability. Default branch is 2.x and now has support for Mono with help of a C library.
Microsoft Public License
624 stars 197 forks source link

SerialPortStream.ReadLine() stops reading data #70

Closed bildsee closed 2 years ago

bildsee commented 5 years ago

My software reads from a device that permanently sends ASCII lines (CR+LF) at 4800,8N1 no flow control. So it basically executes a loop calling SerialPortStream.ReadLine() which works fine most of the time. However, sometimes ReadLine() fails and throws TimeoutException. This may be caused by the device and is not the actual problem. Is is also no problem if some lines get lost. The problem is that afterwards ReadLine() never returns data but always throws TimeoutException although the device continues to send (btw, the read timeout = 500ms). I found a workaround which 'fixes the stream' by reading some bytes via SerialPortStream.Read(byte[] buffer, int offset, int count) in case of TimeoutException. This call returns data and afterwards ReadLine() works as expected again. So I'd expect ReadLine() to return the next available line after it timed out.

jcurl commented 5 years ago

Thankyou. To get further to the root cause of the problem, could you please provide .NET traces enabling the ReadTo and the serial port traces? This may help me to identify where it's getting blocked.

jcurl commented 5 years ago

Hello, are you able to capture .NET traces of the error and attach them to the ticket? Please see https://github.com/jcurl/SerialPortStream/wiki/Tracing for information on how to do this.

bildsee commented 5 years ago

Thanks for your dedicate reply. I did not yet find the time to do so but I will check as soon as possible.

jcurl commented 5 years ago

Hello, have you found the time since reporting the issue to reproduce and to capture logs?

rquackenbush commented 5 years ago

My team is running into a similar problem. After a while (usually weeks), our process stops reading from devices. We're working on a repro, but it's difficult given how long it takes for the issue to manifest. Will report back as soon as we have something.

rwinscot commented 5 years ago

Experiencing a long-running issue on Linux as well... seems to work fine and then several days later reads start failing.

2018-12-17 17:11:26.3045 Error reading from serial port: System.ArgumentException: offset and count exceed buffer boundaries at RJCP.IO.Ports.SerialPortStream.ReadCheck(Byte[] buffer, Int32 offset, Int32 count) at RJCP.IO.Ports.SerialPortStream.Read(Byte[] buffer, Int32 offset, Int32 count

jcurl commented 5 years ago

Do you have logs captured that you can post?

jcurl commented 2 years ago

Closing this issue as there is no feedback and no further reports. Need a reproduction use case to understand the root cause.