Microsoft .NET 2.0 SerialPort class, which is part of System.IO.Ports namespace, provides a framework for synchronous and event-driven I/O, and access to serial driver properties. SerialPort objects can be used to wrap a Stream objects, allowing the serial port to be accessed by classes that use streams.
Let us consider a simple windows console application, which is having the following method.
private void InitializeGS()
{
// Nice methods to browse all ports, for testing I am using COM1
string[] ports = SerialPort.GetPortNames();
// Initializes a new instance of the SerialPort class using the
// port name, baud rate, parity bit, data bits, and stop bit.
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8,
StopBits.One);
// Open the port for communications
port.Open();
// Write two bytes
port.Write(new byte[] { 0x0A, 0xFF }, 0, 2);
// Close the port
port.Close();
}
For complete article click DOWNLOAD Link