Exemple #1
0
 public void ConnectPLC()
 {
     try
     {
         HetModbusTool.Connect(PLCIP, PLCPort);
         ConnectionErrorString = "Connected";
         ConnectionErrorState  = false;
     }
     catch (Exception e)
     {
         ConnectionErrorString = "Control PLC Cable" + e.ToString();
         ConnectionErrorState  = true;
     }
     if (HetModbusTool.Connected)
     {
         ConnectionErrorState = false;
     }
     else if (!HetModbusTool.Connected)
     {
         ConnectionErrorState = true;
     }
 }
Exemple #2
0
        public Program()
        {
            modbusTCP = new ModbusTCP(ipAddress, port);
            modbusTCP.Connect();
            //int[] response = modbusTCP.ReadInputRegisters(startAddress, qty);
            bool[] response = modbusTCP.ReadDiscreteInputs(40001, qty);


            modbusTCP.Disconnect();

            System.Console.WriteLine("Reg 1: " + response[0].ToString());
            System.Console.WriteLine("Reg 2: " + response[1].ToString());
            System.Console.WriteLine("Reg 1: " + response[2].ToString());
            System.Console.WriteLine("Reg 1: " + response[3].ToString());
            System.Console.WriteLine("Reg 1: " + response[4].ToString());
            System.Console.WriteLine("Reg 1: " + response[5].ToString());
            System.Console.WriteLine("Reg 1: " + response[6].ToString());
            System.Console.WriteLine("Reg 1: " + response[7].ToString());
            System.Console.WriteLine("Reg 1: " + response[8].ToString());
            System.Console.WriteLine("Reg 1: " + response[9].ToString());
        }