0

Serial Plugin Script Example

I'm looking for an example script for a plugin that receives serial messages. I cannot seem to get this working and I would like to review an example. I haven't found any examples of a plugin receiving serial. 

 

Thanks,

David 

1 comment

  • 0
    Avatar
    Lyndon

    Try this one. It's pretty simple. It listens for a serial string, and then sends the values received as a zone message event.  I don't know what you want to do with the serial input. 

    https://www.brightsignnetwork.com/download/Scripts/serial_simple_plugin.brs

     

    'Plugin currently assumes ascii strings

    Function serial_Initialize(msgPort As Object, userVariables As Object, bsp as Object)

    print "seriale_Initialize - entry"

    serial = newserial(msgPort, userVariables, bsp)

    return serial

    End Function


    Function newserial(msgPort As Object, userVariables As Object, bsp as Object)
    print "newserial"

    s = {}
    s.version = 0.1
    s.msgPort = msgPort
    s.userVariables = userVariables
    s.bsp = bsp
    s.ProcessEvent = serial_ProcessEvent
    s.objectName = "serial_object"
    s.debug = false
    return s
    End Function


    Function serial_ProcessEvent(event As Object) as boolean
    print "processing event serial plugin"
    retval = false

    if type(event) = "roTimerEvent" then

    else if type(event) = "roStreamLineEvent" then
    'carriage return terminated serial string

    command$= ""
    command$ = event.getstring()

    'send zone message with serial command value
    sendZoneMessageParameter$ = command$
    zoneMessageCmd = CreateObject("roAssociativeArray")
    zoneMessageCmd["EventType"] = "SEND_ZONE_MESSAGE"
    zoneMessageCmd["EventParameter"] = sendZoneMessageParameter$
    m.msgPort.PostMessage(zoneMessageCmd)

    end if

    return retval

    End Function

     

Please sign in to leave a comment.