I’m not sure if this would help, but last summer as I ran into problems with the Serial routine, I never had any issues with the Serial.Write function, but with the Read Line. If you read the communication on a byte by byte basis, it allows you to manual control what is considered a message.
Basically as bytes hit the serial port, I dump them into a buffer Array, and track how many bytes are in it. When a specified number of bytes are received (or timeout, or delimeter ect), I’d verify the CRC, (which makes it difficult to use a delimeter with the Read.Line function), then call a reinitialize to the array to all “0”, and reset the Index to 0. I apologize if it’s a bit crude, but it is functional, and doesn’t suffer from some of the limitations of the Read Line function,
I also suspect that I should have a loop included within the Try to keep reading until bytestoread=0 (to handle the condition where interrupts are disabled in another routine, and data builds up on the serial port), but given my application it’s been functional, and haven’t had time to do a cleanup.
Public Sub DataReceivedHandler(ByVal sender As Gadgeteer.Interfaces.Serial, ByVal data As IO.Ports.SerialData)
If rs232.serialPort.BytesToRead() > 32 Then 'Reset the Serial port, because unexpected data is in the buffer, as no command it will ever receive is greater than 32 bytes
intRecievedIndex = 0
Debug.Print(“bytes to read greater than 16”)
If rs232.serialPort.BytesToRead > 0 Then
bytRecievedData(intRecievedIndex) = CByte(rs232.serialPort.ReadByte)
intRecievedIndex = intRecievedIndex + 1
Catch ex As Exception
’ Code needs to be added here to decide when a full message has been received & reset the array index.
All, please remember that I’m not a professional programmer, but somebody who basically moves on as soon as I get a solution, and this does work.