def readDeviceDataIO(self): results = self.readData() lb, hb = results[5] & 0x7F, results[6] self.eod = (results[5] & 0x80) > 0 resLength = lib.BangInt((lb, hb)) log.info('XXX resLength: %s' % resLength) #assert resLength < 64, ("cmd low byte count:\n%s" % lib.hexdump(results)) data = results[13:13+resLength] assert len(data) == resLength crc = results[-1] # crc check log.info('readDeviceDataIO:msgCRC:%r:expectedCRC:%r:data:%s' % (crc, CRC8(data), lib.hexdump(data))) assert crc == CRC8(data) return data
def checkAck(self): log.info('checkAck sleeping .100') time.sleep(.100) result = bytearray(self.read(64)) io.info('checkAck:read') if len(result) == 0: log.error("ACK is zero bytes!") return False raise BadDeviceCommError("ACK is not 64 bytes: %s" % lib.hexdump(result)) commStatus = result[0] # usable response assert commStatus == 1, ('commStatus: %02x expected 0x1' % commStatus) status = result[1] # status == 102 'f' NAK, look up NAK if status == 85: # 'U' log.info('checkACK OK, found %s total bytes' % len(result)) return result[3:] assert False, "NAK!!"
def clearBuffers(self): garbage = -1 while garbage: garbage = bytearray(self.link.read(64)) log.error("found garbage:\n%s" % lib.hexdump(garbage))