Assume we have a sequence of bytes with header of ‘807F’ which is input to PC through RS232. for example “… 80 7F 4B 97 80 7F 21 3A 80 7F … ” in which “21 3A” is our data in bold package and 21 is MSB and 3A is LSB. how can we extract data from the sequence in DELPHI?
Share
How your data is stored is a bit unclear, but assuming it is stored in a
TBytesarray, here is some code to unpack the data:It will search for first excistance of the header $80 $7F and unpack the following two bytes into a
word. Do what you want with the word. The search then continues until the end of the input data array.Update:
It’s still unclear what you really want, but here is some code where data is coming to the procedure via an event.
Update 2:
By the look of the comments, it seems as though the data is coming as ascii characters.
Then the decoding procedure will look something like this (including a small test) :