Exemple #1
0
        static void Main(string[] args)
        {
            //https://www.youtube.com/watch?v=fg58H-ZZit0
            EEIPClient eeipClient = new EEIPClient();

            eeipClient.RegisterSession("192.168.1.3");

            byte[] readAllRegisters = eeipClient.GetAttributeAll(0x6b, 1);
            Console.WriteLine(readAllRegisters);

            //When done, we unregister the session
            eeipClient.UnRegisterSession();
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            //Ip-Address of the Ethernet-IP Device (In this case Keyence-NU-EP1)
            eeipClient.IPAddress = "192.168.0.123";
            //A Session has to be registered before any communication can be established
            eeipClient.RegisterSession();

            //Parameters from Originator -> Target
            eeipClient.O_T_InstanceID          = 0xfe;                                     //Instance ID of the Output Assembly
            eeipClient.O_T_Length              = 0;
            eeipClient.O_T_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Header32Bit; //Header Format
            eeipClient.O_T_OwnerRedundant      = false;
            eeipClient.O_T_Priority            = Sres.Net.EEIP.Priority.Low;
            eeipClient.O_T_VariableLength      = false;
            eeipClient.O_T_ConnectionType      = Sres.Net.EEIP.ConnectionType.Point_to_Point;
            eeipClient.RequestedPacketRate_O_T = 500000;    //RPI in  500ms is the Standard value



            //Parameters from Target -> Originator
            eeipClient.T_O_InstanceID          = 0x66;
            eeipClient.T_O_Length              = 2;
            eeipClient.T_O_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Modeless;
            eeipClient.T_O_OwnerRedundant      = false;
            eeipClient.T_O_Priority            = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.T_O_VariableLength      = false;
            eeipClient.T_O_ConnectionType      = Sres.Net.EEIP.ConnectionType.Multicast;
            eeipClient.RequestedPacketRate_T_O = 500000;    //RPI in  500ms is the Standard value

            //Forward open initiates the Implicit Messaging
            eeipClient.ForwardOpen();

            while (true)
            {
                //Read the Inputs Transfered from Target -> Originator
                Console.WriteLine("State of first Input byte: " + eeipClient.T_O_IOData[0]);
                Console.WriteLine("State of second Input byte: " + eeipClient.T_O_IOData[1]);


                System.Threading.Thread.Sleep(500);
            }

            //Close the Session
            eeipClient.ForwardClose();
            eeipClient.UnRegisterSession();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            eeipClient.IPAddress = "192.168.178.107";
            eeipClient.RegisterSession();
            //Console.WriteLine("Product Name: " + eeipClient.IdentityObject.ProductName);
            //Console.WriteLine("Product Code: " + eeipClient.IdentityObject.ProductCode);
            //byte[] data =eeipClient.GetAttributeSingle(0x4, 0x65,3);
            //for (int i = 0; i < data.Length; i++)
            //    Console.WriteLine(data[i]);
            //Console.ReadKey();
            //UInt32 sessionHandle = eeipClient.RegisterSession("192.168.178.107", 0xAF12);
            //            eipClient.O_T_ConnectionType = Sres.Net.EEIP.ConnectionType.Null;
            //            eipClient.O_T_Length = 0;


            eeipClient.O_T_InstanceID     = 0x64;
            eeipClient.O_T_Length         = eeipClient.Detect_O_T_Length();
            eeipClient.O_T_RealTimeFormat = Sres.Net.EEIP.RealTimeFormat.Header32Bit;
            eeipClient.O_T_OwnerRedundant = false;
            eeipClient.O_T_Priority       = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.O_T_VariableLength = false;
            eeipClient.O_T_ConnectionType = Sres.Net.EEIP.ConnectionType.Point_to_Point;

            eeipClient.T_O_InstanceID     = 0x65;
            eeipClient.T_O_Length         = eeipClient.Detect_T_O_Length();
            eeipClient.T_O_RealTimeFormat = Sres.Net.EEIP.RealTimeFormat.Modeless;
            eeipClient.T_O_OwnerRedundant = false;
            eeipClient.T_O_Priority       = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.T_O_VariableLength = false;
            eeipClient.T_O_ConnectionType = Sres.Net.EEIP.ConnectionType.Multicast;
            eeipClient.ForwardOpen();
            while (true)
            {
                Console.Write(eeipClient.LastReceivedImplicitMessage);
                Console.WriteLine(eeipClient.T_O_IOData[8]);
                eeipClient.O_T_IOData[0] = (byte)((byte)eeipClient.O_T_IOData[0] + (byte)1);
                eeipClient.O_T_IOData[1] = (byte)((byte)eeipClient.O_T_IOData[1] - (byte)1);
                System.Threading.Thread.Sleep(500);
            }



            Console.ReadKey();
            eeipClient.ForwardClose();
            eeipClient.UnRegisterSession();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            //Ip-Address of the Ethernet-IP Device (In this case Allen-Bradley 1734-AENT Point I/O)
            eeipClient.IPAddress = "192.168.1.254";
            //A Session has to be registered before any communication can be established
            eeipClient.RegisterSession();

            //Parameters from Originator -> Target
            eeipClient.O_T_InstanceID          = 0x68;                                     //Instance ID of the Output Assembly
            eeipClient.O_T_Length              = 4;                                        //The Method "Detect_O_T_Length" detect the Length using an UCMM Message
            eeipClient.O_T_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Header32Bit; //Header Format
            eeipClient.O_T_OwnerRedundant      = false;
            eeipClient.O_T_Priority            = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.O_T_VariableLength      = false;
            eeipClient.O_T_ConnectionType      = Sres.Net.EEIP.ConnectionType.Point_to_Point;
            eeipClient.RequestedPacketRate_O_T = 500000;        //500ms is the Standard value

            //Parameters from Target -> Originator
            eeipClient.T_O_InstanceID          = 0x67;
            eeipClient.T_O_Length              = 8;
            eeipClient.T_O_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Modeless;
            eeipClient.T_O_OwnerRedundant      = false;
            eeipClient.T_O_Priority            = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.T_O_VariableLength      = false;
            eeipClient.T_O_ConnectionType      = Sres.Net.EEIP.ConnectionType.Point_to_Point;
            eeipClient.RequestedPacketRate_T_O = 500000;    //RPI in  500ms is the Standard value

            //Forward open initiates the Implicit Messaging
            eeipClient.ForwardOpen();

            while (true)
            {
                //Read the Inputs Transfered form Target -> Originator
                Console.WriteLine("State of Input byte: " + eeipClient.T_O_IOData[2]);

                //write the Outputs Transfered form Originator -> Target
                eeipClient.O_T_IOData[2] = 0x0F;        //Set all Four digital Inputs to High

                System.Threading.Thread.Sleep(500);
            }

            //Close the Session
            eeipClient.ForwardClose();
            eeipClient.UnRegisterSession();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            EEIPClient             eipClient  = new EEIPClient();
            List <CIPIdentityItem> identities = eipClient.ListIdentity();
            var result = "";

            identities.ForEach(identity => { result += $"{identity}\n"; });
            File.WriteAllText("Identity.xml", result);

            result = "";
            identities.ForEach(identity => {
                try
                {
                    eipClient = new EEIPClient();

                    eipClient.O_T_OwnerRedundant = false;
                    eipClient.T_O_OwnerRedundant = false;
                    eipClient.RegisterSession(identity.SocketAddress.SIN_Address, identity.SocketAddress.SIN_port);
                    eipClient.ForwardOpen();
                    Console.WriteLine($"{identity.SocketAddress.SIN_Address}:{identity.SocketAddress.SIN_port}");
                    Console.WriteLine("Value of First Byte 1: " + eipClient.T_O_IOData[0]);
                    Console.WriteLine("Value of First Byte 2: " + eipClient.T_O_IOData[1]);
                    Console.WriteLine("Value of First Byte 3: " + eipClient.T_O_IOData[2]);
                    Console.WriteLine("Value of First Byte 4: " + eipClient.T_O_IOData[3]);
                    Console.WriteLine("Value of First Byte 5: " + eipClient.T_O_IOData[4]);
                    Console.WriteLine("Value of First Byte 6: " + eipClient.T_O_IOData[5]);
                    result += $"Success: {CIPIdentityItem.GetIPAddress(identity.SocketAddress.SIN_Address)}:{identity.SocketAddress.SIN_port}\n";
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error: {identity.SocketAddress.SIN_Address}:{identity.SocketAddress.SIN_port}");
                    result += $"Error: {CIPIdentityItem.GetIPAddress(identity.SocketAddress.SIN_Address)}:{identity.SocketAddress.SIN_port}\n";
                }
            });

            File.WriteAllText("Result.xml", result);

            var process = new Process();

            process.StartInfo.FileName  = "cmd.exe";
            process.StartInfo.Arguments = $"/C start .";
            process.Start();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            //Register Session (Wago-Device 750-352 IP-Address: 192.168.178.66)
            //we use the Standard Port for Ethernet/IP TCP-connections 0xAF12
            eeipClient.RegisterSession("192.168.1.3");

            //Get the State of Analog Inputs According to the Manual
            //Instance 0x6D of the Assembly Object contains the Analog Input data
            //The Documentation can be found at: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf
            //Page 202 shows the documentation for instance 6D hex
            byte[] analogInputs = eeipClient.AssemblyObject.getInstance(0x6D);

            Console.WriteLine("Temperature of Analog Input 1: " + (EEIPClient.ToUshort(new byte[] { analogInputs[0], analogInputs[1] }) / 10.0) + "°C");
            Console.WriteLine("Temperature of Analog Input 2: " + (EEIPClient.ToUshort(new byte[] { analogInputs[2], analogInputs[3] }) / 10.0) + "°C");
            //When done, we unregister the session
            eeipClient.UnRegisterSession();
            Console.ReadKey();
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Host"/> Class.
        /// </summary>
        public Host()
        {
            _client = new EEIPClient()
            {
                IPAddress = "192.168.125.1"
            };
            try
            {
                _client.RegisterSession();

                //ReadWriteToIntegerRegister();
                //ReadWriteStringRegister();
                ReadWritePositionRegister();

                _client.UnRegisterSession();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            //Register Session (Wago-Device 750-352 IP-Address: 192.168.178.66)
            //we use the Standard Port for Ethernet/IP TCP-connections 0xAF12
            eeipClient.RegisterSession("192.168.1.3");

            //Get the State of a digital Input According to the Manual
            //Instance 0x6C of the Assembly Object contains the Digital Input data
            //The Documentation can be found at: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf
            byte[] digitalInputs = eeipClient.AssemblyObject.getInstance(0x6c);

            Console.WriteLine("State of Digital Input 1: " + (EEIPClient.ToBool(digitalInputs[0], 0)));
            Console.WriteLine("State of Digital Input 2: " + (EEIPClient.ToBool(digitalInputs[0], 1)));
            Console.WriteLine("State of Digital Input 3: " + (EEIPClient.ToBool(digitalInputs[0], 2)));
            Console.WriteLine("State of Digital Input 4: " + (EEIPClient.ToBool(digitalInputs[0], 3)));


            //When done, we unregister the session
            eeipClient.UnRegisterSession();
            Console.ReadKey();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            try
            {
                ParseArgs(args);
            }
            catch (Exception x)
            {
                Console.Error.WriteLine("Failed to parse arguments: {0}", x.Message);
                Console.Error.WriteLine("ERR_INVALID_ARGS");
                Environment.Exit(1);
            }

            Console.CancelKeyPress += Console_CancelKeyPress;

            client = new EEIPClient()
            {
                IPAddress = host,
                TCPPort   = port
            };

            Console.Error.WriteLine($"Connecting to {host}:{port}...");

            try
            {
                client.RegisterSession();
            }
            catch (Exception x)
            {
                Console.Error.WriteLine("Failed to connect: {0}", x.Message);
                Console.Error.WriteLine("ERR_CONNECTION_FAILURE");
                Environment.Exit(1);
            }

            while (!IsCancelled())
            {
                try
                {
                    Run();
                }
                catch (Exception x)
                {
                    if (IsCancelled())
                    {
                        Console.Error.WriteLine("ERR_CANCELLED");
                    }
                    else if (x.Message.StartsWith("ERR_"))
                    {
                        Console.Error.WriteLine(x.Message);
                    }
                    else
                    {
                        Console.Error.WriteLine(x.Message);
                        Console.Error.WriteLine("ERR_EXCEPTION");
                    }

                    if (repeat == 0)
                    {
                        Environment.Exit(1);
                    }
                }

                if (repeat == 0)
                {
                    break;
                }

                if (!IsCancelled())
                {
                    Thread.Sleep(repeat);
                }

                Console.Error.WriteLine();
            }

            try
            {
                Console.Error.WriteLine("Closing the connection...");

                client.UnRegisterSession();
                client = null;
            }
            catch (Exception) { }

            if (result != null)
            {
                var json = new StringBuilder();

                json.Append("{");
                json.Append(@"""program"":");
                json.Append(result.ProgramNoDuringJudgement);
                json.Append(@",""result"":");
                json.Append(result.OverallJudgement ? "true" : "false");
                json.Append(@",""processingTime"":");
                json.Append(result.ProcessingTime);

                if (tools > 0)
                {
                    json.Append(@",""tools"":[");

                    for (var no = 1; no <= tools; ++no)
                    {
                        var tool = result.Tools[no - 1];

                        json.Append("{");
                        json.Append(@"""result"":");
                        json.Append(tool.Result ? "true" : "false");
                        json.Append(@",""matchingRate"":");
                        json.Append(tool.MatchingRate);
                        json.Append(@",""lowerThreshold"":");
                        json.Append(tool.LowerThreshold);
                        json.Append(@",""upperThreshold"":");
                        json.Append(tool.UpperThreshold);
                        json.Append("}");

                        if (tool.No < tools)
                        {
                            json.Append(",");
                        }
                    }

                    json.Append("]");
                }

                json.Append("}");

                Console.WriteLine(json.ToString());
            }
        }
Exemple #10
0
        /// <summary>
        /// Explicit Massaging サービスを使ってPLCからデータを呼び出します。
        /// </summary>
        /// <param name="dataareaID">更新するデータエリア番号</param>
        /// <param name="instanceid">インスタンスID</param>
        /// <param name="dataType">データ型</param>
        /// <param name="isString">入力データが文字列の場合true</param>
        /// <param name="tcpport">TCPポート</param>
        /// <param name="destination">宛先IPアドレス番号</param>
        /// <return>EIP_Status構造体を返します</return>
        public virtual EIP_Status ReadInstance(byte instanceid, DataType dataType, bool isString, bool isBCD, ushort tcpport = 44818, int destination = 0)
        {
            EIP_Status status = new EIP_Status
            {
                code    = 0,
                message = ""
            };

            try
            {
                //IPアドレスはフォームで選択したものを使用
                //TCPポートは特に変更していない場合はこれで固定 EEIP.dll内の既定値
                eEIPClient.TCPPort   = tcpport;
                eEIPClient.IPAddress = Encapsulation.CIPIdentityItem.getIPAddress(IpAddressList[destination]);
                eEIPClient.RegisterSession();

                //CIPメッセージ Assembly(0x04)を使って引数のInstanceIDのIOの値を読み出す
                //戻り値のバッファサイズはPLC側で設定したタグのサイズとなっているので一定ではない
                byte[] response       = eEIPClient.GetAttributeSingle(0x04, instanceid, 0x03);
                string responseString = "";

                //送られてきたデータが数値の場合
                //HEX→DEC変換して格納
                if ((dataType == DataType.DM || dataType == DataType.EM) && !isString && !isBCD)
                {
                    int n        = 0;
                    int tmpvalue = 0;
                    foreach (byte resAddress in response)
                    {
                        tmpvalue += resAddress * (int)Math.Pow(16, 2 * n);
                        n++;
                    }

                    responseString = tmpvalue.ToString();
                    status.value   = responseString;
                }
                else if (isBCD)
                {
                    string tmpvalue = "";
                    foreach (byte resAddress in response)
                    {
                        if (resAddress > 0)
                        {
                            tmpvalue = (resAddress / 16).ToString() + (resAddress % 16).ToString();
                        }
                    }

                    responseString = tmpvalue.ToString();
                    status.value   = responseString;
                }


                //送られてきたデータが文字列の場合
                //リトルエンディアンのため上位バイトは i + 1 に格納されている
                if ((dataType == DataType.DM || dataType == DataType.EM) && isString)
                {
                    for (int i = 0; i < response.Length - 1; i++)
                    {
                        if (response[i] != 0x32)
                        {
                            responseString += (char)response[i + 1];
                            responseString += (char)response[i];
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    status.value = responseString;
                }

                //ビット形式はとりあえず何もしない
                if (dataType == DataType.R || dataType == DataType.L || dataType == DataType.X || dataType == DataType.Y)
                {
                }

                //戻り値を作る
                status.code     = 0;
                status.response = response;
            }
            catch (Exception e)
            {
                status.code     = -1;
                status.message  = e.Message;
                status.response = null;
            }

            return(status);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            //Ip-Address of the Ethernet-IP Device (In this case Allen-Bradley 1734-AENT Point I/O)
            eeipClient.IPAddress = "192.168.178.107";
            //A Session has to be registered before any communication can be established
            eeipClient.RegisterSession();

            //Parameters from Originator -> Target
            eeipClient.O_T_InstanceID          = 0x64;                                     //Instance ID of the Output Assembly
            eeipClient.O_T_Length              = 4;                                        //The Method "Detect_O_T_Length" detect the Length using an UCMM Message
            eeipClient.O_T_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Header32Bit; //Header Format
            eeipClient.O_T_OwnerRedundant      = false;
            eeipClient.O_T_Priority            = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.O_T_VariableLength      = false;
            eeipClient.O_T_ConnectionType      = Sres.Net.EEIP.ConnectionType.Point_to_Point;
            eeipClient.RequestedPacketRate_O_T = 500000;        //500ms is the Standard value

            //Parameters from Target -> Originator
            eeipClient.T_O_InstanceID          = 0x65;
            eeipClient.T_O_Length              = 16;
            eeipClient.T_O_RealTimeFormat      = Sres.Net.EEIP.RealTimeFormat.Modeless;
            eeipClient.T_O_OwnerRedundant      = false;
            eeipClient.T_O_Priority            = Sres.Net.EEIP.Priority.Scheduled;
            eeipClient.T_O_VariableLength      = false;
            eeipClient.T_O_ConnectionType      = Sres.Net.EEIP.ConnectionType.Multicast;
            eeipClient.RequestedPacketRate_T_O = 500000;    //RPI in  500ms is the Standard value

            //Forward open initiates the Implicit Messaging
            eeipClient.ForwardOpen();

            while (true)
            {
                //Read the Inputs Transfered form Target -> Originator
                Console.WriteLine("State of first Input byte: " + eeipClient.T_O_IOData[8]);
                Console.WriteLine("State of second Input byte: " + eeipClient.T_O_IOData[9]);

                //write the Outputs Transfered form Originator -> Target
                eeipClient.O_T_IOData[0] = (byte)(eeipClient.O_T_IOData[0] + 1);
                eeipClient.O_T_IOData[1] = (byte)(eeipClient.O_T_IOData[1] - 1);
                eeipClient.O_T_IOData[2] = 1;
                eeipClient.O_T_IOData[3] = 8;

                System.Threading.Thread.Sleep(500);

                //Detect Timeout (Read last Received Message Property)
                if (DateTime.Now.Ticks > eeipClient.LastReceivedImplicitMessage.Ticks + (1000 * 10000))
                {
                    try
                    {
                        eeipClient.ForwardClose();
                        eeipClient.UnRegisterSession();

                        eeipClient.RegisterSession();
                        eeipClient.ForwardOpen();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Couldn't reconnect to Point I/O");
                    }
                }
            }

            //Close the Session
            eeipClient.ForwardClose();
            eeipClient.UnRegisterSession();
        }