Example #1
0
        /// <summary>
        /// Program entry point
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ModbusMasterSerial mm = new ModbusMasterSerial(ModbusSerialType.RTU, "COM7", 19200, 8, Parity.Even, StopBits.One, Handshake.None);

            mm.Connect();

            while(true)
            {
                Test_ModbusRTUMaster(mm);

                Thread.Sleep(1000);
            }
            //Test_ModbusRTUSlave();
        }
Example #2
0
        /// <summary>
        /// Test modbus RTU master function on a slave RTU id = 5
        /// </summary>
        static void Test_ModbusRTUMaster(ModbusMasterSerial mm)
        {
            try
            {
                Console.Write(
                "---------------------- READING ----------------------" + Environment.NewLine +
                "Input register no. 30501 (Meas. 1) : " + mm.ReadInputRegisters(65, 30501, 1).First().ToString("D5") + Environment.NewLine +
                "Input register no. 30502 (Meas. 2) : " + mm.ReadInputRegisters(65, 30502, 1).First().ToString("D5") + Environment.NewLine + Environment.NewLine);

            }

               catch(Exception ex)
            {
                Console.Write(Environment.NewLine + ex.Message + Environment.NewLine);

                Thread.Sleep(5000);

            }
        }