示例#1
0
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()
示例#2
0
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.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)
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_read_registers_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_registers(self.client, valid_inputs, 2)
        self.assertNotEqual(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_registers_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_registers(self.client, valid_inputs, 3)
        self.assertNotEqual(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_registers_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_registers(self.client, valid_inputs, 2)
        self.assertEqual(res, None)
        print("ModbusPlugin: Failed to read registers")

    def test_plugin_main_read_registers_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_registers(self.client, valid_inputs, 2)
        self.assertEqual(res, None)
        print("ModbusPlugin: Failed to connect")

    def test_plugin_main_read_registers_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_registers(self.client, valid_inputs, 3)
        self.assertEqual(res, None)
        print("ModbusPlugin: Failed to read registers")

    def test_plugin_main_read_registers_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_registers(self.client, valid_inputs, 3)
        self.assertEqual(res, None)
        print("ModbusPlugin: Failed to connect")