def test_long_list_to_word(self): # empty list, return empty list self.assertEqual(utils.long_list_to_word([]), []) # test convert with big and little endian word_list = utils.long_list_to_word([0xdeadbeef]) self.assertEqual(word_list, [0xdead, 0xbeef]) word_list = utils.long_list_to_word([0xdeadbeef, 0xdeadbeef]) self.assertEqual(word_list, [0xdead, 0xbeef, 0xdead, 0xbeef]) word_list = utils.long_list_to_word([0xdeadbeef], big_endian=False) self.assertEqual(word_list, [0xbeef, 0xdead]) word_list = utils.long_list_to_word([0xdeadbeef, 0xdeadbeef], big_endian=False) self.assertEqual(word_list, [0xbeef, 0xdead, 0xbeef, 0xdead])
def test_long_list_to_word(self): # empty list, return empty list self.assertEqual(utils.long_list_to_word([]), []) # test convert with big and little endian word_list = utils.long_list_to_word([0xdeadbeef]) self.assertEqual(word_list, [0xdead, 0xbeef]) word_list = utils.long_list_to_word([0xdeadbeef, 0xdeadbeef]) self.assertEqual(word_list, [0xdead, 0xbeef, 0xdead, 0xbeef]) word_list = utils.long_list_to_word([0xdeadbeef], big_endian=False) self.assertEqual(word_list, [0xbeef, 0xdead]) word_list = utils.long_list_to_word([0xdeadbeef, 0xdeadbeef], big_endian=False) self.assertEqual(word_list, [0xbeef, 0xdead, 0xbeef, 0xdead])
def write_float(self, address, floats_list): b32_1 = [utils.encode_ieee(f) for f in floats_list] b16_1 = utils.long_list_to_word(b32_1) return self.write_multiple_registers(address, b16_1)
def write_float(self, address, floats_list): b32_l = [utils.encode_ieee(f) for f in floats_list] b16_l = utils.long_list_to_word(b32_l) return self.write_multiple_registers(address, b16_l)
def set_floats(cls, address, floats_list): b32_l = [utils.encode_ieee(f) for f in floats_list] b16_l = utils.long_list_to_word(b32_l) return cls.set_words(address, b16_l)
def write_float(self, address, floats_list): b32_l = [utils.encode_ieee(f) for f in floats_list] b16_l = utils.long_list_to_word(b32_l) return self.modbusClient.write_multiple_registers(address, floats_list)
def write_multiple_floats(self, address: int, floats_list: list): integer_32bits_representation_list = [modbus_utils.encode_ieee(number) for number in floats_list] integers_represented_in_list_of_16bits = modbus_utils.long_list_to_word(integer_32bits_representation_list) return self.write_multiple_registers(address, integers_represented_in_list_of_16bits)
def write_float(self, address: int, float_number: float): integer_32bits_representation = modbus_utils.encode_ieee(float_number) integer_represented_in_list_of_16bits = modbus_utils.long_list_to_word([integer_32bits_representation]) return self.write_multiple_registers(address, integer_represented_in_list_of_16bits)