ed@448: import serial edouard@453: import exceptions ed@448: from threading import Lock ed@448: Lolitech@545: class LPCProtoError(exceptions.Exception): ed@448: """Exception class""" ed@448: def __init__(self, msg): ed@448: self.msg = msg ed@448: ed@448: def __str__(self): ed@448: return "LPC communication error ! " + str(self.msg) ed@448: ed@448: class LPCProto: ed@448: def __init__(self, port, rate, timeout): edouard@453: # serialize access lock edouard@453: self.TransactionLock = Lock() ed@448: # open serial port edouard@453: # self.serialPort = serial.Serial( port, rate, timeout = timeout ) edouard@453: # Debugging serial stuff edouard@453: self._serialPort = serial.Serial( port, rate, timeout = timeout ) edouard@453: class myser: edouard@453: def read(self_,cnt): edouard@453: res = self._serialPort.read(cnt) Lolitech@545: if len(res) > 16: Lolitech@545: print "Recv :", map(hex,map(ord,res[:16])), "[...]" Lolitech@545: else: Lolitech@545: print "Recv :", map(hex,map(ord,res)) Lolitech@545: edouard@453: return res edouard@453: def write(self_, str): Lolitech@545: if len(str) > 16: Lolitech@545: print "Send :", map(hex,map(ord,str[:16])), "[...]" Lolitech@545: else: Lolitech@545: print "Send :", map(hex,map(ord,str)) edouard@453: self._serialPort.write(str) edouard@453: def flush(self_): edouard@453: self._serialPort.flush() edouard@453: self.serialPort = myser() edouard@453: # start with empty ed@448: self.serialPort.flush() ed@448: