Sending UDP Datagrams to and from a Cobox, Xport, or WiPort

The Cobox Micro can send and receive UDP packets. I haven’t written examples yet. Following are just my notes, from discussions on the Lantronix Xport Yahoo mailing list, and from experimentation.

To send directed UDP packets, you have to put set the connectMode appropriately. Bits 2 and 3 of the ConnectMode register are set to 1 to enable directed UDP. Setting the ConnectMode to 0xCC (hex) will set the Cobox to accept any incoming UDP packets and allow you send UDP packets to the address and port number you set for the remote IP address. Once you’ve set the ConnectMode to 0xCC, set the Datagram Type to 01. With these settings, your cobox will only send to the remote IP specified in your configuration.

It is possible to change the destination address on the fly. It’s undocumented, but the Lantronix folks on the list have been helpful in figuring it out. First, you have to set the ConnectMode to CC and the Datagram type to 00. In this configuration, you have to compose your own outgoing datagrams, as follows:

From the serial side, you send:

  • (Start of transmission byte)
  • (Destination IP byte 1)
  • (Destination IP byte 2)
  • (Destination IP byte 3)
  • (Destination IP byte 4)
  • (Number of data bytes (a two-byte value))
  • (data bytes, highest to lowest)

For example, to send the string “1023” to the address, you’d send the following into the serial port of the Cobox (these are the raw values of the bytes, in decimal form):

2 192 168 0 20 0 4 49 48 50 51

The device at would receive the ASCII string “1023”.

To send to a Cobox, you just send a datagram as you normally would. The cobox wraps the message in a packet and sends all the packet through to the serial port. For example, if you sent the string “AAAA” to the cobox, from IP address, then what you’d see out the serial port would look like this (again, these are the raw values of the bytes, in decimal form):

2 192 168 0 30 0 4 65 65 65 65

This means that in order to get the data in the packet, you have to discard the header. However, it also means that you get the address of the device that sent to you, so that you can respond to it. This is useful when you’re sending and responding to multiple different addresses.

Thanks to Shaye and Garry Morris for their help in figuring this out.

This entry was posted in Lantronix. Bookmark the permalink.

Comments are closed.