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

            long[] data = await modbus.ReadLongArrayAsync(MODBUS_SLAVE, 0, 5);

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

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

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

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

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

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