Shop OBEX P1 Docs P2 Docs Learn Events
Combining two discrete SERIN bytes — Parallax Forums

Combining two discrete SERIN bytes

PKilbournPKilbourn Posts: 4
edited 2009-04-08 15:20 in BASIC Stamp
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-07 20:07
    Declare a word variable, like VALUE. You can then write SERIN RxDs, B2400, [noparse][[/noparse] VALUE.HIGHBYTE, VALUE.LOWBYTE ]

    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.
  • PKilbournPKilbourn Posts: 4
    edited 2009-04-08 00:46
    Thank you, Mike, for digesting my concern, and crafting a reply.

    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.
  • PKilbournPKilbourn Posts: 4
    edited 2009-04-08 15:20
    Mike,

    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
Sign In or Register to comment.