Shop OBEX P1 Docs P2 Docs Learn Events
Sending HEX bytes — Parallax Forums

Sending HEX bytes

FranklinFranklin Posts: 4,747
edited 2007-03-02 16:43 in BASIC Stamp
I have a device that need to be communicated with in a specific format. To write data to a memory location I need to send (In the spacific case I'm trying to accomplish) three bytes of info, a hex 81, a hex 0 (I know, it's the same as a decimal or binary 0) and the conversion of an ascii "70" that I get from another serial port. I can get the data OK and if I do
DEBUG HEX 128, HEX 0, HEX 70

I see 80038 in the debug window but what I really need is the actual HEX bytes. What is it I need to do to get this?

Thanks,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

Post Edited (Franklin) : 2/27/2007 3:50:34 AM GMT

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-02-27 03:14
    If you need two characters, use HEX2.

    Can you show an example of exactly what the format is that is needed by your device?

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • FranklinFranklin Posts: 4,747
    edited 2007-02-27 03:48
    From the documentation:
    Sends objects from the device to SitePlayer. Write has a single byte of address covering object addresses of 0 to 255 (00FFh), WriteX has an eXtended address of two bytes or 0 to 65535 (0FFFFh). Various models of SitePlayer have various object memory block sizes. The smallest SitePlayer has 768 bytes of objects covering addresses 0 to 2FFh. The Write or WriteX command also contains the count of bytes to send from 1 to 16 within the command byte in the bottom 4 bits. Zero meaning one byte and 15 meaning 16 bytes. As an example, to send two bytes of the number 1023 (3FFh) to object location 47h the Write command is used:
    80h+2-1=81h |·47h |·0FFh |·03h
    Since the value of Write is 80h by adding the number 2 to it for the number of bytes you are sending then subtracting 1 which is the character offset, makes the command byte 81h.
    Hope that gives you a little more info in my case i need to send three bytes so I think I need to send 80h | 0h | 38h

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-27 04:13
    What you've described is not normally described as sending HEX bytes. You need to send 3 eight bit values. If you want to send a single byte "wrVal" to location "wrAdr", you'd use "SEROUT <pin>,<Baud>,[noparse][[/noparse]$80,wrAdr,wrVal]".
  • FranklinFranklin Posts: 4,747
    edited 2007-03-02 16:43
    OK, an update. Mike you were right, I was making too big a project of it. Your suggestion worked but I had other problems. First I was using a serin [noparse][[/noparse]WAIT("s"), speed,WAIT("c"),wind] and apparently the 9600 baud data was too fast for the commands to get variables that followed directly behind each other so I changed the order so it waited for the last variable then the second and lastly the first. this required three data strings but won't affect the results. Next the cable I was using to connect the two devices was not good so the results were flakey so I just hooked the two devices together at TTL levels and it started to work. Thanks all for the help. I hope I can someday return the favor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.