Пример #1
0
        /// <summary>
        /// ネットワーク上にあるEthernet/IPデバイスの情報を取得します。
        /// </summary>
        /// <returns>デバイス名</returns>
        public string[] SearchDevice()
        {
            string[] dev = new string[128];
            int      i   = 0;

            //実際のCIPIdentityItem情報はDeviceListに格納される
            DeviceList = eEIPClient.ListIdentity();
            foreach (Encapsulation.CIPIdentityItem device in DeviceList)
            {
                dev[i] = Encapsulation.CIPIdentityItem.getIPAddress(device.SocketAddress.SIN_Address) + "\t" + device.ProductName1;
                IpAddressList.Add(device.SocketAddress.SIN_Address);
                i++;
            }

            //戻り値はコンボボックス用
            return(dev);
        }
Пример #2
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();
        }