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

            double[] data = await modbus.ReadDoubleArrayAsync(MODBUS_SLAVE, 0, 5);

            Assert.Equal(5, data.Length);
            await modbus.WriteDoubleArrayAsync(MODBUS_SLAVE, 0, new double[] { 0.12345, 1.2345, 12.345, 123.45, 1234.5 });

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

            Assert.Equal(5, data.Length);
            Assert.Equal(new double[] { 0.12345, 1.2345, 12.345, 123.45, 1234.5 }, data);
            await modbus.WriteDoubleArrayAsync(MODBUS_SLAVE, 0, new double[] { 0, 0, 0, 0, 0 });

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

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

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