Using serial port (rs232) terminals in Linux

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A thread documanting my trials and tribulations using a serial port in Linux. May eventually turn into a tutorial. I have been looking for a hterm or bray's terminal substitute for use under Linux, but there seems to be little info on what and how to make stuff work.

My current setup:
Fedora core 8
Keyspan USA-19HS usb to serial adapter
STK500 board

=========
Setup hardware
=========
Luckily my Keyspan usb to serial adapter was automatically recognized and set up as /dev/ttyUSB2 by Fedora. Run

dmesg

after you plug in the adapter to see if the device was set up. You should see something like:

usb 7-1: new full speed USB device using uhci_hcd and address 6
usb 7-1: configuration #1 chosen from 2 choices
keyspan 7-1:1.0: Keyspan 1 port adapter converter detected
usb 7-1: Keyspan 1 port adapter converter now attached to ttyUSB2

The last line tells you that the adapter was set up as ttyUSB2. Check the dev folder by running

ls -al /dev/ttyUSB*

crw-rw---- 1 root uucp 188, 2 2008-03-13 12:30 /dev/ttyUSB2

**Important note: "Permission denied" errors
Notice that /dev/ttyUSB2 is owned by the root user and the uucp group. You might get "Permission denied" errors when trying to use the /dev/ttyUSB2 port if you are not root or a member of the uucp group. There are a couple of options around this.
A) 'su' to root
B) prefix 'sudo' to your commands. ex: 'sudo stty -F /dev/ttyUSB2 9600'
C) add yourself to the uucp group. 'gpasswd -a me uucp'
D) make the /dev/ttyUSB2 device readable and writable to everyone. sudo chmod 0666 /dev/ttyUSB2
E) create a udev rule to make the /dev/ttyUSB2 device readable and writable by everyone whenever the adapter is plugged in. (too complicated to explain here)

Set up the baud rate with the stty command. I'm using 115200, so I run

stty -F /dev/ttyUSB2 115200

. To verify the settings, run

stty -F /dev/ttyUSB2

speed 115200 baud; line = 0;
min = 1; time = 5;
ignbrk -brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

You can do some very primitive debugging. Receive data from the STK500 by opening a terminal window and running

cat /dev/ttyUSB2

You can send characters by running

echo "send this" > /dev/ttyUSB2

But it would be really much better if all this could be done inside one program, and maybe get some hex or binary viewing too.

===========
Candidate programs:
===========
* HTerm under Wine
* Bray's Terminal under Wine
* Minicom
* Picocom
* Gtkterm
* Cutecom

===========
HTerm and Wine
===========
I installed wine using yum.

sudo yum install wine

Setup the serial port to be recognized by wine. Create a symbolic link to /dev/ttyUSB2 in ~/.wine/dosdevices. (run 'wine hterm.exe' first so that wine can create the ~/.wine directory).

ln -s /dev/ttyUSB2 ~/.wine/dosdevices/com5

I chose com5 because I already had /dev/ttyS0 thru /dev/ttyS3 which get mapped to com1 thru com4 in wine.
I can run HTerm in Wine,

cd ~/hterm && wine hterm.exe

but HTerm doesn't seem to recognize my serial ports under Wine. I can connect to com5, but nothing really happens. There's an error in the console: 'fixme:comm:set_queue_size insize 4096 outsize 4096 unimplemented stub' so maybe HTerm is calling something that isn't implemented in Wine. Also, there's something glitchy about the cursor placement when you type in text. The cursor is about one character in front of where it should be.

===========
Bray's Terminal and Wine
===========
Bray's website http://bray.velenje.cx/avr/terminal seems down right now, but I downloaded terminal.exe from here http://www.myplace.nu/mp3/download.htm (scroll down to the "Tools and Others" section)

Set up the serial ports as described in the above HTerm section.

cd ~/bray && wine terminal.exe

Bray's terminal actually works when you connect! :)

============
Minicom v2.2
============
I finally got minicom working, although I don't really like minicom. It's like running hyperterminal in windows... yucky.

Run the minicom setup.

sudo minicom -s

Go to Serial port setup and set the Serial Device to /dev/ttyUSB2. (Press A to change the Serial Device, and press Enter when you are finished to go back to the menu)
Press E to set the baud rate (Bps/Par/Bits). I'm using 115200 bps. If you know what stop bits and stuff you need to use, set it here. If you don't know, I think '8N1' is pretty standard and should work. My setting reads 115200 8N1
Press F to set the Hardware flow control to 'No'.
Press G to set the Software flow control to 'No'.
Leave Callin Program and Callout Program blank. (I have no clue what these do)
Press Enter to go back to the main menu.

Go to the Modem and dialing menu. I'm not sure if this is necessary, but I deleted all of the strings in here. Press Enter to go back to the main menu.

Go to the Screen and keyboard menu. Press Q and set the Local echo setting to Yes. This allows you to see what you are sending over the serial connection in the terminal. Press Enter to go back to the main menu

Choose Save setup as dfl then Exit the minicom setup. It should start up minicom.

In the minicom window you should be able to start typing to send characters. Press 'ctrl-a z' to see a list of menu options. I have to go to the menu and set the local Echo to off then on each time to see my input, even though it's supposed to be saved in the settings

==========
Picocom v1.4
==========
I try running picocom

sudo picocom --baud 115200 /dev/ttyUSB2

but I'm not sure if it's working. Press 'ctrl-a x' to exit the program.

==========
Gtkterm v0.99.5
==========
Run gtkterm

sudo gtkterm

Go to Configuration => Port and setup the device and baud rate. Turn on the Local Echo by making sure Configuration => Local Echo is checked. Now start typing!

==========
Cutecom
==========
There was no cutecom package in yum, so I have to compile it myself. I downloaded 0.20.0 from their site http://cutecom.sourceforge.net
Install cutecom:

su -
yum install qt4-devel.x86_64 cmake
tar xzvf cutecom-0.20.0.tar.gz
cd cutecom-0.20.0
less README

The README says to make sure to use qt4's qmake. Check which qmake is in your path with

which qmake

This returns '/usr/lib64/qt-3.3/bin/qmake' for me, which is qt3's qmake. Find where yum put qmake for qt4

find / -name qmake 2>/dev/null

Looks like qt4's qmake is at /usr/lib64/qt4/bin/qmake. Add this to the PATH variable like it says to do in the README

export PATH=/usr/lib64/qt4/bin:$PATH
cmake .
make
make install

The install went ok. Running Cutecom opens up a nice Bray-esque interface. :)

Last Edited: Fri. Mar 14, 2008 - 12:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

minicom is perhaps the most popular linux serial program.

Here are some links for you:

http://www.cyberciti.biz/tips/co...

http://www.vanemery.com/Linux/Se...

http://tldp.org/HOWTO/Serial-Pro...

http://www.comptechdoc.org/os/li...

Eric

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think there was supposed to be a Linux version of RealTerm, but I think there will be none.

Using serial ports in Linux with C code is simple, but I am no GUI or text user interface guy.. Maybe you could use Gambas to create basic-like GUI programs to use your serial port?

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the suggestions and links. I would like to use a program, instead of having to program my own. I've been spoiled by HTerm in windows. 0=) I'm hoping Cutecom works out.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cutecom works nice. minicom is the "standard", but it is a good idea to create a profile without modem setup and moden reset commands.

There are a bunch of other tools too. E.g.

screen
cu
tip -

The last two are so old you probably don't have them any more on your system.

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a great tutorial, thanks a lot.

I'm running linux (ubuntu) on an asus eeepc and I'm using a USB-RS232-Adapter to connect to an Atmega32. Unfortunately the command

sudo stty 9600 -crtscts -echo -ixoff -F /dev/ttyUSB0
$ stty -F /dev/ttyUSB0
speed 9600 baud; line = 0;
eof = ^A; min = 1; time = 5;
ignbrk -brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

sudo cat /dev/ttyUSB0

did not work, but with the minicom application it works perfectly. The settings used for minicom are 9600 baud 8N1

Linux max-eee 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux

Bus 003 Device 010: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

[34582.431122] pl2303 3-1:1.0: pl2303 converter detected
[34582.443301] usb 3-1: pl2303 converter now attached to ttyUSB0