transmission seems a bit difficult for
those who are new to the world of
Long ago, I had searched on ucancode.net
for some help on
serial data transmission
and I got some valuable information. It
was my dream to develop a simple class
serial data transmission
getting seven months practical
experience in the field of
communication, I have
developed a simple class for
implementing serial transmission using
transmission the data is
transmitted in serial format with the
LSB of the byte to be transmitted,
shifted out first among the data bits.
The general format for serial
transmission is Start Bit + Data
Bits + Parity Bit (Optional) + Stop Bit.
Parity bit is optional. It is used for
error checking in communication. You can
enable or disable parity checking by
software modifications. Also, you can
specify which parity you would like to
use, either 'EVEN' or 'ODD' through
various steps to be performed for
sending and receiving data through the
serial port of a PC are listed below:-
communication port by
setting the Baud rate, parity, no.
of data bits, etc.
Set time-outs for
to the port.
Read data from the port.
Close the port.
communications port. There
are two ways to call
to open the port -
You can open a Communication Port for
IO operation and
IO operation. The
class is written for
IO operation. For more details on
IO, please refer to the MSDN
Configuring Serial Ports
most critical phase in serial
communication programming is configuring
the port settings with the
structure. Erroneously initializing the
structure is a common problem. When a
serial communications function does not
produce the expected results, the
structure may be in error. A call to the
function opens a serial port with
default port settings. Usually, the
application needs to change the
defaults. You must set the Baud rate for
communication, Parity functions, no. of
Stop Bits, etc. in accordance with the
requirements of the external device by
calling appropriate WinAPI functions.
application must always set
communication time-outs using the
structure each time it opens a
communication port. If this structure is
not configured, the port uses default
time-outs supplied by the driver, or
time-outs from a previous communication
application. By assuming specific
time-out settings when the settings are
actually different, an application can
have read/write operations that never
complete or complete too often. You must
configure the read & write time-outs by
calling the appropriate WinAPI
a Serial Port
function transfers data through the
serial connection to another device.
Before calling this function, an
application must open and configure a
from a Serial Port
application calls the
function to receive data from a device
at the other end of a serial connection.
must close the communications port after
serial transmission in order to make
this port available for other
applications which use this resource. As
long as you are working with a port
(i.e. the port is in an open state),
other threads or applications will not
be able to access to this port till you
close the handle to that port in
IO operation. Call the
function to close the serial port.
has one parameter, which is the handle
returned by the
call that opened the port.