Hi Chris,
I use serial in a project that has been in development for a number of years and it is operating on Mac, Pi and windows.
it is perfectly reliable and never misses a beat since the first time the code was written, it is extremely simple I have found.
I operate with 57600 baud, 8 N 1 without handshake.
my method relies on the hardware system I have sending data at a period (100ms) longer than the timer (20ms) used as the END of data packet signifier rather than looking for an end character in a random packet of data.
This method may not be as useful in some applications but It is very good as a start point and will work perfectly in the application you outline.
in the serial port ‘DataAvailable’ event:-
RXTimer(true)//start the RX data 20ms timer every time new data is seen, this is a single shot timer in MODE 'single' with a PERIOD of 20ms.
RxData=RxData+me.ReadAll()//load the received data int0 the app property
in the timer ‘Action’ event:-
if Len(RXData)>0 then
//do something with the data received, call a method that works on the data, do not handle the data here.
RXData=""//clear the property here so the next data packet can be created
end
That is basically all there is to the serial port part of the code, I do have a flag in my code that blocks the new data coming in until the current one has been serviced but thats not included here.
Also I am ONLY communicating in my system using ASCII therefore I will only ever need to work with UTF8 characters in the decimal range of 32 to 126.
As you have a line feed you will need to check the data for either a decimal 10 or 13, I use ‘ascb(some single data character)’ to convert the received data characters one by one to decimal values and if they are 10 or 13 I know its an EndOfLine (in my case).
A final thing is you mention the expected received data, depending on how you are viewing the data it may or may not make sense.
1.08481000E-04
In a HEX viewer it would be:-
31 2e 30 38 34 38 31 30 30 30 45 2d 30 34
at the end of the data you would have either 0a or 0d whichever is used as line feed.
Sorry if that is already known to you, but it is so easy to forget that data seen in the terminal application text field is not the raw data but the ASCII representation (usually) of that data, plus if you load the received data into a string in the ‘DataAvailable’ event and then print it to screen you will see ASCII characters which is going to confuse if not remembered.