Data Sheet
36
ETHERIO24TCPDATASHEET
UDPINTERFACEEXAMPLES
SendingUDPCommands
BROADCASTIO24
Shownbelowisexamplecodeforabutton(Ether_Scan)thatbroadcasts
“IO24”onport2424
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 EtherIO24example
{
public partial class Form1 : Form
{
//******************************************************
// Define variables that will be used throughout the code
//******************************************************
public UdpClient udpClient = new UdpClient(2424);
public byte[] sendBytes;
public Form1()
{
InitializeComponent();
}
private void Ether_Scan_Click(object sender, EventArgs e)
{
//******************************************************
// Send out IO24 via broadcast(255.255.255.255) on port 2424
//******************************************************
//******************************************************
// Fill sendBytes buffer with "IO24"
//******************************************************
sendBytes = Encoding.ASCII.GetBytes("IO24");
//******************************************************
// Broadcast UDP packet with IO24 on port 2424
// using the udpClient.send
//******************************************************
udpClient.Send(sendBytes, //buffer
sendBytes.Length, //buffer length
"255.255.255.255", //destination IP
2424); //destination Port
//******************************************************
// All units will respond with IO24
// + 6 byte MAC address + Version Number
//******************************************************
}
}
}
©
2013ElexolPtyLtd Revision1.3