I have an application built with .net core and raspberry pi (compute module 4) with raspberry pi OS. I have two threads, each one responsible for receiving data of (200 bytes) from different USB port every 0.5 millisecond. When only one thread is working, everything is OK, but when two threads are working together this gives me exception while reading from serial buffer, which cause losing in data.
Are there any limits for Linux USB buffers? Or there is another concern should be considered for this practice? Or there is any memory issue?
Code of Receiving:
try
{
int availableBytes = serialPort.BytesToRead;
if (availableBytes > 0)
{
byte[] receivedBytes = new byte[availableBytes];
serialPort.Read(receivedBytes, 0, receivedBytes.Length);
return receivedBytes;
}
}
catch (Exception ex)
{
}
Exception:
- Error Exception Message : The operation has timed out.
- Exception StackTrace : at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout) at System.IO.Ports.SerialPort.Read(Byte[] buffer, Int32 offset, Int32 count) at MainBoardSW.HAL.Serial.UsbDriver.ReadAvailableData() in F:\MainBoardSW\HAL\Serial\UsbDriver.cs:line 126
Thank you .