class TestPluginMain(unittest.TestCase): def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.start() def tearDown(self): self.t.disconnect("127.0.0.1:5020") self.t.stop() self.t = None def test_plugin_main_connect_T(self): res = self.t.connect("127.0.0.1:5020") self.assertEqual(res['data'], 'connect success') print("result:", res) def test_plugin_main_connect_F1(self): res = self.t.connect("0.0.0.1:5020") self.assertEqual(res['data'], 'connect failed') print("result:", res) def test_plugin_main_connect_F2(self): res = self.t.connect("127.0.0.1") self.assertEqual(res['data'], 'modbus-tcp plugin connect parameter error') print("result:", res)
class TestPluginMain(unittest.TestCase): def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.connect("127.0.0.1:5020") def tearDown(self): self.t.disconnect("127.0.0.1:5020") self.t = None def test_plugin_main_write_register_T(self): uri = "127.0.0.1:5020" res = self.t.write_coil(uri, 20, "112") self.assertEqual(res['data'], 'OK') print("result:", res['data']) def test_plugin_main_write_register_F1(self): uri = "0.0.0.1:5020" res = self.t.write_coil(uri, 20, "112") self.assertEqual(res['data'], 'device not found') print("result:", res['data']) def test_plugin_main_write_register_F2(self): uri = "127.0.0.1:5020" res = self.t.write_coil(uri, "20", "112") self.assertEqual(res['data'], 'error') print("result:", res['data'])
class TestPluginMain(unittest.TestCase): def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.start() '''self.t.connect("127.0.0.1:5020")''' def tearDown(self): self.t.stop() '''self.t.disconnect("127.0.0.1:5020")''' self.t = None def test_plugin_main_is_client_connected_T(self): res = self.t.is_client_connected("127.0.0.1:5020") self.assertTrue(res) print("result:", res) def test_plugin_main_is_client_connected_F(self): res = self.t.is_client_connected("") self.assertFalse(res) print("result:", res)
def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.connect("127.0.0.1:5020")
class TestPluginMain(unittest.TestCase): def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.connect("127.0.0.1:5020") def tearDown(self): self.t.disconnect("127.0.0.1:5020") self.t = None def test_plugin_main_read_inputs_T1(self): self.client = ModbusClient("127.0.0.1", "5020") valid_inputs = [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ] res = self.t.read_inputs(self.client, valid_inputs, 0) self.assertEqual(res, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) print("result:", res) def test_plugin_main_read_inputs_T2(self): self.client = ModbusClient("127.0.0.1", "5020") valid_inputs = [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ] res = self.t.read_inputs(self.client, valid_inputs, 1) self.assertEqual(res, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) print("result:", res) def test_plugin_main_read_inputs_F1(self): self.client = ModbusClient("127.0.0.1", "5020") valid_inputs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] res = self.t.read_inputs(self.client, valid_inputs, 0) self.assertEqual(res, None) print("ModbusPlugin: Failed to read inputs") def test_plugin_main_read_inputs_F2(self): self.client = ModbusClient("127.0.0.1", "5") valid_inputs = [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ] res = self.t.read_inputs(self.client, valid_inputs, 0) self.assertEqual(res, None) print("ModbusPlugin: Failed to connect") def test_plugin_main_read_inputs_F3(self): self.client = ModbusClient("127.0.0.1", "5020") valid_inputs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] res = self.t.read_inputs(self.client, valid_inputs, 1) self.assertEqual(res, None) print("ModbusPlugin: Failed to read inputs") def test_plugin_main_read_inputs_F4(self): self.client = ModbusClient("127.0.0.1", "5") valid_inputs = [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ] res = self.t.read_inputs(self.client, valid_inputs, 1) self.assertEqual(res, None) print("ModbusPlugin: Failed to connect")
def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) self.t.start()
class TestPluginMain(unittest.TestCase): def setUp(self): e = ModbusPluginEntity(SCRIPT_DIR + '/../plugin_modbus.json') c = ModbusPluginConfig(SCRIPT_DIR + '/../default.conf') self.t = ModbusPluginClient(e, c) def tearDown(self): self.t = None def test_plugin_main_disconnect_T(self): self.t.connect("127.0.0.1:5020") res = self.t.disconnect("127.0.0.1:5020") self.assertEqual(res['data'], 'disconnect success') print("result:", res) def test_plugin_main_disconnect_F1(self): self.t.connect("127.0.0.1:5020") res = self.t.disconnect("0.0.0.1:5020") self.assertEqual(res['data'], 'device not found') print("result:", res) def test_plugin_main_disconnect_F2(self): self.t.start() res = self.t.disconnect("127.0.0.1:5020") self.assertEqual(res['data'], 'disconnect not allow') print("result:", res) self.t.stop()