0

Error in Scirpt

I hope someone can help.  There is an error in the following script but I can't seem to find it.  It loads, but as soon as I press a button on the GPIO I get the dreaded 10 flashes of the error light.

Thanks in advanced.

--Paul

 

Sub Main()

 

p = CreateObject("roMessagePort")

gpio = CreateObject("roGpioControlPort")

gpio.SetPort(p)

bcp = CreateObject("roControlPort", "BrightSign")

bcp.SetPort(p)

gpio.EnableInput(0)

gpio.EnableInput(1)

gpio.EnableInput(2)

gpio.EnableInput(3)

 

gpio.EnableOutput(4)

gpio.EnableOutput(5)

gpio.EnableOutput(6)

gpio.EnableOutput(7)

 

v = CreateObject("roAudioPlayer")

REM v.SetLoopMode(false)

REM v.SetVolume(100)

v.SetPort(p)

 

Main_Loop:

 msg = wait(0,p)   if type(msg) = "roroGpioBUtton"    

   if msg.GetInt() = 0 then

    A = 1     

    LEDA = 1    

else     

A = 0     

LEDA = 0   

 end if

   if msg.GetInt() = 1 then     

B = 2     

LEDB = 1    

else     

B = 0     

LEDB = 0   

 end if      

if msg.GetInt() = 2 then    

 C = 4     

LEDC = 1    

else     

C = 0     

LEDC = 0   

 end if

   if msg.GetInt() = 3 then   

  D = 8     

LEDD = 1   

 else     

D = 0     

LEDD = 0   

 end if   

end if

 song = A + B + C + D  

 gpio.SetOutputState(0,LEDA)

 gpio.SetOutputState(1,LEDB)  

gpio.SetOutputState(2,LEDC)  

gpio.SetOutputState(3,LEDD)

 if song <> 0 then 

  ok = v.PlayFile("\" + song + ".mp3")           

msg = wait(0,p)   

 if type(msg) = "roAudioEvent" and msg.GetInt() = 8     

 ok = v.StopClear()      

gpio.SetOutputState(0,0)     

 gpio.SetOutputState(1,0)     

 gpio.SetOutputState(2,0)     

 gpio.SetOutputState(3,0)    

end if

 end if

 goto Main_loop

End Sub 

 




autorun.brs

5 comments

  • 0
    Avatar
    Roni Starc

    The debugger says

    Use of uninitialized variable. (runtime error &he9) in SD:/autorun.brs(77)
    077:    song = A + B + C + D

    This means something does not execute, upon looking at the code i see this:

    if type(msg) = "roroGpioBUtton"  <- typo, should be roGpioButton

    Then you will get another error:

    Type Mismatch. (runtime error &h18) in SD:/autorun.brs(91)
    091:            ok = v.PlayFile("\" + song + ".mp3")

    the song int is not automatcally converted to a string (like in javascript for example), you need to do the conversion "manually", i think the Str() or Stri() function should do the trick, but have not tested it.

    You also have some anomalities, eg. you use both the roControlPort and roGpioControlPort. roControlPort superseeds roGpioControlPort, so there is no need to use roGpioControlPort. Definetly take a look at the BS object reference manual.

  • 0
    Avatar
    Paul Trembly

    Thanks for the help, so far so good, still throwing an error but I am sure I am missing something simple.  BTW, what are you using as a debugger?  I haven't been able to find one.  I am writing this in Notepad which is no doubt why I am not finding all my errors.

  • 0
    Avatar
    MustangAce

    These are the few thing I see...

    if type(msg) = "roGpioBUtton" should have a "then"

    A, B, C, D are not initilized unless their "if" is executed. So when an event comes in, "song" does not get initilaized properly. The same goes for LEDA, LEDB, LEDC, LEDD.

    The hidden sign in "song" must be removed as well as made into a string before passing it to play.

    get rid of bcp = CreateObject("roControlPort", "BrightSign") and bcp.SetPort(p)

     

     

  • 0
    Avatar
    Roni Starc

    For debuggign you can use either the serial port and a terminal program on the computer or (my preferred choice) telnet to the BS player. The telnet must be enabled (it is disabled as default). When the red led starts to blink you press the svc button and the error is spilled to the console (serial or telnet).

    You have still to upload the brs files to the BS (i do it through the web interface) and either name the brs as autorun.brs and reboot the player at every upload (but this takes time). Or simply leave the player without an autorun, when boots hit the svc, the console goes live, then with the script command you enter the script interpreter and from there you use Run("whateverIsTheNameOfYourScript.brs"). This way you can upload, run, find the bug, reupload, rerun ...  But I found sometimes you need a reboot, but haven't figured the occurrence yet. All this is described in various places in the documentation, but can be hard to find.

    This is for now the best way to do it, that I could find.

    @MustangAce, the BS manual states, that the "then" keyword is optional.

    Paul, I'm pretty sure the error you are mentioning is because of the song variable. You must change it to a string. I tried with the Str() function, but did not work. I then just made a quick "lookup" table for the variable.
     Works at my place now (haven't tried it with audio files, I just look if the scripts says it is playing the file). Attaching the brs.

  • 0
    Avatar
    Paul Trembly

    Roni  I have a HD120, so I don't think there is an option to telnet into it. :-(

Please sign in to leave a comment.