Using CU as terminal emulator


Many of us use Linux as primary development station for microcontrollers. Long time back I discovered a simple terminal emulator or Linux called CU ( From it's man page - Call up another system / Call Unix). CU was originally developed to connect to other UNIX systems using serial modems or null-modem connection. This was before network systems like Ethernet or Token Ring were developed. I still remember in my UNIX lab 8x dumb terminals were connected to a server with one Eight Port serial adapter in good old days.

CU is a very low footprint terminal emulator for Linux / UNIX based systems.

Only thing that you would have to remember is how to connect and disconnect from the terminal.

Installing:

I installed CU on xUbuntu using the following command


sudo apt-get install cu


This will ask for your sudo password and install cu with all dependencies.


Now, to run cu (or any terminal emulation program)  following minimal parameters are needed:

1. Port number
2. Speed of the serial port


I connected an PL2303 based USB to serial adapter to my Linux machine and it detected it as device ttyUSB0. I found the device name using Linux command "dmesg" as it appeared right after I connected the hardware device.

Here is the sample output of the dmesg command (your experience may vary):

[  215.320221] usb 1-2: new full-speed USB device number 3 using ohci_hcd
[  215.877355] usbcore: registered new interface driver usbserial
[  215.877364] USB Serial support registered for generic
[  215.877383] usbcore: registered new interface driver usbserial_generic
[  215.877386] usbserial: USB Serial Driver core
[  215.885268] USB Serial support registered for pl2303
[  215.885284] pl2303 1-2:1.0: pl2303 converter detected
[  215.917802] usb 1-2: pl2303 converter now attached to ttyUSB0
[  215.917818] usbcore: registered new interface driver pl2303
[  215.917821] pl2303: Prolific PL2303 USB to serial adaptor driver

So this confirms (in my case) that operating system recognized that USB<->Serial hardware as ttyUSB0.

Each individual case may be different as your operating system can recognize it as a different device. Use the device name that is reported by your OS.

So, now we got one parameter that we need to pass to cu command and that is the port number or a port device (UNIX).

Now we need to determine what speed we need to connect to that terminal / target device. The speed totally depends on your target device. For example I'm connecting to a GPS Engine (target device) chip that communicates at 9600 baud.

This is the simplistic setup as I am not discussing the parity, start bits, stop bits, flow control etc. If your device obeys a certain protocol, you can specify that at cu command line.

Here is a manual page for cu on Linux systems:

http://linux.die.net/man/1/cu

You can specify other parameters (from man page) as below:

--parity=even
--parity=even
--parity=none

--nostop   #Turn off XON/XOFF handling (it is on by default)

-h, --halfduplex #Echo characters locally (half-duplex mode).


You get the point by now...

Running:

I connect my GPS device (9600 n,8,1) with cu as under:


chetan@xubuntu:~$ cu --line /dev/ttyUSB0 --speed 9600
Connected.
bbbj�,M,,*45
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,054205.391,V,,,,,0.00,0.00,090615,,,N*4B
$GPGGA,054206.391,,,,,0,0,,,M,,M,,*46
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,054206.391,V,,,,,0.00,0.00,090615,,,N*48
$GPGGA,054207.391,,,,,0,0,,,M,,M,,*47
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,054207.391,V,,,,,0.00,0.00,090615,,,N*49
~.

Disconnected.


As you can see that I was able to successfully connected to the GPS device using command

cu --line /dev/ttyUSB0 --speed 9600


I was able to successfully communicate with the device at 9600 N81 @ port /dev/tty/USB0

At the end you see a command "~." this terminates the cu session. When you are ready to disconnect with your device (GPS in my case) just type a ~ and a . (dot) and hit enter. You will then be disconnected from your device. You need to remember the disconnect procedure as CU would not provide any help in the session.

Logging Output:

In case you want to log output of the session you can start "cu" with "tee" as below:

cu --line /dev/ttyUSB0 --speed 9600 | tee logfile.txt

this will log your session output in file "logfile.txt".

Bottom Line:

CU is a great lightweight program to communicate with serial / UART / USART  devices available on many UNIX platforms including FreeBSD. Please comment.

Comments