private void OnInputsChanged(ModbusSlave sender, bool calRegisters) { if (this.RegistersChanged != null) { this.RegistersChanged(sender, calRegisters); } }
private void OnCoilsChanged(ModbusSlave sender) { if (this.CoilsChanged != null) { this.CoilsChanged(sender); } }
static void StartSlave() { //SLAVE var slavePort = GHIElectronics.TinyCLR.Devices.Uart.UartController.FromName (GHIElectronics.TinyCLR.Pins.SC20260.UartPort.Uart5); var setting = new UartSetting() { BaudRate = 19200, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None, }; slavePort.SetActiveSettings(setting); slavePort.Enable(); //new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One); var RtuInterface = new ModbusRtuInterface(slavePort, 19200, 8, UartStopBitCount.One, UartParity.None); Debug.WriteLine("rtu open:" + RtuInterface.isOpen + ", rtu connection:" + RtuInterface.IsConnectionOk); byte ModbusID = 5; slave = new ModbusSlave(RtuInterface, ModbusID); slave.CoilsChanged += Slave_CoilsChanged; slave.RegistersChanged += Slave_RegistersChanged; // // Init the SLAVE REGISTERS // initSlave(); // // Start the slave now // slave.Start(); Debug.WriteLine("running:" + slave.IsRunning); }
private static void Slave_CoilsChanged(ModbusSlave sender) { Debug.WriteLine("coil changed"); }
private static void Slave_RegistersChanged(ModbusSlave sender, bool calRegisters) { Debug.WriteLine("callreg:" + calRegisters); }