Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions EEIP.NET/EIPClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,46 @@ public class UdpState
List<Encapsulation.CIPIdentityItem> returnList = new List<Encapsulation.CIPIdentityItem>();

/// <summary>
/// List and identify potential targets. This command shall be sent as braodcast massage using UDP.
/// List and identify potential targets. This command shall be sent as braodcast message using UDP.
/// </summary>
/// <returns>List<Encapsulation.CIPIdentityItem> contains the received informations from all devices </returns>
public List<Encapsulation.CIPIdentityItem> ListIdentity()
{

foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
if (ni.OperationalStatus != OperationalStatus.Up)
{
continue;
}

foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
if (ni.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && ni.NetworkInterfaceType != NetworkInterfaceType.Ethernet)
{
continue;
}

foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
System.Net.IPAddress mask = ip.IPv4Mask;
System.Net.IPAddress address = ip.Address;
System.Net.IPAddress mask = ip.IPv4Mask;
System.Net.IPAddress address = ip.Address;

String multicastAddress = (address.GetAddressBytes()[0] | (~(mask.GetAddressBytes()[0])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[1] | (~(mask.GetAddressBytes()[1])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[2] | (~(mask.GetAddressBytes()[2])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[3] | (~(mask.GetAddressBytes()[3])) & 0xFF).ToString();
String multicastAddress = (address.GetAddressBytes()[0] | (~(mask.GetAddressBytes()[0])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[1] | (~(mask.GetAddressBytes()[1])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[2] | (~(mask.GetAddressBytes()[2])) & 0xFF).ToString() + "." + (address.GetAddressBytes()[3] | (~(mask.GetAddressBytes()[3])) & 0xFF).ToString();

byte[] sendData = new byte[24];
sendData[0] = 0x63; //Command for "ListIdentity"
System.Net.Sockets.UdpClient udpClient = new System.Net.Sockets.UdpClient();
System.Net.IPEndPoint endPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(multicastAddress), 44818);
udpClient.Send(sendData, sendData.Length, endPoint);
byte[] sendData = new byte[24];
sendData[0] = 0x63; //Command for "ListIdentity"
System.Net.Sockets.UdpClient udpClient = new System.Net.Sockets.UdpClient();
System.Net.IPEndPoint endPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(multicastAddress), 44818);
udpClient.Send(sendData, sendData.Length, endPoint);

UdpState s = new UdpState();
s.e = endPoint;
s.u = udpClient;
UdpState s = new UdpState();
s.e = endPoint;
s.u = udpClient;

var asyncResult = udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), s);
var asyncResult = udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), s);

System.Threading.Thread.Sleep(1000);
}
System.Threading.Thread.Sleep(1000);
}
}
}
Expand Down