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

            bool[] data = await modbus.ReadBoolArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
            await modbus.WriteBoolArrayAsync(MODBUS_SLAVE, 0, new bool[] { true, false, true, true, false });

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

            Assert.Equal(5, data.Length);
            Assert.Equal(new bool[] { true, false, true, true, false }, data);
            await modbus.WriteBoolArrayAsync(MODBUS_SLAVE, 0, new bool[] { false, false, false, false, false });

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

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

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