Exemple #1
0
 private void OnInputsChanged(ModbusSlave sender, bool calRegisters)
 {
     if (this.RegistersChanged != null)
     {
         this.RegistersChanged(sender, calRegisters);
     }
 }
Exemple #2
0
 private void OnCoilsChanged(ModbusSlave sender)
 {
     if (this.CoilsChanged != null)
     {
         this.CoilsChanged(sender);
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
 private static void Slave_CoilsChanged(ModbusSlave sender)
 {
     Debug.WriteLine("coil changed");
 }
Exemple #5
0
 private static void Slave_RegistersChanged(ModbusSlave sender, bool calRegisters)
 {
     Debug.WriteLine("callreg:" + calRegisters);
 }