Shop OBEX P1 Docs P2 Docs Learn Events
Is it possible to send HEX bytes with BS1? — Parallax Forums

Is it possible to send HEX bytes with BS1?

FalconFalcon Posts: 191
edited 2012-09-08 05:09 in BASIC Stamp
I'm trying to send 7 HEX BYTES to a PTZ camera. I have this working with the BS2 with this code:
HIGH RS485_Out
PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
SEROUT SIO,baud,[$FF,$02,$00,$02,$00,$20,$24]    ' Id
LOW RS485_Out                                        ' Switch to receive mode.

However, I want to use the BS1. I adjusted the SEROUT statement format (parenthesis vs. Brackets) to this:
HIGH RS485_Out
PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
SEROUT SIO,baud,($FF,$02,$00,$02,$00,$20,$24)    ' Id
LOW RS485_Out                                         ' Switch to receive mode.

I the following note on page 415 of the Basic Stamp Manul:

"NOTE: The BS1's OutputData argument can only be a list of variables and the optional decimal modifier (#)."

Is there a work-arounf for this? Or do I have a formatting error?

Thanks,

falcon

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-07 17:55
    SEROUT SIO, baud, (65)
    SEROUT SIO, baud, ($41)

    are two ways to
    send out %01000001

    If the SERIN peripheral is set to interpret incoming data as ASCII characters, then the result is seen as an A.
    If the SERIN peripheral is set to cache incoming data as numeric, then it'll have got the value transmitted: %01000001.

    SEROUT SIO, baud, (#65)
    will end up with a 65 printed on the SERIN perpheral.

    Is that what you're driving at?
  • FalconFalcon Posts: 191
    edited 2012-09-07 18:09
    The camera requires Pelco-D over RS-485 and requires 7 HEX bytes. The fomat is here: PelcoD-protocol.pdf I'm using an SN75176 to convert to RS-485.

    I have simple pan and tilt control working with the BS2 but I can get no camera movement with the BS1 with this code:
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    
    INPUT 3                                           'Pan Left
    INPUT 4                                           'Tilt Down
    INPUT 5                                           ' Pan Right
    INPUT 6                                           'Tilt Up
    INPUT 7                                           'RCRX Input Pulse stream
    
                                                      ' Connection to RC RX
    SYMBOL   Zoom      = W1                           ' Word variable for pulsewidth
    SYMBOL   SIO       = 1
    SYMBOL   RS485_Out = 0
    SYMBOL   baud      = T2400
    
    
    
    
    ' WORD    1          2            3            4           5          6             7
    '       Sync      Address     Command 1   Command 2      Data 1     Data 2      Check Sum
    
    
    ' ------------------------------------------------------------------------------
    ' Initialization
    ' -------------------------------------------------------------------------------
    DEBUG "go", CR
    HIGH RS485_Out
    PAUSE 10                                           ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,T2400,($FF,$02,$88,$00,$00,$00,$8A)    ' Camera On
    PAUSE 10
    SEROUT SIO,T2400,($FF,$02,$00,$2B,$00,$00,$2D)    ' AutoFocus On
    PAUSE 10
    LOW RS485_Out                                         ' Switch to receive mode.
    DEBUG "Camera On", CR
    PAUSE 1000
    
    HIGH RS485_Out                                        'Stops any current movement
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,T2400,($FF,$02,$00,$00,$00,$20,$02)    ' Id
    LOW RS485_Out                                         ' Switch to receive mode.
    DEBUG "Stop", CR
    
    ' ------------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------------
    
    main:
    
      IF PIN3 = 0 THEN Pan_Left_Medium                 'Parallax 5-Position Switch
      IF PIN4 = 0 THEN Tilt_Down_Medium
      IF PIN5 = 0 THEN Pan_Right_Medium
      IF PIN6 = 0 THEN Tilt_Up_Medium
    PAUSE 10
    
     GOTO Main
    
    
    ' -------------
    ' Sub Routines
    ' -------------
    
    Pan_Right_Medium:
    DEBUG "Pan Right Medium", CR
    HIGH RS485_Out
    PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,baud,($FF,$02,$00,$02,$00,$20,$24)    ' Id
    
    LOW RS485_Out                                         ' Switch to receive mode.
    
    GOTO main
    
    
    Pan_Left_Medium:
    DEBUG "Pan Left Medium", CR
    HIGH RS485_Out
    PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,baud,($FF,$02,$00,$04,$00,$20,$26)    ' Id2
    LOW RS485_Out                                         ' Switch to receive mode.
    
    GOTO main
    
    
    Tilt_Up_Medium:
    DEBUG "Tilt Up", CR
    HIGH RS485_Out
    PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,baud,($FF,$02,$00,$08,$00,$20,$2A)    ' Id2
    LOW RS485_Out                                         ' Switch to receive mode.
    
    GOTO main
    
    
    Tilt_Down_Medium:
    DEBUG "Tilt Down", CR
    HIGH RS485_Out
    PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,baud,($FF,$02,$00,$10,$00,$20,$32)    ' Id
    LOW RS485_Out                                         ' Switch to receive mode.
    
    GOTO main
    
    
    Move_STOP:
    DEBUG "Stop", CR
    HIGH RS485_Out
    PAUSE 10                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT SIO,T2400,($FF,$02,$00,$00,$00,$00,$02)    ' Id
    LOW RS485_Out                                         ' Switch to receive mode.
    
    GOTO main
    
    
    
    
    
    
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-07 18:30
    Does your BS2 code use a True baudmode, too?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-07 18:35
    The BS1 SEROUT examples don't show a case actually using HEX ($), even though it compiles.

    What if you use decimal values instead?

    $FF,$02,$88,$00,$00,$00,$8A
    vs.
    255,2,136,0,0,0,138
  • FalconFalcon Posts: 191
    edited 2012-09-07 18:45
    Yes. Here is the BS2 code that works:

    [code]
    baud CON 396 ' 8 bit No Parity True 2400-baud serial baudmode.


    ]/code]
  • FalconFalcon Posts: 191
    edited 2012-09-07 18:47
    I had tried using the decimal numbers but that did not work.

    The code does compile, but the camera does not respond.

    falcon
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-07 18:56
    Too many numbers in one line?

    SEROUT SIO, baud, (255,2,136,0)
    SEROUT SIO, baud, (0,0,138)
  • FalconFalcon Posts: 191
    edited 2012-09-07 19:00
    PJ Allen wrote: »
    Too many numbers in one line?

    SEROUT SIO, baud, (255,2,136,0)
    SEROUT SIO, baud, (0,0,138)

    Got it!

    I found a wiring error. I had the BS2 mocked up on one breadboard and the BS1 on another. I must have pulled a wire when switching the programming cable back and forth.

    I appreciate your help.

    For the record, it did work with the one line of decimal numbers.

    Thanks,

    falcon
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-07 19:07
    Falcon wrote: »
    Got it!

    For the record, it did work with the one line of decimal numbers.

    Does that mean that using Hex notation is a No-Go?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-07 19:47
    Hex, binary, decimal, and character should be all the same. The BS1 compiler translates them all into binary constant values just like the BS2 compiler does.
  • FalconFalcon Posts: 191
    edited 2012-09-08 05:09
    PJ Allen wrote: »
    Does that mean that using Hex notation is a No-Go?

    It did also work with the HEX BYTES after the wiring error was corrected.

    I thought the BS1 could/should be able to send HEX BYTES. But I did run into a BS1 limitation on a previous project regarding a serial connection to an XBee so I thought this might be another. And that note in the BSM made me wonder.

    Thank you both for your help.

    falcon
Sign In or Register to comment.