0

Serial control in .csv file?



In a .csv file, instead of looking for GPIO buttons inputs, can you tell it to look for a serial command input? I'm using a crestron currently to act as GPIO but have run out of ports. Need to play 9 different clips and if it will accept the command from the serial, that would help.

Working on custom script as well, but seem to be in over my head, and a .csv file would be easier to use.

12 comments

  • 0
    Avatar
    RokuLyndon


    The csv file doesn't currently look for serial input, so it would have to be a custom script.



    What exactly are you trying to do? Please provide as much detail as possible.



    I'm not sure where you're having trouble with the custom script, but here's a little info about using the serial port.



    Creating Objects & Initializing message port

    ----------------------------------------------------------------

    video=CreateObject("roVideoPlayer")

    serial=CreateObject("roSerialPort", 0, 9600) 'this assumes the rate is 9600

    p=CreateObject("roMessagePort")

    video.SetPort(p)

    serial.SetLineEventPort(p)





    SetLineEvent assumes the brightsign will be receiving a string. You could also use "SetByteEventPort", to trigger action based a byte received.





    Playing the Video

    ----------------------------

    wait_for_serial:

    msg=wait(0,p) 'waiting indiefinitely for an event

    if (type(msg<>"roStreamLineEvent")) goto wait_for_serial

    video.PlayFile("video.mpg")



    Page 16 of the object reference shows sample code playing a video clip, and checking for the video end event. Page 28 covers the serial object, and shows how to send serial output.







    You can find more information about scripting in the object reference guide for the brightsign.



    <!-- m --><a class="postlink" href="http://www.roku.com/products/brightsign/documents/HD2000ObjectReferenceManualv2.pdf">http://www.roku.com/products/brightsign ... nualv2.pdf</a><!-- m -->
  • 0
    Avatar
    Jrich7


    This is the script I am attempting to use.  It is based on another I had though never was able to test  When I load this it up, nothing happens.  The unit just remains black and shows firmware.  Am I overlooking something, or is the script just off:







    REM **********************************************************

    REM Initialize Objects

    REM ******************************************************

    REM Initialize Video & Button

       video=CreateObject("roVideoPlayer")

       image=CreateObject("roImagePlayer")

       mode=CreateObject("roVideoMode")

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

       p=CreateObject("roMessagePort")

       vid.SetPort(p)

       serial.SetLineEventPort(p)

      video.SetAudioOutput(2)

      audio.SetAudioOutput(2)





    REM **********************************************************

    REM Set Constants

    REM *********************************************************

    imagemode=1

    videomode$="1920x1080x60i"





    REM

    REM *************************************

    REM File Names

    REM *************************************

    REM



    main$="intro.bmp"

    one$="movie1.mpg"

    two$="movie2.mpg"

    three$="movie3.mpg"

    four$="movie4.mpg"

    five$="movie5.mpg"

    six$="movie6.mpg"

    seven$="movie7.mpg"

    eight$="movie8.mpg"

    nine$="movie9.mpg"



    vid_to_play$=""



    vid_playing=false





    rem ---------------------------------

    mode.SetMode(videomode$)  

    image.SetDefaultMode(imagemode)







    REM Start Demo ------------------------------------------

    REM Image plays first, and waits for input



    intro:

    image.DisplayFile(main$)





    REM Now we wait for a serial command

    wait_for_serial:

    msg=wait(0, p)



    if type(msg)<>"roStreamLineEvent" then goto wait_for_serial_only



    if type(msg)=main$ then

    goto intro



    else if serial = one$ then

    vid_to_play$=one$

    goto Play_File



    else if type(msg)=two$ then

    vid_to_play$=two$

    goto Play_File



    else if type(msg)=three$ then

    vid_to_play$=three$

    goto Play_File



    else if type(msg)=four$ then

    vid_to_play$=four$

    goto Play_File



    else if type(msg)=five$ then

    vid_to_play$=five$

    goto Play_File



    else if type(msg)=six$ then

    vid_to_play$=six$

    goto Play_File



    else if type(msg)=seven$ then

    vid_to_play$=seven$

    goto Play_File



    else if type(msg)=eight$ then

    vid_to_play$=eight$

    goto Play_File



    else if type(msg)=nine$ then

    vid_to_play$=nine$

    goto Play_File



    endif



    endif





    Play_File:

    vid_playing=true

    vid.PlayFile(vid_to_play$)



    wait_for_video_end:

    msg=wait(0,p)



    if type(msg)="roVideoEvent" then

    status=msg.GetInt()

    if status <> vidend then goto wait_for_video_end

    vid_playing=false

    goto intro



    endif

    return
  • 0
    Avatar
    Jrich7


    Spent the weekend trying various forms of the two programs above.  I was not able to get the program you posted to work either.  I sending strings from a creston in hex format.  Is this where my problem is.  Where would I designate what the incoming string is?  The object reference said something about serial.seteol, tried that, but nothing happened.



    Thanks.
  • 0
    Avatar
    RokuLyndon


    The script works when I use my pc to send the strings to the brightsign. I've modified it to output what it receives from the crestron over the serial port to the screen, for the first 3 videos.



    debug=false



    REM **********************************************************

    REM Initialize Objects

    REM ******************************************************

    REM Initialize Video & Button



    vid=CreateObject("roVideoPlayer")

    image=CreateObject("roImagePlayer")

    mode=CreateObject("roVideoMode")

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

    p=CreateObject("roMessagePort")

    vid.SetPort(p)

    serial.SetLineEventPort(p)

    vid.SetAudioOutput(2)



    REM **********************************************************

    REM Set Constants

    REM *********************************************************



    imagemode=1

    videomode$="1920x1080x60i"





    REM******************************************

    REM Text object for error output to screen

    REm ******************************************

    REM Metadata for other text

    meta2 = CreateObject("roAssociativeArray")

    meta2.AddReplace("CharWidth", 22)

    meta2.AddReplace("CharHeight", 35)

    meta2.AddReplace("BackgroundColor", &H000000) ' Black

    meta2.AddReplace("TextColor", &HFF0000) ' Red

    tf2 = CreateObject("roTextField", mode.GetSafeX(), mode.GetSafeY()+568, 40, 5, meta2)









    REM

    REM *************************************

    REM File Names

    REM *************************************

    REM



    main$="intro.bmp"

    one$="movie1.mpg"

    two$="movie2.mpg"

    three$="movie3.mpg"

    four$="movie4.mpg"

    five$="movie5.mpg"

    six$="movie6.mpg"

    seven$="movie7.mpg"

    eight$="movie8.mpg"

    nine$="movie9.mpg"



    vid_to_play$=""



    vid_playing=false



    REM

    REM *************************************

    REM File Names hex

    REM *************************************

    REM



    oneh$="\x6F\x6E\x65\x0D\x0A"

    twoh$="\x74\x77\x6F\x0D\x0A"

    threeh$="three \0D\x0A"

    fourh$="four"

    fiveh$="\x66\x69\x76\x65"

    sixh$="\x73\x69\x78"

    sevenh$="\x73\x65\x76\x65\x6E"

    eighth$="\x65\x69\x67\x68\x74"

    nineh$="\x6E\x69\x6E\x65"



    rem ---------------------------------



    mode.SetMode(videomode$)

    image.SetDefaultMode(imagemode)



    REM Start Demo ------------------------------------------

    REM Image plays first, and waits for input



    intro:

    image.DisplayFile(main$)



    REM Now we wait for a serial command



    wait_for_serial:

    msg=wait(0, p)



    if type(msg)<>"roStreamLineEvent" then goto wait_for_serial



    if msg=main$ then

    goto intro



    else if msg = oneh$ then

    if debug print #tf2, oneh$

    msg=wait(3000, p)  'wait 3 seconds for message to dispaly onscreen before playing file

    vid_to_play$=one$

    goto Play_File



    else if msg=twoh$ then

    if debug print #tf2, twoh$

    msg=wait(3000, p)  

    vid_to_play$=two$

    goto Play_File



    else if msg=threeh$ then

    if debug print #tf2, threeh$

    msg=wait(3000, p)  

    vid_to_play$=three$

    goto Play_File



    else if msg=fourh$ then

    vid_to_play$=four$

    goto Play_File



    else if msg=fiveh$ then

    vid_to_play$=five$

    goto Play_File



    else if msg=sixh$ then

    vid_to_play$=six$

    goto Play_File



    else if msg=sevenh$ then

    vid_to_play$=seven$

    goto Play_File



    else if msg=eighth$ then

    vid_to_play$=eight$

    goto Play_File



    else if msg=nineh$ then

    vid_to_play$=nine$

    goto Play_File



    endif



    Play_File:

    vid_playing=true

    vid.PlayFile(vid_to_play$)



    wait_for_video_end:

    msg=wait(0,p)



    if type(msg)="roVideoEvent" then

    status=msg.GetInt()

    if status <> vidend then goto wait_for_video_end

    vid.StopClear()

    vid_playing=false

    endif

    goto intro
  • 0
    Avatar
    rcmaples


    What does the command you're sending to the Roku look like coming from the PC?



    Are you using hyperterminal to communicate?



    "RokuLyndon" wrote:

    The script works when I use my pc to send the strings to the brightsign. I've modified it to output what it receives from the crestron over the serial port to the screen, for the first 3 videos.

    debug=false

    REM **********************************************************
    REM Initialize Objects
    REM ******************************************************
    REM Initialize Video & Button

    vid=CreateObject("roVideoPlayer")
    image=CreateObject("roImagePlayer")
    mode=CreateObject("roVideoMode")
    serial=CreateObject("roSerialPort", 0, 38400)
    p=CreateObject("roMessagePort")
    vid.SetPort(p)
    serial.SetLineEventPort(p)
    vid.SetAudioOutput(2)

    REM **********************************************************
    REM Set Constants
    REM *********************************************************

    imagemode=1
    videomode$="1920x1080x60i"


    REM******************************************
    REM Text object for error output to screen
    REm ******************************************
    REM Metadata for other text
    meta2 = CreateObject("roAssociativeArray")
    meta2.AddReplace("CharWidth", 22)
    meta2.AddReplace("CharHeight", 35)
    meta2.AddReplace("BackgroundColor", &H000000) ' Black
    meta2.AddReplace("TextColor", &HFF0000) ' Red
    tf2 = CreateObject("roTextField", mode.GetSafeX(), mode.GetSafeY()+568, 40, 5, meta2)




    REM
    REM *************************************
    REM File Names
    REM *************************************
    REM

    main$="intro.bmp"
    one$="movie1.mpg"
    two$="movie2.mpg"
    three$="movie3.mpg"
    four$="movie4.mpg"
    five$="movie5.mpg"
    six$="movie6.mpg"
    seven$="movie7.mpg"
    eight$="movie8.mpg"
    nine$="movie9.mpg"

    vid_to_play$=""

    vid_playing=false

    REM
    REM *************************************
    REM File Names hex
    REM *************************************
    REM

    oneh$="\x6F\x6E\x65\x0D\x0A"
    twoh$="\x74\x77\x6F\x0D\x0A"
    threeh$="three \0D\x0A"
    fourh$="four"
    fiveh$="\x66\x69\x76\x65"
    sixh$="\x73\x69\x78"
    sevenh$="\x73\x65\x76\x65\x6E"
    eighth$="\x65\x69\x67\x68\x74"
    nineh$="\x6E\x69\x6E\x65"

    rem ---------------------------------

    mode.SetMode(videomode$)
    image.SetDefaultMode(imagemode)

    REM Start Demo ------------------------------------------
    REM Image plays first, and waits for input

    intro:
    image.DisplayFile(main$)

    REM Now we wait for a serial command

    wait_for_serial:
    msg=wait(0, p)

    if type(msg)<>"roStreamLineEvent" then goto wait_for_serial

    if msg=main$ then
    goto intro

    else if msg = oneh$ then
    if debug print #tf2, oneh$
    msg=wait(3000, p)  'wait 3 seconds for message to dispaly onscreen before playing file
    vid_to_play$=one$
    goto Play_File

    else if msg=twoh$ then
    if debug print #tf2, twoh$
    msg=wait(3000, p)  
    vid_to_play$=two$
    goto Play_File

    else if msg=threeh$ then
    if debug print #tf2, threeh$
    msg=wait(3000, p)  
    vid_to_play$=three$
    goto Play_File

    else if msg=fourh$ then
    vid_to_play$=four$
    goto Play_File

    else if msg=fiveh$ then
    vid_to_play$=five$
    goto Play_File

    else if msg=sixh$ then
    vid_to_play$=six$
    goto Play_File

    else if msg=sevenh$ then
    vid_to_play$=seven$
    goto Play_File

    else if msg=eighth$ then
    vid_to_play$=eight$
    goto Play_File

    else if msg=nineh$ then
    vid_to_play$=nine$
    goto Play_File

    endif

    Play_File:
    vid_playing=true
    vid.PlayFile(vid_to_play$)

    wait_for_video_end:
    msg=wait(0,p)

    if type(msg)="roVideoEvent" then
    status=msg.GetInt()
    if status <> vidend then goto wait_for_video_end
    vid.StopClear()
    vid_playing=false
    endif
    goto intro

  • 0
    Avatar
    RokuLyndon


    Yes, I was using hyperterm. I used the send file command to send a text file that had one word in it.
  • 0
    Avatar
    rcmaples


    "RokuLyndon" wrote:


    REM******************************************
    REM Text object for error output to screen
    REm ******************************************
    REM Metadata for other text
    meta2 = CreateObject("roAssociativeArray")
    meta2.AddReplace("CharWidth", 22)
    meta2.AddReplace("CharHeight", 35)
    meta2.AddReplace("BackgroundColor", &H000000) ' Black
    meta2.AddReplace("TextColor", &HFF0000) ' Red
    tf2 = CreateObject("roTextField", mode.GetSafeX(), mode.GetSafeY()+568, 40, 5, meta2)




    Is there a similiar way to do this on a HD600? I noticed the use of roAssociativeArrary (HD2000 only...)
  • 0
    Avatar
    RokuLyndon


    Yes.



    THe code dealing with roAssociative array was just for printing output to the screen. You can pull any references to that, rotextfield, and any print #tf2 entries. And, the same code would work on the hd600. If you're testing via hyperterm, you'd then also change the baud rate to 9600.
  • 0
    Avatar
    travis


    Has anyone already modified autorun.bas to monitor the serial port and work with autoplay.csv instead of (or in addition to) the GPIO port?



    I'd like to be able to send a string over serial, something like "button:2", and have the state machine do the same thing it would if if button 2 on the GPIO were pressed.
  • 0
    Avatar
    RokuLyndon


    Travis,



    No, not yet, but you are the 3rd or 4th who have asked. I'll look into it this week. You want to send the whole command.



    What if the we just looked for a generic serial command, similar to how buttons work. For example button:0 looks input from 0.



    If we used something like serial:play, for example, then we'd be looking for the command "play" over the serial port. I'm not saying this is exactly how it might work, but what do you think of that implementation?
  • 0
    Avatar
    travis


    I don't want to be pushy about implementation. I just started looking into this thing yesterday and I'm not a very advanced programmer.



    I'm just trying to avoid building a cable and using up a bunch of the ports on my controller.
  • 0
    Avatar
    travis


    I have it working.  I modified the demo. Use HyperTerminal to send a text-file with nothing but 3(return) in it (or any other number)



    Here's the file:

    <!-- m --><a class="postlink" href="http://pastie.org/256767">http://pastie.org/256767</a><!-- m -->
Please sign in to leave a comment.