Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21314

Parsing continuous stream of comma delimited serial data from com port

$
0
0
OK, I am about to give up on this common, seemingly trivial task. I've spent hours researching numerous serial port parsing threads using MSComm1 and commands; InStr, Mid$, Split and can't seem to get the job done with any confidence I am not losing serial data in the process.

Here is a summary: A microcontroller is monitoring the rotation of 2 asynchronous motor shafts and reports the time each one completes a revolution then sends the data to the serial port in the format: Shaft ID, Timer1 Overflow Count, Timer1 Value<CrLf> Where Shaft ID is the character W or E, Timer1 Overflow Count is an integer from 0 to 65535 and Timer1 Value is also an integer from 0 to 65535 used to calculate the event time knowing each Timer1 tick is 4us.

The data stream looks like this:

W,0,12199
E,0,15636
W,0,18078
W,0,53275
E,0,176
W,1,22932
E,1,50252
W,1,58130
W,2,27789
E,2,34818
W,2,62983
E,3,19358
.
.
.
W,65535,65535

Each serial message ends with <CrLf>. I tried using InStr, Mid$ and Split to parse the serial messages to detect shaft ID (W or E) then calculate the event time based on Timer1 OF count and Timer1 value (4us per tick) then store the value into a corresponding array W(t) or E(t) but believe I may be missing some incoming serial data while doing the parsing and/or calculations. The parsing is done in an Oncomm event subroutine along with the time calculation from the two values received and array storage W(t) or E(t). I don't know if all that is getting done fast enough before another serial message appears and triggers another Oncomm event. I don't know the dynamic behavior of the MSComm1.Input buffer while parsing is going on or what value to use for MSComm1.RThreshold should be; I tried 5 counting the two commas but not sure if I need to also include the <CrLf> characters since they are needed to separate messages; parsing is getting out of sync. Thanks in advance for helping me find the right way to reliably capture the serial data.

Viewing all articles
Browse latest Browse all 21314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>