Example #1
0
        private void checkSampleCompiles()
        {
            var settings = new SerialSettings()
            {
                PortName = "COM3",
                BaudRate = 57600,
            };

            //Modbus RTU over serial
            using (var master = ModbusMaster.RTU(settings))
            {
                master.WriteCoil(1, 3000, false);
                master.WriteCoils(1, 3001, false, true);
            }
            //Modbus RTU over isolated serial
            using (var master = ModbusMaster.IsolatedRTU(settings))
            {
                master.WriteCoil(1, 3000, false);
                master.WriteCoils(1, 3001, false, true);
            }
            //Modbus TCP over socket
            using (var master = ModbusMaster.TCP("10.77.0.2", 502))
            {
                master.WriteCoils(1, 4, false, true);
            }
        }
Example #2
0
        public void RtuOverSerialTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusRTUScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var master = ModbusMaster.RTU(new SerialSettings(MasterCOM)))
                {
                    //race condition avoided by access order
                    H.SharedSlaveTest(model, master);
                }
        }
Example #3
0
        public void RtuExceptionOverSerialTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusRTUScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var master = ModbusMaster.RTU(new SerialSettings(MasterCOM)))
                {
                    var ex = Assert.Throws <ModbusException>(() => H.SharedExceptionTest(master));
                    Assert.AreEqual("Modbus exception 2", ex.Message);
                    Assert.AreEqual(2, ex.Code);
                }
        }
Example #4
0
        public void ModportSweepTest()
        {
            //http://comfiletech.com/etc/field-i-o/modport-i-o-module/
            //m0 - MD-DIDC8 8 digital input
            //m1 - MD-DOSO8 8 digital output
            //all outputs wired to corresponding inputs
            var settings = new SerialSettings()
            {
                PortName = "COM3",
                BaudRate = 57600,
            };

            using (var master = ModbusMaster.RTU(settings))
            {
                testMaster(master);
            }
            Thread.Sleep(200);
            using (var master = ModbusMaster.IsolatedRTU(settings))
            {
                testMaster(master);
            }
        }