5.21. Access a COM Port

Problem

You need to send data directly to a serial port.

Solution

Use the System.IO.Ports.SerialPort class. This class represents a serial port resource and defines methods that enable communication through it.

How It Works

The .NET Framework defines a System.IO.Ports namespace that contains several classes. The central class is SerialPort. A SerialPort instance represents a serial port resource and provides methods that let you communicate through it. The SerialPort class also exposes properties that let you specify the port, baud rate, parity, and other information. If you need a list of the available COM ports, the SerialPort class provides the GetPortNames method, which returns a string array containing the names ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.