Shop OBEX P1 Docs P2 Docs Learn Events
Serial data Hex — Parallax Forums

Serial data Hex

Hi, I would like to send the following Hex data 01 04 01 05 00 01 5F 90 FB
I have tried SEROUT 16, 16468, [HEX "01 04 01 05 00 01 5F 90 FB",CR] but it is displayed on the debug screen as 301 04 01 05 00 01 5F 90 FB
Where has the extra 3 come from at the beginning?
And basically what am I doing wrong here?
Also whats the best way of receiving the reply which will be in the same format as the data sent?
Any help / pointers are welcome.

Thanks
Stuart

Comments

  • SEROUT 16, 16468, [ $01, $04, $01, $05, $00, $01, $5F, $90, $FB]

    The double quotes in your SEROUT cause the text within the quotes to be sent literally as given so "01" gets sent as an ASCII 0 character followed by an ASCII 1 character, not a byte with the value 1.

    The HEX converts the following byte values to hex (two ASCII characters per byte ... human readable).

    I'm not sure where the extra 3 came from. Maybe the HEX followed by a string confused the compiler.

    Are you sure this is what you want? The bytes you're sending will go out to the debug screen where they may be interpreted as control sequences. Are you attaching some non-display device to the debug serial port?
  • kwinnkwinn Posts: 8,697
    edited 2017-06-23 14:47
    Not sure what you are trying to do, but SEROUT or DEBUG send data out as text. Without seeing all the code I cannot be sure of what is happening but it may be that the "HEX" is being treated as a variable with a value of 3 and the "01" and the rest of the characters you want as hex are written immediately after that.

    You should read the "BASIC Stamp Architecture – Number Representations" chapter in the manual to understand the difference between decimal, binary, hex, and characters.

    Posting your code and an explanation of what you are trying to do will get you more help.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2017-06-23 16:30
    Do you want to send ASCII characters or raw data?
    Stuarttttt wrote: »
    Hi, I would like to send the following Hex data 01 04 01 05 00 01 5F 90 FB

    How many bytes of data should this be? 9 or 27(including the carriage return)?

    If you want to send raw data, you won't be able to view it well on the normal debug terminal. The ASCII character $5F (the underscore character) is the only printable character in the list.
    Stuarttttt wrote: »
    Also whats the best way of receiving the reply which will be in the same format as the data sent?

    What sort of device is sending the data

    I second kwinn's suggestion here:
    kwinn wrote: »
    You should read the "BASIC Stamp Architecture – Number Representations" chapter in the manual to understand the difference between decimal, binary, hex, and characters.

    I also suggest reading about ASCII characters on Wikipedia. (Mike Green's post also mentions ASCII.)

    Edit: If the protocol you want to use, doesn't use ASCII characters, then it is likely either always the same length or it includes a field to indicate the length of the message. Non-ASCII protocols also generally include some sort of check sum.

    Edit again: I just looked back as some of your earlier posts. Sorry for explaining basic stuff you likely already know.
  • Thanks for your replies,
    I have a 6 axis stepper controller, have a look here at a robotic arm I designed and programmed using the boards software



    However due to the stepper boards limited input functions I would like to interface a BS2 via RS-485 and therefore be able
    to use accelerometers, GP2D02 detectors, MakerPlot and other devices in my future robotic creations.

    This stepper board expects control data such as 01 04 01 05 00 01 5F 90 FB (each byte is an instruction) and replies with similar.
    When I set up the 485 data line properly and get it working and time allows I hope to be able to control the board from the BS2 using
    Hex but probably more meaningful ASCII mnemonics.

    That is what I am trying to achieve. I haven't used the BS2 for a while (a bit rusty :) and have forgotten more than I knew.
    Hence just asking for some advice.
  • Very cool arm!
    Stuarttttt wrote: »
    I have a 6 axis stepper controller

    What's the make and model of the controller?
    Stuarttttt wrote: »
    This stepper board expects control data such as 01 04 01 05 00 01 5F 90 FB (each byte is an instruction)

    So the above instruction is sent as nine bytes?

    If so then you want to send the raw data and not ASCII characters.

    I don't recall how to do this with a Basic Stamp but I'm sure someone around here could help you with the appropriate commands.

  • I don't think you can use any of the formatter such as HEX or BIN.

    What you can do is:
    serstr   VAR   Byte(9)
    serstr(0) = $01
    serstr(1) = $04
    serstr(2) = $01    'and so on
    SEROUT pin, baud, [STR serstr\9]
    
  • @stuarttttt,

    looks like you are deep into that meccano thing.

    wonderful. Arm and car are nicely made.

    Enjoy!

    Mike
  • Thanks Mike and Tom for your Hex suggestions, I'll give them a try.
    Duane, the stepper board is made by Trinamic and is model TMCM-6110

    Stuart
  • Stuarttttt wrote: »
    the stepper board is made by Trinamic and is model TMCM-6110
    Duane Degn wrote: »
    If the protocol you want to use, doesn't use ASCII characters, then it is likely either always the same length or it includes a field to indicate the length of the message. Non-ASCII protocols also generally include some sort of check sum.

    In case anyone else is interested, here's the download page for this particular driver.

    Page 11 of this pdf file indicate the binary protocol uses a 9 byte packet. The last byte of the packet is a check sum.

    You might run into some trouble using a Basic Stamp to control the device since (IIRC) the Basic Stamp doesn't have an UART buffer. I haven't used Basic Stamps enough to now if a BS is a good match for your project.

    Apparently the driver can be placed in ASCII mode which would allow you to control the device from a terminal program.






  • tomcrawfordtomcrawford Posts: 1,129
    edited 2017-06-26 20:55
    Basic stamp (even BS-2green) has a kinda buffer; the STR formatter reads a string into an array for subsequent processing.

    The problem is, when a SEROUT is followed by SERIN, it may not turn around quickly enough to capture the first character.

    The obvious solution to all such BS-2 problems is, of course, FLiP!
  • Update, this morning I received and hooked up my TTL to 485 converter and both methods suggested by Mike G and Tom C of sending Hex to the stepper module work. Thanks very much :)
    I now know the stepper module RS-485 interface actually works as wasn't sure if it was or not.
    I can send and receive Hex and ASCII commands to the module from HTerm (Hyperterminal type interface). Hopefully I will be able to get more meaningful ASCII commands sent from the BS2 working soon. Thanks again for your input. (I'll probably be back :)

    ' HEX control data to TMCM-6110 Stepper module (via TTL to RS-485)
    serstr VAR Byte(9)
    serstr(0) = $01
    serstr(1) = $04
    serstr(2) = $01
    serstr(3) = $05
    serstr(4) = $00
    serstr(5) = $01
    serstr(6) = $82
    serstr(7) = $B8
    serstr(8) = $46 'serSTR moves motor +99000 steps relatively

    MAIN:
    HIGH 0 'Tx enable DE/RE
    SEROUT 1, 84,[STR serstr\9]
    PAUSE 4000 'allow motor to reach posn

    SEROUT 1, 84, [$01, $04, $01, $05, $FF, $fe, $7d, $48, $cd] 'moves motor -99000 steps relatively
    PAUSE 4000 'allow motor to reach posn
    GOTO MAIN
  • Stuarttttt wrote: »
    Hopefully I will be able to get more meaningful ASCII commands sent from the BS2 working soon.

    Can you describe a bit what you want to do with the BS2 and the stepper controller?

    As Tom suggested, a Propeller might be a better fit for this project.

    I don't think the BS2 can monitor two serial lines at the same time so if you wanted the microcontroller to both listen to commands coming from the debug terminal and also want the microcontroller to listen to replies coming from the stepper controller, you might want to switch to a more powerful microcontroller.

  • Mike GreenMike Green Posts: 23,101
    edited 2017-06-27 21:10
    "I don't think the BS2 can monitor two" ...
    No question about it. The BS2 can't do two things at once without external hardware. In particular, there's no serial buffer so the BS2 can't listen to replies from the stepper controller and the debug port at the same time. It can't tranmit simultaneously either.

    ProteanLogic shows a serial buffer on their website (the RSB509C). I don't know if they still carry it, but with two of them you could monitor both serial ports with the Stamp polling the serial buffers for any input.
  • I can now control the stepper board using ASCII control RS-485 data from the BS2. (A few timing problems but seems OK now)
    Yes Mike, perhaps I'll just send ASCII Serout motor position commands using the BS2 and not listen to replies. I'll be getting feedback from other input devices to the BS2.
    Just gives a bit more flexibility as the stepper controller only has a few DI and DO and two AI (Or I could multiplex several AI's to the stepper board perhaps)

    "A Propeller might be a better fit for this project"
    Probably is but I have several BS2's and don't (at the moment) intend buying / learning yet another micro.

    Duane Degn wrote "Can you describe a bit what you want to do with the BS2 and the stepper controller?"
    Well....just hobby robotics, three are on Utube,
Sign In or Register to comment.