Пример #1
0
        public async Task TestBytes()
        {
            var           factory = new ModbusFactory();
            IModbusMaster modbus  = factory.CreateMaster(_client);
            await _client.ConnectAsync(MODBUS_IP, MODBUS_PORT);

            byte[] data = await modbus.ReadBytesAsync(MODBUS_SLAVE, 0, 5);

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

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

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

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

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

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