Ejemplo n.º 1
0
        public async Task FC01Test()
        {
            // Arrange
            var endpoint = EndpointSource.GetNext();

            using var server = new ModbusTcpServer();
            server.Start(endpoint);

            void AsyncWorkaround()
            {
                var buffer = server.GetCoilBuffer <byte>();

                buffer[1] = 9;
                buffer[2] = 0;
                buffer[3] = 24;
            }

            lock (server.Lock)
            {
                AsyncWorkaround();
            }

            var client = new ModbusTcpClient();

            client.Connect(endpoint);

            // Act
            var actual = await client.ReadCoilsAsync(0, 8, 25);

            // Assert
            var expected = new byte[] { 9, 0, 24, 0 };

            Assert.True(expected.SequenceEqual(actual.ToArray()));
        }