Example #1
0
        public async Task TestShortArrayAsync()
        {
            var           factory = new ModbusFactory();
            IModbusMaster modbus  = factory.CreateMaster(_client);
            await _client.ConnectAsync(MODBUS_IP, MODBUS_PORT);

            short[] data = await modbus.ReadShortArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
            await modbus.WriteShortArrayAsync(MODBUS_SLAVE, 0, new short[] { -1, -2, -3, -4, -5 });

            data = await modbus.ReadShortArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
            Assert.Equal(new short[] { -1, -2, -3, -4, -5 }, data);
            await modbus.WriteShortArrayAsync(MODBUS_SLAVE, 0, new short[] { 0, 0, 0, 0, 0 });

            data = await modbus.ReadShortArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
            Assert.Equal(new short[] { 0, 0, 0, 0, 0 }, data);
            data = await modbus.ReadOnlyShortArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
        }