def test_modbus_mbmap_from_xml_element(self): filename = os.path.join(self.pathlist.path[1], 'mbmap_test_device_1.xml') f = open(filename, 'r') map_data = f.read() f.close() root = ET.fromstring(map_data) m1 = mbmap.ModbusMap() m1.from_xml(element=root) m2 = mbmap.ModbusMap() m2.from_xml('mbmap_test_device_1_a.xml', self.pathlist) not_equal = m1.not_equal(m2) if not_equal: raise Exception(not_equal) m3 = mbmap.ModbusMap() m3.from_xml('mbmap_test_device_1_b.xml', self.pathlist) not_equal = m1.not_equal(m3) if not_equal: raise Exception(not_equal) m4 = mbmap.ModbusMap() m4.from_xml('mbmap_test_device_1_c.xml', self.pathlist) not_equal = m1.not_equal(m4) if not_equal: raise Exception(not_equal)
def test_modbus_mbmap_from_xml_element(pathlist=None): try: filename = os.path.join(pathlist.path[1], 'mbmap_test_device_1.xml') f = open(filename, 'r') map_data = f.read() f.close() root = ET.fromstring(map_data) m1 = mbmap.ModbusMap() m1.from_xml(element=root) m2 = mbmap.ModbusMap() m2.from_xml('mbmap_test_device_1_a.xml', pathlist) not_equal = m1.not_equal(m2) if not_equal: raise Exception(not_equal) m3 = mbmap.ModbusMap() m3.from_xml('mbmap_test_device_1_b.xml', pathlist) not_equal = m1.not_equal(m3) if not_equal: raise Exception(not_equal) m4 = mbmap.ModbusMap() m4.from_xml('mbmap_test_device_1_c.xml', pathlist) not_equal = m1.not_equal(m4) if not_equal: raise Exception(not_equal) except Exception, e: print '*** Failure test_modbus_mbmap_from_xml: %s' % str(e) return False
def test_modbus_mbmap_from_xml_file(self): m1 = mbmap.ModbusMap() m1.from_xml('mbmap_test_device_1.xml', self.pathlist) m2 = mbmap.ModbusMap() m2.from_xml('mbmap_test_device_1_a.xml', self.pathlist) not_equal = m1.not_equal(m2) if not_equal: raise Exception(not_equal) m3 = mbmap.ModbusMap() m3.from_xml('mbmap_test_device_1_b.xml', self.pathlist) not_equal = m1.not_equal(m3) if not_equal: raise Exception(not_equal) m4 = mbmap.ModbusMap() m4.from_xml('mbmap_test_device_1_c.xml', self.pathlist) not_equal = m1.not_equal(m4) if not_equal: raise Exception(not_equal) m5 = mbmap.ModbusMap() m5.from_xml('mbmap_test_device_1_d.xml', self.pathlist) not_equal = m1.not_equal(m5) if not_equal: raise Exception(not_equal)
def test_modbus_mbmap_from_xml_file(pathlist=None): try: m1 = mbmap.ModbusMap() m1.from_xml('mbmap_test_device_1.xml', pathlist) m2 = mbmap.ModbusMap() m2.from_xml('mbmap_test_device_1_a.xml', pathlist) not_equal = m1.not_equal(m2) if not_equal: raise Exception(not_equal) m3 = mbmap.ModbusMap() m3.from_xml('mbmap_test_device_1_b.xml', pathlist) not_equal = m1.not_equal(m3) if not_equal: raise Exception(not_equal) m4 = mbmap.ModbusMap() m4.from_xml('mbmap_test_device_1_c.xml', pathlist) not_equal = m1.not_equal(m4) if not_equal: raise Exception(not_equal) except Exception, e: print '*** Failure test_modbus_mbmap_from_xml: %s' % str(e) return False
def test_modbus_mbmap_from_xml_file(pathlist=None, raw_traceback=False): try: m1 = mbmap.ModbusMap() m1.from_xml('mbmap_test_device_1.xml', pathlist) m2 = mbmap.ModbusMap() m2.from_xml('mbmap_test_device_1_a.xml', pathlist) not_equal = m1.not_equal(m2) if not_equal: raise Exception(not_equal) m3 = mbmap.ModbusMap() m3.from_xml('mbmap_test_device_1_b.xml', pathlist) not_equal = m1.not_equal(m3) if not_equal: raise Exception(not_equal) m4 = mbmap.ModbusMap() m4.from_xml('mbmap_test_device_1_c.xml', pathlist) not_equal = m1.not_equal(m4) if not_equal: raise Exception(not_equal) except Exception as e: if raw_traceback: traceback.print_exc(file=sys.stdout) print('*** Failure test_modbus_mbmap_from_xml: %s' % str(e)) return False return True
def __init__(self, slave_id, name, pathlist=None, max_count=None, ctx=None): self.slave_id = slave_id self.name = name self.ctx = ctx self.modbus_map = None if name is not None: self.modbus_map = mbmap.ModbusMap(slave_id) self.modbus_map.from_xml(name, pathlist) else: raise mbmap.ModbusMapError('No modbus map file provided during initialization')
def test_modbus_mbmap_to_xml(self): filename = os.path.join(self.pathlist.path[1], 'mbmap_test_device_1.xml') f = open(filename, 'r') map_data = f.read() f.close() root = ET.fromstring(map_data) expected_output_filename = os.path.join( self.pathlist.path[1], 'mbmap_test_device_1_processed.xml') f = open(expected_output_filename, 'r') expected_output = f.read() f.close() expected_root = ET.fromstring(expected_output) # Convert from xml to ModbusMap and back to xml to verify to_xml() is working properly m1 = mbmap.ModbusMap() m1.from_xml(element=root) assert m1.to_xml().find('regs').text == expected_root.find('regs').text
def test_modbus_mbmap_regs_add(self): m1 = mbmap.ModbusMap(base_addr=999, func='holding', mapid=12345) m1.regs_add(offset=40072, count=1)