From Jason_Magill on Thu, 23 Sep 1999
I have an application that I am running that requires me to read the serial port (Com2). The problem is that I need to read it at 9600 7-E-1. How would you go about doing that so when the system is rebooted it will automatically read the serial port at 9600 7-E-1?
I could really use your help.
You should be able to do that with the following command:
stty 9600 parenb cs7 < /dev/ttyS1
... or something like that.
Note you must redirect INPUT from the serial port to the 'stty' command. This is because the terminal settings are accomplished through an ioctl().
You might also look at the 'setserial' program. It works a bit differently (and is Linux specific) whereas the 'stty' program has been around for UNIX for many years.
Note also that we use ttyS1 for MS-DOS COM2. This is because Linux counts these devices from zero. There is no guarantee that Linux will detect these ports in the same order as MS-DOS, but usually COM2 should be /dev/ttyS1.
The parenb is to set "parity even" (I don't know why the have the "b" there --- for "byte" maybe?) and the cs7 is to set the "character size." There are many other 'stty' settings available. Read the 'man' page for details.