def read_single_value(self, address, additional_data="1"): """ Reads a value from an address in the device. :param address: :param additional_data: :return: """ # TODO Can't find documentation on why the additional_data of 1 is needed. # LIS-200 Specific? # TODO: When not using the additional data on an EMH meter we get an ack back. # a bit later we get the break message. Is the device waiting? request = messages.CommandMessage.for_single_read( address, additional_data) logger.info(f"Sending read request: {request}") self.transport.send(request.to_bytes()) response = self.read_response() if len(response.data) > 1: raise exceptions.TooManyValuesReturned( f"Read of one value returned {len(response.data)}") if len(response.data) == 0: raise exceptions.NoDataReturned(f"Read returned no data") logger.info(f"Received response: {response}") # Just return the data, not in a list since it is just one. return response.data[0]
def read_multi_value(self, address, additional_data=""): """ Reads a value from an address in the device. :param address: :param additional_data: :return: """ # TODO Can't find documentation on why the additional_data of 1 is needed. request = messages.CommandMessage.for_single_read( address, additional_data) logger.info(f"Sending read request: {request}") self.transport.send(request.to_bytes()) response = self.read_response() if len(response.data) == 0: raise exceptions.NoDataReturned(f"Read returned no data") logger.info(f"Received response: {response}") # Just return the data, not in a list since it is just one. return response.data