'ports peed 1200 'send and receive end of line character hard coded at CR 'serial port # assumed to be 0 '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.resetport = serial_resetport 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) = "roAssociativeArray" then if type(event["EventType"]) = "roString" then if (event["EventType"] = "SEND_PLUGIN_MESSAGE") then if event["PluginName"] = "serial" then pluginMessage$ = event["PluginMessage"] print "SEND_PLUGIN/EVENT_MESSAGE:";pluginMessage$ retval = ParseserialPluginMsg(pluginMessage$, m) endif endif endif else if type(event) = "roTimerEvent" then end if return retval End Function Function ParseserialPluginMsg(Msg as string, s as object) as boolean Print "Parseserial function" retval = false command = "" param ="" ' convert the message to all lower case for easier string matching later msg = lcase(Msg) print "Received Plugin message: "+msg r = CreateObject("roRegex", "^udp", "i") match=r.IsMatch(msg) if match then retval = true ' split the string r2 = CreateObject("roRegex", "!", "i") fields=r2.split(msg) numFields = fields.count() if (numFields < 2) or (numFields > 2) then print "Incorrect number of fields for seriale command:";msg return retval else if (numFields = 2) then command=fields[1] print "two fields found "; command if s.resetport then s.bsp.serial["0"].sendline(command) else s.bsp.diagnostics.printdebug("Serial: Failed to reset port speed") endif end if end if if command = "debug" then s.debug=true end if return retval end Function Function serial_resetport() as Boolean port$="0" if type(m.bsp.serial) = "roAssociativeArray" then m.bsp.serial[port$] = invalid else m.bsp.serial={} endif serialPortSpeed% = 1200 serialPortMode$ = "8N1" serial = CreateObject("roSerialPort", port%, serialPortSpeed%) if serial <> invalid then sendEOL$ = "CR" receiveEol$= "CR" serial.setmode(serialPortMode$) serial.SetSendEol(sendEol$) serial.SetReceiveEol(receiveEol$) m.bsp.serial[port$] = serial return true endif endif return false End function