Hi All,
I’m performing some test (cerberus and sdk beta 4.2) to send data over serial using usbSerial module. Provably i’m missing some thing, I’m using "DataReveived’ event, but the event only fires the first reception of data.
I don’t know if this is an unknow bug, or I need some aditional code.
My test code:
Thanks Architect,
I think the question are inside the small differences between System.IO.Ports.SerialPort from Framework and the GT.Interfaces.Serial
The ‘DataReceived’ Event in IO.Ports is fired every time when the buffer are incoming new bytes. Now I have understood “GT.Interfaces.Serial” only fires the event one time until the buffer becomes empty again.
I hope this help others like me.
to test you can simply use ‘echo response’
void SerialLine_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
{
int toRead = usbSerial.SerialLine.BytesToRead;
byte[] buffer = new byte[toRead];
usbSerial.SerialLine.Read(buffer, 0, toRead);
usbSerial.SerialLine.Write(buffer, 0, toRead); // echo the buffer
}
Yes, of course.
As a try explain, you must be carefull to read all bytes from buffer in every ‘DataReceived’ event, otherwise the handler is not firing a new event until the buffer is empty again.
Handling of data in the datarecieved event handler is a common source of confusion, great to hear you have it sorted.
My interpretation of the datarecieved event handler is always that you should de-queue all the data that you have and push it into your app for consumption elsewhere (which is why this event type isn’t always a good way to handle a serial port)