0

how to send out strings via serial port with brightsign?



And, how to set the Baud rate, the parity bits and stop bits?

Thanks.

15 comments

  • 0
    Avatar
    eaglexp


    and, can we send HEX value via Com Port by pandora?
  • 0
    Avatar
    RokuAnthony


    eaglexp,



    To send a string out the serial port, use the BrightScript: "print" comand.  To send a non-ascii value, use the chr(value) function.  For example:



    Print "this string is going to the console which is the serial port"

    print chr(65);"B";chr(67)   ' prints "ABC"



    [edit:  I had stated that you must use a version of the software greater than 1.0.72, but this is incorrect.  This feature is in 1.0.72]



    To change the baud rate, use the roSerialControl object (or the shell cmd).  This object controls the RS232 port Baud Rate.  It has one interface:



    ifSerialControl

    • rotBOOL SetBaudRate(rotINT32 baud_rate)



    Supported baud rates are:



    1800,   2000,  2400,  3600,  4800,  7200, 9600,

    12800,  14400,  19200,  23040,  28800,  38400,  57600,

    115200



    Example:



    print "Attempting to change baud rate to 4800"

    baud=CreateObject("roSerialControl")

    if type(baud)<>"roSerialControl" then print "unexpected error!":stop

    okay = baud.SetBaudRate(4800)

    print "SetBaudRate(4800) returned: ";okay

    end
  • 0
    Avatar
    eaglexp


    if i want to send a HEX Number, like "4AH",

    how to write the scirpt then?



    Thanks.
  • 0
    Avatar
    RokuAnthony


    print chr(&H4A);



    The semicolon prevents a CR being appended to the output.



    For more info, look up the "print" and the "chr()" functions in the BrightScript Reference Manual which can be downloaded from the support section of our web site.



    anthony
  • 0
    Avatar
    eaglexp


    thanks, i'll try it later.
  • 0
    Avatar
    ikwildatjij


    Hi,



    I am trying to control my projector using the serialport on my hd2000.

    and i have to change the baudrate to 19200

    I tried the example in this topic but it does not work......



    This is in my autorun.bas at this time:



    serial = CreateObject("roSerialPort", 0, 19200)

    p = CreateObject("roMessagePort")

    serial.SetLineEventPort(p)

    serial_only:

    msg = wait(0,p) ' Wait forever for a message.

    if(type(msg) <> "roStreamLineEvent") goto serial_only 'Accept serial

    messages only.

    serial.SendLine(msg) ' Echo the message back to serial.





    print "attempting to turn the projector on"



    print chr(67);chr(48);chr(48)





    Can someone help me out? <!-- s:roll: --><img src="{SMILIES_PATH}/icon_rolleyes.gif" alt=":roll:" title="Rolling Eyes" /><!-- s:roll: -->
  • 0
    Avatar
    RokuTed


    ikwildatjij,



    In what way does your code not work? How are you testing it?



    Have you verified that your serial cable is functional by connecting it to your PC and running the shell?



    Also, I noticed that your code uses print statements after attempting to do serial communication. Please note that those print statements will go out the serial port and get sent to your projector.
  • 0
    Avatar
    RokuTed


    ikwildatjij,



    Let me add to the above post. If all that you are trying to do is to send the three bytes out to the projector, all you should need is the following code:



    serial=CreateObject("roSerialPort", 0, 19200)

    serial.SendBlock(chr(67) + chr(48) + chr(48))



    The first line sets the baud rate.

    The second line sends the characters.



    If you are not waiting for a response from the projector, you do not need to wait for events on the message port.
  • 0
    Avatar
    ikwildatjij


    Thx in advance Ted for a quick reply!



    I'll let you know asap.



    Greets ikwildatjij  <!-- s:o --><img src="{SMILIES_PATH}/icon_surprised.gif" alt=":o" title="Surprised" /><!-- s:o -->
  • 0
    Avatar
    RokuAnthony


    Note that to connect a BrightSign to a PC, you need to use a "null modem adaptor" which crosses the TX and RX lines.



    If you projector connects to a PC with a regular serial cable, then it will also connect to your BrightSign with a normal serial cable.  IE, the BrightSign serial port acts like a PC serial port.
  • 0
    Avatar
    ikwildatjij


    It does so that won't be any problem.

    Thx again ! If there's any progress i'll let u know.



    Greets Ikwildatjij
  • 0
    Avatar
    ikwildatjij


    I'm still trying to control my projector via a string through the serial port....



    Please advice me on the following.....



    in our last posts we discussed about sending strings out via the serial port and how to write it correctly in the script.



    if i put this (only this) in the autorun.bas :

    serial=CreateObject("roSerialPort", 0, 19200)

    serial.SendBlock (chr(67) + chr(48) + chr(48) + chr(13))

    my projector does not respond

    the string "C00" is send out... i checked this with a terminal program





    then we tried the following with the led test script :



    print "BrightSign Button-LED Test Running"

    p =   CreateObject("roMessagePort")

    tmr = CreateObject("roMessagePort")

    serial = CreateObject("roSerialPort",0,19200)  <<<-------------- IS ADDED

    gpio =  CreateObject("roGpioControlPort")  

    gpio.SetPort(p)

    sw = CreateObject("roGpioControlPort")   'switch/led control port

    sw.SetPort(p)

    LED1=2 ^ 17

    LED2=2 ^ 18

    LED3=2 ^ 19

    LED4=2 ^ 20

    LED5=2 ^ 21

    LED6=2 ^ 22

    dim idx(5):idx(0)=LED1:idx(1)=LED2:idx(2)=LED3:idx(4)=LED5:idx(5)=LED6



    event_loop:

    msg=wait(0, p)

    if type(msg)<>"roGpioButton" then event_loop

    butn = msg.GetInt()

    if butn > 5 then event_loop

    sw.SetOutputState(butn+17,1)

    print "Button Pressed: ";butn

    msg = wait (500, tmr)

    serial.SendBlock(chr(67) + chr(48) + chr(48) + chr(13))      <----is added

     

    sw.SetOutputState(butn+17,0)



    clear_events:

    msg=p.GetMessage():if type(msg)<>"rotINT32" then clear_events

    goto event_loop





    This projector should now send the same string on an button event (17)

    And this works!!! when i press button 17 the projector responds and turns on !!!!



    What is the difference between the two scripts?



    if i start to rem most of the lines to simplify the whole script and take out the whole button routine , the projector does not respond.

    Im going crazy on this now , i must understand....



    for example:

    REM print "BrightSign Button-LED Test Running"

    p =   CreateObject("roMessagePort")

    tmr = CreateObject("roMessagePort")

    serial = CreateObject("roSerialPort",0,19200)

    gpio =  CreateObject("roGpioControlPort")  

    gpio.SetPort(p)

    REM sw = CreateObject("roGpioControlPort")   'switch/led control port

    REM sw.SetPort(p)

    REM LED1=2 ^ 17

    REM LED2=2 ^ 18

    REM LED3=2 ^ 19

    REM LED4=2 ^ 20

    REM LED5=2 ^ 21

    REM LED6=2 ^ 22

    REM dim idx(5):idx(0)=LED1:idx(1)=LED2:idx(2)=LED3:idx(4)=LED5:idx(5)=LED6



    REM event_loop:

    REM msg=wait(0, p)

    REM if type(msg)<>"roGpioButton" then event_loop

    REM butn = msg.GetInt()

    REM if butn > 5 then event_loop

    REM sw.SetOutputState(butn+17,1)

    REM print "Button Pressed: ";butn

    REM msg = wait (500, tmr)

      serial.SendBlock(chr(67) + chr(48) + chr(48) + chr(13))

     

    REM sw.SetOutputState(butn+17,0)



    REM clear_events:

    REM msg=p.GetMessage():if type(msg)<>"rotINT32" then clear_events

    REM goto event_loop





    Please help.....



    Greets ikwildatjij <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: -->



    Greets Ronald
  • 0
    Avatar
    ikwildatjij


    serial = CreateObject("roSerialPort",0,19200)

    event_loop:

    serial.SendBlock(chr(67) + chr(48) + chr(48) + chr(13))

    goto event_loop





    with this in the autorun.bas my projector turns on
  • 0
    Avatar
    RokuLyndon


    I'll check on this...
  • 0
    Avatar
    RokuLyndon


    Ronald,



    Please try the following, so we can identify why this isn't working as expected:



    First:



    - try using Hyperterm or equivalent and just sending C00 to the

    projector. Does it work?

    - try sending C00 to the projector twice.

    - try simplifying the script that works to just include the print

    statement and the serial initialization and sendBlock.





    On the brightsign:



    Instead of sending characters in a loop, try just sending them twice. If that works try this:



    chr(13) + chr(67) + chr(48) + chr(48) + chr(13)
Please sign in to leave a comment.