Ejemplo n.º 1
0
    def test_client_server_count(self):

        client = ModbusProtocol(
            protocol=TestModbusProtocol.CLIENT_PROTOCOL)

        ADDRESS = 'localhost:3502'
        TAGS = (50, 50, 50, 50)

        try:
            server = ModbusProtocol._start_server(self.SERVER_CMD_PATH, ADDRESS, TAGS)
            time.sleep(1.0)

            print('TEST: Write and Read holding registers, offset=4, count=3')
            what = ('HR', 4)
            hrs = [1, 2, 3]
            client._send(what, hrs, ADDRESS, count=3)
            eq_(client._receive(what, ADDRESS, count=3), hrs)
            print('')

            print('TEST: Write and Read holding registers, offset=4, count=3')
            what = ('CO', 7)
            cos = [True, False, False, True, False]
            client._send(what, cos, ADDRESS, count=5)
            eq_(client._receive(what, ADDRESS, count=5), cos)
            print('')

            ModbusProtocol._stop_server(server)

        except Exception as error:
            ModbusProtocol._stop_server(server)
            print 'ERROR test_client_server_count: ', error
            assert False
Ejemplo n.º 2
0
    def test_send(self):

        client = ModbusProtocol(
            protocol=TestModbusProtocol.CLIENT_PROTOCOL)

        ADDRESS = 'localhost:3502'
        TAGS = (20, 20, 20, 20)
        OFFSET = 10

        try:
            server = ModbusProtocol._start_server(self.SERVER_CMD_PATH, ADDRESS, TAGS)
            time.sleep(1.0)

            print('TEST: Write to holding registers')
            for offset in range(0, OFFSET):
                what = ('HR', offset)
                client._send(what, offset, ADDRESS)
            print('')

            coil = True
            print('TEST: Write to coils')
            for offset in range(0, OFFSET):
                what = ('CO', offset)
                client._send(what, coil, ADDRESS)
                coil = not coil
            print('')

            ModbusProtocol._stop_server(server)

        except Exception as error:
            ModbusProtocol._stop_server(server)
            print 'ERROR test_send: ', error
            assert False
Ejemplo n.º 3
0
    def test_server_start_stop(self):

        try:
            server = ModbusProtocol._start_server(self.SERVER_CMD_PATH,
                'localhost:3502', self.TAGS)
            ModbusProtocol._stop_server(server)

        except Exception as error:
            print 'ERROR test_server_start_stop: ', error
            assert False
Ejemplo n.º 4
0
    def test_receive(self):

        client = ModbusProtocol(
            protocol=TestModbusProtocol.CLIENT_PROTOCOL)

        ADDRESS = 'localhost:3502'
        TAGS = (20, 20, 20, 20)
        OFFSET = 10

        try:
            server = ModbusProtocol._start_server(self.SERVER_CMD_PATH, ADDRESS, TAGS)
            time.sleep(1.0)

            print('TEST: Read holding registers')
            for offset in range(0, OFFSET):
                what = ('HR', offset)
                eq_(client._receive(what, ADDRESS), 0)
            print('')

            print('TEST: Read input registers')
            for offset in range(0, OFFSET):
                what = ('IR', offset)
                eq_(client._receive(what, ADDRESS), 0)
            print('')

            print('TEST: Read discrete inputs')
            for offset in range(0, OFFSET):
                what = ('DI', offset)
                eq_(client._receive(what, ADDRESS), False)
            print('')

            print('TEST: Read coils inputs')
            for offset in range(0, OFFSET):
                what = ('CO', offset)
                eq_(client._receive(what, ADDRESS), False)
            print('')

            ModbusProtocol._stop_server(server)

        except Exception as error:
            ModbusProtocol._stop_server(server)
            print 'ERROR test_receive: ', error
            assert False
Ejemplo n.º 5
0
    def test_receive_count(self):

        client = ModbusProtocol(
            protocol=TestModbusProtocol.CLIENT_PROTOCOL)

        ADDRESS = 'localhost:3502'
        TAGS = (20, 20, 20, 20)

        try:
            server = ModbusProtocol._start_server(self.SERVER_CMD_PATH, ADDRESS, TAGS)
            time.sleep(1.0)

            print('TEST: Read holding registers, count=3')
            what = ('HR', 0)
            eq_(client._receive(what, ADDRESS, count=3), [0, 0, 0])
            print('')

            print('TEST: Read input registers, count=1')
            what = ('IR', 0)
            eq_(client._receive(what, ADDRESS, count=1), 0)
            print('')

            print('TEST: Read discrete inputs, count=2')
            what = ('DI', 0)
            eq_(client._receive(what, ADDRESS, count=2), [False] * 2)
            print('')

            print('TEST: Read coils, count=9')
            what = ('CO', 0)
            eq_(client._receive(what, ADDRESS, count=9), [False] * 9)
            print('')

            ModbusProtocol._stop_server(server)

        except Exception as error:
            ModbusProtocol._stop_server(server)
            print 'ERROR test_receive_count: ', error
            assert False