Setting serial port configuration

I have 1 serial port (9 Pin) attached with my Linux server.If I give
$dmesg | grep tty , it provides me the following.
ttyS0 and ttyS1 .
I have 1 COM port with my server mother board. I have 1 customized application
that requires this COM port to be used.
The parameter to be set for COM port is as follows.

Baud Rate:- 9600
Data Bit: - 9
Parity: - None
Stop Bit: - 1
Flow Control :- None

How to set these parameters for this COM port(I guess ttyS0 is the required COM port) in Red Hat Linux 5.9?

There's is no such thing as 9 bit RS-232. The road is 8 bits wide, period; you can send 7 bit or 8 bit trucks down it but not 9.

Sometimes you see 8-bit with parity misused to send an extra bit instead of parity. It's a serious pain to communicate with these devices anywhere, the 9th bit ends up coming in as parity error or on a sideband of some sort. You'd use stty to set serial port settings on a Linux system, but there's no setting to make the 8 bit road 9 bits wide, as your computer uses 8-bit bytes, not 9-bit ones.

Your application is going to have to either be modified or read through a filter.

Linux can do slightly better than having to calculate parity for each byte and check if it's error or not to deduce the 9th bit, but only slightly. See mark/space parity for a full explanation.

It is a typical mistake from My side.Data Bit should be 8 instead of 9.
I need the commands to do so.

---------- Post updated at 06:52 AM ---------- Previous update was at 02:17 AM ----------

To set the following I have used the following command.

Baud Rate:- 9600 Data Bit: - 8 Parity: - None Stop Bit: - 1 Flow Control :- None
$stty 9600 cs8 -parenb -ixon -cstopb -echo -F /dev/ttyS0

If you see again the parameter by the following command, it shows the attibute as set by the above command.

$stty -a -F /dev/ttyS0

Do I need to restart the machine after that?

A restart should not be necessary for the current run.

You could also look at the 'raw' extension, (man stty):-

 stty -F /dev/ttyS0 raw 

Oh, thank goodness -- that's much, much easier.

You do not.

Indeed, if you do, you'll have to set it again. Remember that -- you might want to put it in local.start or in an @reboot cron job.

wisecracker speaks wisely. UNIX serial ports have far more settings than data bits and flow control. See Canonical and noncanonical mode in man termios. What you need depends on the needs of your application (reading lines of text? canonical. reading individual bytes of binary data? raw.)