Processing app:
import processing.net.*;
/*
Lantronix UDP Device Query
Sends out a UDP broadcast packet to query a subnet for Lantronix
serial-to-ethernet devices.
Lantronix devices are programmed to respond to UDP messages received on
port 30718. If a Lantronix device receives the string 0x00 0x00 0x00 0xF6,
it respond with a UDP packet containing the status message on port 30718.
See the Lantronix integration guide from http://www.lantronix guid for the details.
This program uses the Hypermedia UDP library available at
http://hypermedia.loeil.org/processing/
by Tom Igoe
Created 18 April 2006
*/
// import UDP library
import hypermedia.net.*;
UDP udp; // define the UDP object
int queryPort = 30718; // the port number for the device query
String broadcastIpAddress = "128.122.151.255"; // fill in IP address here
void setup() {
// create a new connection to listen for
// UDP datagrams on query port
udp = new UDP(this, queryPort);
// listen for incoming packets:
udp.listen( true );
}
//process events
void draw() {
// twiddle your thumbs. Everything is event generated.
}
/*
send the query message when any key is pressed:
*/
void keyPressed() {
byte[] queryMsg = new byte[4];
queryMsg[0] = 0x00;
queryMsg[1] = 0x00;
queryMsg[2] = 0x00;
queryMsg[3] = (byte)0xF6;
// send the message
udp.send( queryMsg, broadcastIpAddress, queryPort );
}
/*
listen for responses
*/
void receive( byte[] data, String ip, int port ) {
String inString = new String(data); // data converted to a string
int[] intData = int(data); // data converted to ints
int i = 0; // counter
// print the result:
println( "received "+inString+" from "+ip+" on port "+port );
// parse the payload for the appropriate data:
print("Opcode: ");
println(intData[3]);
// if the fourth byte is , we got a status reply:
if (intData[3] == 0xF7) {
// firmware data is bytes 4 to 20:
print("Firmware data: ");
for (i=4; i < 20; i++) {
print(" " + Integer.toHexString(intData[i]));
}
// MAC address is bytes 24 to 30 (the end):
print("\nMAC Addr: ");
for (i=24; i < intData.length; i++) {
print(" " + Integer.toHexString(intData[i]));
}
print("\n\n");
}
}