def test_stream_3(self): data1 = [0, 0, 0, 0, 0, 0, 0, 0, 0] data2 = bytes(data1) data3 = debug_data(data2) stream = easyb.message.stream.Stream(Length.Byte9) self.assertIsNotNone(stream) self.assertEqual(stream.len, 9) self.assertIs(stream.length, Length.Byte9) self.assertEqual(stream.data, data1) self.assertEqual(stream.bytes, data2) self.assertEqual(repr(stream), data3) self.assertEqual(str(stream), data3) return
def default_command(self, message: Message): logging = debug_data(message.stream.bytes) easyb.log.inform(self.name, logging) return True
def receive(self) -> Union[None, Message]: try: header = self.serial.read(3) except serial.SerialException as e: easyb.log.error("Problem during reading of message header!") easyb.log.exception(e) return None debug = debug_data(header) easyb.log.debug1("SERIAL", "Header: {0:s}".format(debug)) message = Message() check = message.decode(header) if check is False: return None message.info("RECEIVE") if message.code == 5: easyb.log.warn(self.name, "Command not supported!") return None number = 0 if message.length is Length.Byte6: number = 3 if message.length is Length.Byte9: number = 6 if message.length is Length.Variable: number = -1 if number == 0: easyb.log.warn(self.name, "Message body has no size!") message.data = header return message if number == -1: easyb.log.warn(self.name, "Message body is variable!") data = self.read_unit_timeout() else: try: data = self.serial.read(number) except serial.SerialException as e: easyb.log.error("Problem during reading of message body!") easyb.log.exception(e) return None stream = message.stream debug = debug_data(data) easyb.log.debug1("SERIAL", "{0:s}: {1:s}".format(message.length.name, debug)) check = stream.append(data) if check is False: return None stream.length = message.length check = stream.verify_length() if check is False: return None return message
def __repr__(self): return debug_data(self.bytes)