Tom's Main Menu

Physical Computing Home

Intro to Physical Computing Syllabus

Networked Objects

Sustainable Practices

blog

Resources

code, circuits, & construction

my del.icio.us links

 

CoBox Micro and Xport: Configuration Notes

 

Once you've got the Cobox Micro or Xport wired up, the integration guide comes in very handy. The guides for both can be found online here. They go into more details on the setup options than are covered here. There are a variety of ways to set the Lantronix devices up. For the initial setup, it's easiest to do it serially. Connect the device's serial port 1 (pins 3 and 4 on the 12-pin connector underneath of the Cobox; pins 4 and 5 on the Xport) to a PC's serial port through a hex inverter or MAX232 chip. Open any terminal program to connect to the serial port (I use Hyperterm on the PC, Zterm on the Mac) at 9600-8-N-1. Open the serial port on the computer, then, while holding down the "x" key, power up the device (this is covered in detail in the installation guide). A menu will come up allowing you to modify the various settings of the Micro.

Configure the device as follows:

Server settings (main menu item 0) This sets the IP address for the device:

  • IP address: as given to you by your administrator
  • Gateway address: as given to you by your administrator
  • Netmask (number of bits for host part): 8 (equates to 255.255.255.0)

Channel 1 settings (main menu item 1) This configures how the serial port will work, and how you'll connect to it from the net:

  • Baudrate: 9600
  • I/F Mode: 4C (sets the various baud mode bits; see manual for details)
  • Flow: 00
  • Port No: 10001 (or whatever other port number you choose)
  • Connect Mode: C4 or D4 (or C5 or D5 for auto-connect)
  • Remote Address: address of whatever machine you want it to connect to automatically on startup (works only if connect mode is C5 or D5)
  • Remote Port no.: port number to connect to on that remote machine
  • Disconnect mode: 00
  • Flush Mode: 77
  • Disconnect Time: 00:00
  • SendChar1: 00
  • SendChar2: 00

Once that's done, you can choose main menu item 9, save and quit. You should be able to log into it from the net now. Open its IP address in a browser and you'll get a configuration applet. This applet lets you set the configuration, much like you just did, but in a graphical format.

Once you're set up, you're ready to communicate to the device from another device. The easiest way to do this at first is to use telnet. First, leave your Cobox connected to the serial port just like you did to configure it serially. Then, from the command line of your computer, telnet to the cobox's address, port 10001. On the mac, open the terminal program. On the PC, open the Run menu. On either, type:

telnet xxx.xxx.xxx.xxx 10001

where xxx.xxx.xxx.xxx is the address of your device, and 10001 is the port number you assigned for the serial connection, above. When you get a successful connection, type something. You should see it come out on your serial connection (Hyperterminal or ZTerm, from above). Then type in the serial program, and you should see the results come out on the telnet window. This is the simplest way to test the throughput of your Cobox, so remember it. You'll come back to it over and over again.

You can also configure the Cobox via telnet, once you know its IP address. Simply telnet into port 9999, and you'll get the same configuration menu from above.

See the code examples for more on connecting to the Lantronix devices from the net.


There are some useful configuration options to know about on the device, once you've got the basics in your head.

The Connect Mode Configuration Byte

The connect mode configuration is stored in a special function register on the cobox. This is just a one-byte address in memory where the configuration is stored. Each bit of the byte has a different meaning. Here are the meanings of the bits:

  • Bits 5-7: control whether the device will never accept incoming connections, accept conditionally, or always accept connections
  • Bit 4: controls the device's response to a connection.
  • Bits 3 - 0: control how the device starts up.

The details on all of these modes are in the manual, but here's an example. Setting the Connect Mode to the value C4 in hexadecimal (11000100 in binary) sets the following bits:

Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
1
1
0
0
0
1
0
0

This means: Accept any incoming connection (bits 6 and 7 = 11), no response when connections are made (bit 4 = 0), and make outbound connections manually (bit 3 - 0 = 0100). By changing these settings, and the settings of other configuration registers, you can get different functionality out of the Cobox.

Auto-Connect Configuration

If you know your device will only be connecting to one fixed IP address, it's easy to configure it to connect on startup. To do this, you set bit 0 of the connect mode to 1. For example, if you had configured the connect mode to manual connection, no response on startup, accept incoming connections unconditionally, the value would be C4, as described above. To set the device to connect automatically to another address, you'd set it to C5 instead (11000101 in binary). Then you configure the address and port number to connect to. For example, if you're connecting to a server on 128.122.151.xxx, port number 10002, you just fill those numbers in when configuring the Cobox. In the serial and telnet configuration menus, it will prompt you for them after you enter the connect mode.

Notification of Connection

Bit 4 of the connect mode controls whether the device sends a message to the serial port once it's made a connection. When it disconnects from a server, it will send an ASCII D (raw value = 43 hex). When it's not connected, it will send an ASCII N every couple of seconds until it connects. When it connects, it will send an ASCII C, then stop sending, and let whatever's coming in from the net through. If it's waiting for incoming connections, you'll get "CIxxx.xxx.xxx.xxx" when a connection is made, where xxx.xxx.xxx.xxx is the IP address of the remote device that connected to your device.

Notification can be useful when you're connecting the device to a microcontroller, because you can program the microcontroller to wait until it gets a C from the device before it starts to try to send data. You can also get the address of whoever connects to you.

To turn on notification, set bit 4 of the connect mode to 1. So instead of C4 above, you'd set it to D4 (11010100 in binary). To set autoconnect and notification on, you'd set it to D5 (11010101 in binary).

The Disconnect Configuration Byte

The disconnect configuration byte has some useful parameters as well. By changing bit 6, you can set the device to Telnet mode, and it will assume that all bytes coming in are ASCII, and will react to certain control values as control characters as defines in the ASCII chart. Once you've done that, changing bit 5 will set the device so that the raw value 04 hex will cause it to disconnect from a server. 04 is the End of transmission control character in ASCII. So with bits 5 and 6 set high and all the others low, we get 01100000 in binary. In hex, that's 60. So setting the Disconnect mode to 60 will allow you to disconnect the Cobox via the microcontroller.

Keep in mind that if you set the device to ASCII mode, you'll have some problems with byte values that are ASCII control codes. For example, imagine you were sending an analog sensor value, and the value happened to be 4. If you send the raw value, you'll disconnect the device from the server! When you're using telnet mode, it's best to send all number values as ASCII, and convert them back to raw numbers on the other end. In PicBasic Pro, you can do this by using the DEC modifier on all values you send using serout2. In BX-basic, use the Cstr() function to convert numerical values to strings. This may make programming a bit harder on the other end. Use it wisely.

Disconnect on DTR

Another method for disconnecting is to use the DTR (Data Terminal Receive) pin on the device is pin 8 of the Cobox connector. For the Xport, it's pin 8 (CP3), which has to be configured as an input. More on this below. If the Disconnect mode bit 7 is high (i.e. DisconnectMode = hex 80), you can force the device to disconnect by pulling the DTR pin low. This is convenient because you can just attach the DTR pin to a pin of your microcontroller to control disconnect.

Xport Installer Software

The Xport Installer Software is a small application for Windows that allows you to configure Xports over the net. You can search for Xports, see their configurations, and change them. To install the xport Installer software, you'll need the .NET framework, which is also on Lantronix' FTP site. Read the readme file for details on installing.

Among other things, the Installer is the only way you can set the third input pin, CP3 (pin 8), to be the serial DTR pin. To do this, open the Installer, click Search to find your device on the net, then scroll down in the cofiguration to "OEM Configurable Pins" and select "DTR" form the pulldown menu by pin 3. Then click "Update" (which can take a minute or more), and your Xport will now disconnect from all net connections when you take CP3 low.