
398 MAKING THINGS TALK
Chapter 7
Lantronix UDP Device Query
Language: Processing
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 responds with a UDP packet
containing the status message on port 30718. When the
program starts, press any key on the keyboard and watch
the message pane for responses. See the Lantronix inte-
gration guide from www.lantronix.com for the details. This
program uses the Hypermedia UDP library available at
hypermedia.loeil.org/processing/
// import UDP library
import hypermedia.net.*;
UDP udp; // define the UDP object
int queryPort = 30718; // the port number for the device query
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 );
}
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;
// because 0xF6 (decimal value 246) is greater than 128
// you have to explicitly convert it to a byte:
queryMsg[3] = byte(0xF6);
// send th