Serial

javadoc

 

 

 

 

Serial service is a way to send and recieve serial data into and out of MRL

 

References

 


#file : toSort/Serial.min.py edit raw
import time

#create a Serial service named serial
serial = Runtime.createAndStart("serial","Serial")
#create a Log service named log
log    = Runtime.createAndStart("log","Log")
#have the log's log method subscribe to the serial's read method
serial.addListener("publishByte", log.getName(),"log")

#connect to a serial port COM4 57600 bitrate 8 data bits 1 stop bit 0 parity
serial.connect("COM4", 57600, 8, 1, 0)

#sometimes its important to wait a little for hardware to get ready
sleep(1)

#write a series of bytes to the serial port
serial.write(87) 
serial.write(79) 
serial.write(82) 
serial.write(75) 
serial.write(89)
serial.write(32)



#file : toSort/Serial.asciiToChar.py edit raw
#file : Serial.asciiToChar.py
import time
 
#create a Serial service named serial
serial = Runtime.createAndStart("serial","Serial")
def onByte(code):
 decoded = ''.join(chr(code))
 print decoded
#have python listening to serial
serial.addByteListener("python") 
#connect to a serial port COM4 57600 bitrate 8 data bits 1 stop bit 0 parity
serial.connect("COM9", 57600, 8, 1, 0)
#sometimes its important to wait a little for hardware to get ready
sleep(1)
 
#write a series of bytes to the serial port
serial.write(87) 
serial.write(79) 
serial.write(82) 
serial.write(75) 
serial.write(89)
serial.write(32)

Architecture Diagram

 

Examples:


#file : service/Serial.py edit raw
# start the service
serial = Runtime.start("serial","Serial")