Data Sheet
38
ETHERIO24TCPDATASHEET
ReceivingUDPCommandResponses
UDPLISTENER
ThisexampleprogramwillbroadcastIO24acrossthenetworkonstartup
andlistallEtherIO24’sthatrespondtothecommandinadropdowncombo
box.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//***************************************************************
// Declare additional system-defined namespaces used by UDPClient
//***************************************************************
using System.Net.Sockets;
using System.Net;
namespace UDPListener
{
public partial class Form1 : Form
{
//******************************************************
// Define variables that will be used throughout the code
//******************************************************
public UdpClient udpClient = new UdpClient(2424);
public byte[] sendBytes;
public byte[] data = new byte[1024];
string PCIPAddress;
public string strHostName;
string ReturnIPAddress;
List<IPEndPoint> IPList = new List<IPEndPoint>();
public int DeviceNo, list;
public IPEndPoint EtherIP;
//********************************************************
// The thread that will manage the data back from the board
//********************************************************
private System.Threading.Thread thdUDPReciever;
//********************************************************
// This Subroutine is to handle all the UDP return data
// recieved from the thread UDPReciever
//********************************************************
public delegate void ReturnUDPDataCallback(byte[] text, IPEndPoint IP);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//***********************************************
// Declare and start UDP recieve Thread
//***********************************************
thdUDPReciever = new System.Threading.Thread(new
System.Threading.ThreadStart(RecieveThread));
thdUDPReciever.Start();
//***********************************************
//Find out PC IP address as UDP Recieve thread
//recieves all UDP packets
//***********************************************
strHostName = System.Net.Dns.GetHostName();
PCIPAddress =
System.Net.Dns.GetHostEntry(strHostName).AddressList[0].ToString();
}
©
2013ElexolPtyLtd Revision1.3