public void ModbusFactoryThrowsOnNullTcpClientPassedToCreateRtuOverTcpMaster()
        {
            // Arrange
            var factory = new ModbusFactory();

            // Act/Assert
            Assert.Throws <ArgumentNullException>("tcpClient", () => factory.CreateRtuOverTcpMaster((TcpClient)null));
        }
        public void ModbusFactoryThrowsOnNullLoggerPassedToCreateRtuOverTcpMaster()
        {
            // Arrange
            var factory = new ModbusFactory();

            // Act/Assert
            Assert.Throws <ArgumentNullException>("logger", () => factory.CreateRtuOverTcpMaster(new TcpClient(), null));
        }
Esempio n. 3
0
        private static void ModbusRtuOverTcpMasterReadInputs()
        {
            while (true)
            {
                using (TcpClient client = new TcpClient("127.0.0.1", 502))
                {
                    //var factory = new ModbusFactory();

                    var           factory = new ModbusFactory();
                    IModbusMaster master  = factory.CreateRtuOverTcpMaster(client);
                    // read five input values
                    ushort startAddress = 0;

                    ushort numInputs = 5;

                    ushort[] inputs = master.ReadHoldingRegisters(1, startAddress, numInputs);

                    inputs.ToList().ForEach(x => { Console.WriteLine(x); });

                    Console.WriteLine("---------------------------------------------");
                    Thread.Sleep(1000);
                }
            }
        }