Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT using Binary — Parallax Forums

SEROUT using Binary

mikeweezermikeweezer Posts: 27
edited 2005-01-13 19:59 in BASIC Stamp
Hello again everyone.

So I have a coding question. I am sending data through the serial port on my Board of Education (BS 2). This data needs to be in a Binary format. I am going to copy and paste the relevant stuff below, in addition to my somewhat close attempt at this. Also, I am under the assumption from the notes that I can send this data out of the same serial port that my Board of Education uses to receive code. Am I correct? Thanks Everyone!

My attempt:

SEROUT 16, 19200, [noparse][[/noparse]BIN ? 0xBE + 0xEF + 0x03 + 0x06 + 0x00 + 0x2A + 0xD3 + 0x01 + 0x00 + 0x00 + 0x60 + 0x00 + 0x00]

Some relevant information about this code:

- This code will be used to power on / off an LCD projector. A person at Hitachi was nice enough to forward me some of this stuff
- 19,200 bps
- 8bits data length
- no parity
- 1 stop bit

I'll copy and paste the code that works through HyperTerminal

Sending RS232C Command Using HyperTerminal

1. There are three sample files for sending RS232C command to the projector.
HTC Projector.ht :
HyperTerminal file that defined communication settings. This is for COM1 port configuration. If you need to change the port, please configure the properity setting.
PowerOn.bin :
Projector sample command for “Power On”. The “Power On” command consists of 13 bytes binary data ( i.e. 0xBE + 0xEF + 0x03 + 0x06 + 0x00 + 0xBA + 0xD2 + 0x01 + 0x00 + 0x00 + 0x60 + 0x01 + 0x00 ).
PowerOff.bin :
Projector sample command for “Power Off”. The “Power Off” command consists of 13 bytes binary data ( i.e. 0xBE + 0xEF + 0x03 + 0x06 + 0x00 + 0x2A + 0xD3 + 0x01 + 0x00 + 0x00 + 0x60 + 0x00 + 0x00 ).
The binary command files will be sent directly via HyperTerminal as following steps.

2. Connect your conputer with the projector using the appropriate cable.

3. Double click the file named “HTC Projector.ht”. Make sure the communication settings are correct. It should be 19,200bps baud rete, 8bits date length, no parity and 1 stop bit.

4. Send a sample binary file to your projector. Select “Transfer text file” menu, the file dialog will appear. Please select the binary command file “PowerOn.bin” or “PowerOff.bin”. The projector will respond to the command immediatelly.
of what he sent me below... This works when run through HyperTerminal.

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2005-01-13 01:06
    You need to be sure you connect both the Rx and Tx pins of your stamp board.· The stamp 'borrows' power from the Computers' Tx line to power it's own rs232.· (you'll need the ground too).· If you're not using a custom cable (and using a regular programming cable) then it'll probably work fine.

    You've got the pinout right in your serout line but you have to use the proper "baud value" for the baudrate you want to use.· simply typing in 19200 isn't going to work.· If you're using the BS2 then you'll need to use 16416 for your baud value.

    I'm honestly not sure about your output string.· not sure if they have to be separated by +'s or ,'s.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-13 04:15
    A couple things: the serial modifiers (BIN, HEX, DEC) actually convert values to text representations. So

    SEROUT Sio, Baud, [noparse][[/noparse]BIN 255]

    actually transmits "11111111"

    And Hex values in PBASIC don't use C notation -- where you're using 0xBE you should be using $BE

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-13 15:07
    Also, I don't think the '+' operator does string concatenation in PBasic. You probably want to replace the '+' character with a 'comma', which IS the parameter delimiter in PBasic.

    You are using port 16, which means you are using the built-in serial port, which means you MUST wire in both the TX AND RX pins insure you get a good RS-232 signal level.

    And the 'Baud' parameter is actually a 'Baud Select' parameter. Probably you want 'Inverted' + 19200 baud, so it should be something like 16348. See the manual under SEROUT for all your options, and the correct values.

    And yes, DO NOT use the 'BIN' modifier. The default output format of the BS2 IS 'binary' already. When you put in 'BIN', it actually converts your single byte binary value into a multi-byte text version.
  • mikeweezermikeweezer Posts: 27
    edited 2005-01-13 18:25
    Hello again,

    So after everyone's comments, I went to the Baud Rate conversion table and came up with 16416 - ( INT(1,000,000 - 19,200) = 52 - 20 = 32 + 16384 (inverted polarity) = 16416. Also, I am using the Board of Education Rev. B. Using my multimeter, I confirmed that Pin2 of the Serial is connected to SOUT (or Pin 16, I think), and that Pin 5 on the serial is connected to the ground. So I think all is well with that. I can't attach the .bin file for people to read (security in the forum), but below is the point at which my code stands now (not working yet). Thanks for your help!


    start:
    PAUSE 10000
    SEROUT 16, 16416, [noparse][[/noparse]$BE , $EF , $03 , $06 , $00 , $2A , $D3 , $01 , $00 , $00 , $60 , $01 , $00]
    PAUSE 10000
    GOTO start
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-13 19:59
    Very good, that should turn it on.

    You'll need to add a connection to Pin 3 of the DB-9 connector (connect to SIN). I assume your projector has a suitable TX signal? This is used by the BS2 RS232 circuit when it sends its signal on Pin 2.
Sign In or Register to comment.