31 from p2msg
import P2Msg
46 ERR_STR = { 10:
"Incomplete or timeout header recv",
47 11:
"Timeout on data size recv",
48 12:
"Incomplete or timeout data recv",
49 13:
"Incomplete message or checksum or timeout on checksum recv",
50 2 :
"Invalid checksum",
51 9 :
"Global timeout, no frame received"}
79 return "Error "+str(self.
errno)+
" : "+P2ComError.ERR_STR[self.
errno]
87 return P2ComError.ERR_STR[self.
errno]
113 self.
ser = serial.Serial(portFile,9600,serial.EIGHTBITS,serial.PARITY_NONE,serial.STOPBITS_ONE,self.
timeout,)
129 Remove P2Com.checksum()
138 buff += int(tmp[-2:],16)
161 tmp = int(msg[0:2],16)
171 res.append(checksum/0x100)
172 res.append(checksum%0x100)
177 self.ser.write(str(bytearray(res)))
179 logger.debug(
"Send '"+msg_bck+
"%04X" % checksum+
"'")
188 self.ser.write(msg.getRaw()+
"\r")
190 logger.debug(
"Send '"+msg.getStr()+
"'")
204 logger.debug(
"Waiting for data on serial port")
207 recvBuff = self.ser.read(1024)
208 if len(recvBuff) > 0:
210 if len(recvBuff) >= 1
and not res.setHeader(recvBuff[0:2]):
212 if len(recvBuff) >= 3
and not res.setDataSz(recvBuff[2:3]):
214 if len(recvBuff) >= 5
and not res.setData(recvBuff[3:-2]):
216 if not res.setChecksum(recvBuff[-2:]):
218 logger.debug(
"Frame received "+res.getStr())