[SWLUG] Serial ports

Justin Mitchell justin at discordia.org.uk
Mon Jul 31 13:25:49 UTC 2006


On Mon, 2006-07-31 at 13:42 +0100, Steve Anderson wrote:
> Hiya LUGarinos.
> 
> Real quick[1] question, hopefully a real simple answer. I've got an
> old till display hooked up to the serial port on a PC. It's configured
> to 38400 bps, 8-N-1, no flow control. On Windows I can run Hyperterm
> on COM1, select those settings, type away and the letters come up on
> the display. I could probably set those settings as the default for
> the port and redirect echos at the serial port.
> 
> Under Linux, what I want to do is configure /dev/ttyS0 to those
> settings and get the same result. Having looked around it looks like
> "stty" or possibly "setserial" will let me get the settings correct
> but I'm having difficulty following what's going on, because most (if
> not all) of the resources I've found are talking about having a
> terminal hooked up to the serial port and seem to be aimed more at
> that particular kettle of fish.

first off, make sure that the cable has been wired so that the CD line
is asserted, otherwise you will have to fiddle around to avoid it.

you can use programs like minicom to talk directly to the serial port
and tweak all the settings, or you can treat it like a file and read
directly, in which case you use the stty program to change the settings.

you want: stty 38400 -crtscts -ixoff -parenb < /dev/ttyS0
you can list the current settings with: stty -a </dev/ttyS0

-crtscts  means 'no hardware flow control'
-ixoff    means 'no software flow control'
-parenb   means 'no parity bit'

to read from the serial port then you can just 'cat /dev/ttyS0' to write
to it you can 'echo "hello" >/dev/ttyS0'







More information about the Swlug mailing list