Friday, March 16, 2007

USB to Serial Adapter

My new laptop doesn't have a serial port. This is one of the great tragedies of modern laptops in my opinion. At least for situations where I want to connect to the serial port on a server or system with a serial port, I can use a USB to serial adapter like this adapter I bought at NewEgg. I tested it just now by connecting to the serial port on my old FreeBSD laptop.

First I enabled the serial port in /etc/ttys

#ttyd0 "/usr/libexec/getty std.9600" dialup off secure
ttyd0 "/usr/libexec/getty std.9600" dialup on secure

Then I restarted init to activate it.

# kill -HUP 1

On my Ubuntu laptop I attached the USB to serial adapter to a null modem and a gender changer, then connected it to the FreeBSD laptop serial port.

I installed cu(1) on Ubuntu

# apt-get install cu

then checked dmesg output to ensure I had a device to which I could connect.

[17213831.716000] usb 1-1: new full speed USB device using uhci_hcd and address 2
[17213831.876000] usb 1-1: configuration #1 chosen from 1 choice
[17213831.984000] usbcore: registered new driver usbserial
[17213831.984000] drivers/usb/serial/usb-serial.c: USB Serial support registered for generic
[17213831.984000] usbcore: registered new driver usbserial_generic
[17213831.984000] drivers/usb/serial/usb-serial.c: USB Serial Driver core
[17213831.988000] drivers/usb/serial/usb-serial.c: USB Serial support registered for pl2303
[17213831.992000] pl2303 1-1:1.0: pl2303 converter detected
[17213831.992000] usb 1-1: pl2303 converter now attached to ttyUSB0
[17213831.992000] usbcore: registered new driver pl2303
[17213831.992000] drivers/usb/serial/pl2303.c: Prolific PL2303 USB to serial adaptor driver

Now that I saw /dev/ttyUSB0 was enabled, I connected to it.

richard@neely:~$ cu -l /dev/ttyUSB0

FreeBSD/i386 ( (ttyd0)

login: richard
Last login: Fri Mar 16 11:57:49 on ttyv1
Copyright (c) 1992-2006 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.

FreeBSD 6.1-SECURITY (GENERIC) #0: Wed Feb 14 15:33:28 UTC 2007

Welcome to FreeBSD!

That's it. If I needed to set a different speed I'd use the -s switch. For example, if 9600 above was 19200 in /etc/ttys, I'd use syntax like

richard@neely:~$ cu -l /dev/ttyUSB0 -s 19200

Now I know I can rely on this USB to serial adapter when I visit servers in the data center.


John Ward said...

Thats cool. I had the same problem with my laptop not having a Parallel port. You should remember my rewired SNES controller from back in the BATC days. Well, it requires that a particular pin have a 5V output, which not all parallel ports have. So I tried one of those USB adapters, but it didn't quite work. They make newer USB adapters for these controllers which I may pick up. So be wary, different standards may prevent your setup from working in all scenarios, but at least it is good to know that there is at least a baseline to work from if I ever come across this.

By the way, is that off of a Thinkpad? I noticed a bunch of those at Eclipsecon that had Parallel ports, but no serial port. Strange that the Dells are the exact opposite.

Anonymous said...

We have brought a bunch similar USB-RS232 converters at work for the same reasons.

The windows drivers are notoriously buggy, producing a blue screen if you use them for too long.

Babak Farrokhi said...
This comment has been removed by the author.
pvaneynd said...

They also gave us one, but we have no end of problems with it. Sometimes the speed won't change or it cannot send a break.

The IBM serial+parallel port thing seems to work better.

Landon Lewis said...

I bought a similar adapter made by Keyspan. The 2.6.x kernel provides support for it, however Debian/Ubuntu disabled it b/c of the licensing model. So I had to recompile the kernel by hand. Not a big deal, but nothing "plug-n-pray" like your experience.

The device now works perfectly with minicom, cu, etc. I did however run into a problem using iWar in analog mode however. I would be interested to know if you get the same results with this adapter.

I blogged (in the link below) about iWar in VOIP mode and plan to write one about analog mode after resolving this issue.

Ted Demopoulos said...

Interesting -- I just bought one yesterday for my "Vista" laptop, which probably means I'll have *some* problems like everything Vista.

That said, some people seem to have zero problems, others endless headaches.

I certainly agree the lack of Serial ports is a major nuisance!

Pete said...


If you're doing a lot of work with serial I recommend using screen. It can auto-detect the speeds and settings you need.


Anonymous said...

cool, i had done that in windows, so dun have the hassle of entering the commands. of course, i can do it with nix, but i guess the project was urgent during that period of time, so i have to use windows. But well, thats a nice piece of info to have.

Richard Bejtlich said...

geek00l asked me in IRC about using this adapter to connect to Cisco gear. I connected the adapter to a rolled cable, and was able to access my Cisco switch.

Anonymous said...

i ahd try to follow the tutorial but it seem doesn't work. i cant' find /etc/ttys in my computer:
root@cceng:~# cd /etc/ttys
bash: cd: /etc/ttys: No such file or directory

do you guys have any other idea how can i use my usb to rs232 converter. Actually i want to use the usb to rs232 converter connected to ts7200 single board computer.

Anonymous said...
This comment has been removed by a blog administrator.
Matt said...

Thanks for the article; I didn't know to check dmesg for things like new usb devices. Here I was looking for a linux driver for my Dynex USB to Serial adapter, when all along Ubuntu had plug & played the thing, loaded a driver and stuck it on /dev/ttyUSB0.

I never would have guessed that this adapter would just work after plugging it in. After typing cu -l /dev/ttyUSB0 I was magically connected to my cisco router I had hooked up to it. Amazing. Thanks again.

Pepe said...

It's so easy to set up, but i had a little trouble, could you please tell me how can i close a connection, I use to kill the process number but there should be another way to close, because when i connect again it shows a warning message

pp@pp-laptop:~$ cu -l /dev/ttyUSB0
cu: Stale lock /var/lock/LCK..ttyUSB0 held by process 25339 created 2008-09-02 16:42:57

cas said...

To disconnect a cu session type ~.

Anonymous said...
This comment has been removed by a blog administrator.
Richard Bejtlich said...

Run the minicom program and using command CTRL-a z o (inside minicom) to configure the minicom serial port. Make sure the configuration look like this.

A - Serial Device : /dev/ttyUSB0
B - Lockfile Location : /var/lock
C - Callin Program :
D - Callout Program :
E - Bps/Par/Bits : 9600 8N1
F - Hardware Flow Control : Yes
G - Software Flow Control : No

Richard Bejtlich said...

Windows driver (untested)

Leviana said...
This comment has been removed by the author.
Leviana said...
This comment has been removed by a blog administrator.