Combining two discrete SERIN bytes
PKilbourn
Posts: 4
In my application, using SERIN, my BS2 is receiving two 8-bit bytes, for example "05" and "D0".· The serial sender convention is that a HEX (base 16) word is meaningful.· In this example, the sender wants me to receive 05D0, which equates to 1488.· I am trying to determine how PBasic can combine (convert?) the two bytes to a single base 16 byte.
I am using a simple SERIN command: SERIN RxDs, B2400, [noparse][[/noparse]char1, char2].
For information, the sender is a USDigital A2 optical encoder, being used to measure the angle of rotation of a rotating assembly.
I am using a simple SERIN command: SERIN RxDs, B2400, [noparse][[/noparse]char1, char2].
For information, the sender is a USDigital A2 optical encoder, being used to measure the angle of rotation of a rotating assembly.
Comments
This uses the first received byte as the high order 8 bits and the 2nd received byte as the low order 8 bits.
Obviously, if your data comes in the opposite order, reverse the items. You can then refer to the 16 bit
value as VALUE.
I don't know if it is the best way, but I found a way to make things work.· I took the first byte, took the last nib, and then shifted it left 8 bits.· I then XOR'ed it with the second byte.· For example, this took 05 and D5 to become 5D5, which I then assigned to a variable.· I'm happy; it worked.· Now I can proceed with the guts of the thing; making the algorithms work.
Thanks very much for the VALUE.HIGHBYTE and VALUE.LOWBYTE approach.· Far more simple than my work-around.· It worked fine and saved unnecessary lines of code.
Payne