5/30/2009

Linux RS232 Programming

1. http://www.avsforum.com/avs-vb/archive/index.php/t-838364.html

At the simplest level, if you don't mind the command line (which is where the power of Linux lies anyway, so not using the command line when setting up a powerhouse HTPC is like not using the Tiptronic mode of your new Acura), you can control a serial device with two steps:

1. set the baud rate
stty -F /dev/ttyS0 [[]baud rate[]]
i.e.
stty -F /dev/ttyS0 115200
stty stands for set teletype
/dev/ttyS0 is the UNIX equivalent to COM1 in Windows

2. send the control string
printf "blahblah" > /dev/ttyS0
i.e.
printf "Input 02\r\n" > /dev/ttyS0
printf "\x08\x0f" > /dev/ttyS0
\r\n prints a Windows-style newline, in case your device requires such a newline after a command. \x lets you use hexadecimal bytes directly, as my Plus projector required, for example.

To go beyond one-way control, there is a program called chat or expect or something like that, that can run scripted conversations with your devices. It was designed for handling logins to dial-up Internet/network access back in the day. Beyond that, you can write something in C/C++, perl, bash, or any other language to do your bidding.

2. S-Jinn
S-Jinn is a free, lightweight, open-source Linux application written in C. It is a simple command-line tool designed for sending & receiving data from PC controlled TIA/EIA-232 (RS-232) test, measurement, and control devices.

3. A Linux serial port test program

4. Serial Programming Guide for POSIX Operating Systems

5. Linux Serial Programming Howto

0 comments: