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(); }
public byte State1; //Current state of device public static CIPIdentityItem getCIPIdentityItem(int startingByte, byte[] receivedData) { startingByte = startingByte + 2; //Skipped ItemCount CIPIdentityItem cipIdentityItem = new CIPIdentityItem(); cipIdentityItem.ItemTypeCode = Convert.ToUInt16(receivedData[0 + startingByte] | (receivedData[1 + startingByte] << 8)); cipIdentityItem.ItemLength = Convert.ToUInt16(receivedData[2 + startingByte] | (receivedData[3 + startingByte] << 8)); cipIdentityItem.EncapsulationProtocolVersion = Convert.ToUInt16(receivedData[4 + startingByte] | (receivedData[5 + startingByte] << 8)); cipIdentityItem.SocketAddress.SIN_family = Convert.ToUInt16(receivedData[7 + startingByte] | (receivedData[6 + startingByte] << 8)); cipIdentityItem.SocketAddress.SIN_port = Convert.ToUInt16(receivedData[9 + startingByte] | (receivedData[8 + startingByte] << 8)); cipIdentityItem.SocketAddress.SIN_Address = (UInt32)(receivedData[13 + startingByte] | (receivedData[12 + startingByte] << 8) | (receivedData[11 + startingByte] << 16) | (receivedData[10 + startingByte] << 24) ); cipIdentityItem.VendorID1 = Convert.ToUInt16(receivedData[22 + startingByte] | (receivedData[23 + startingByte] << 8)); cipIdentityItem.DeviceType1 = Convert.ToUInt16(receivedData[24 + startingByte] | (receivedData[25 + startingByte] << 8)); cipIdentityItem.ProductCode1 = Convert.ToUInt16(receivedData[26 + startingByte] | (receivedData[27 + startingByte] << 8)); cipIdentityItem.Revision1[0] = receivedData[28 + startingByte]; cipIdentityItem.Revision1[1] = receivedData[29 + startingByte]; cipIdentityItem.Status1 = Convert.ToUInt16(receivedData[30 + startingByte] | (receivedData[31 + startingByte] << 8)); cipIdentityItem.SerialNumber1 = (UInt32)(receivedData[32 + startingByte] | (receivedData[33 + startingByte] << 8) | (receivedData[34 + startingByte] << 16) | (receivedData[35 + startingByte] << 24)); cipIdentityItem.ProductNameLength = receivedData[36 + startingByte]; cipIdentityItem.ProductName1 = Encoding.ASCII.GetString(receivedData, 37 + startingByte, cipIdentityItem.ProductNameLength); cipIdentityItem.State1 = receivedData[receivedData.Length - 1]; return(cipIdentityItem); }