Free Basic Serial Port Programming

Serial port programming on Visual Basic with Windows API. An example how to use Windows API to control a serial port or a USB VCP. While serial port programming was absent in.NET version 1.1, Visual Basic developers who grew accustomed to the MSCOMM control in. 'This program is free software: you can redistribute it and/or modify. Reading or receiving data from serial port RS232 in visual basic 2013 (visual studio.NET). Port, but data received is coded as displays series of squares. RS232 communication, Data received. Serial port data receive. Receive Data from Serial Port. Serial port free download - HiSerial.sys Serial Port Driver, Advanced Serial Port Monitor, Ultra Serial Port Monitor, and many more programs. Virtual Serial Port Applications Programming Interface. 1.Introduction The Virtual Serial Port framework (VSP) is a product of Constellation Data. Example on how to use the serial port to communicate with visual basic for applications.

9 May 2010CPOL
Scans for installed serial ports, queries the supported baud rates, and starts listening to the selected serial port.

Introduction

This is a basic sample of serial port (COM port) listening in C#. This application is connected to a GPS sending ASCII text for test, but the serial port listening part is all byte-oriented.

CodeProject is missing a simple serial port application. Serial port listening applications usually have this only as a part of a bigger solution, while this application does nothing else than list the available COM-ports, list the available baud rates for the selected COM-port, and starts sending the data. In this solution, a form converts the data to ASCII-text and displays it in a text box.

Using the code

The serial port handling code is placed in a class called SerialPortManager. This class contains methods to start and stop listening for data on the serial port.

Finding the installed serial ports

Rather than just assuming the number of serial ports, or leaving it up to the user to know this beforehand, the code finds the installed serial ports. A string array of serial ports is received through a call made in the constructor of the class SerialPortManager.

Updating baud rates supported by the selected device

When a serial port is selected by the user, a query for supported baud rates is done. Depending on the hardware, different collections of baud rates may be supported. The field dwSettableBaud from the COMMPROP structure is a join of all supported baud rates.

Serial port settings

The class named SerialSettings contains the currently selected serial port settings, and also includes lists of alternatives for the different setting properties. Everything is data bound to the GUI.

Start listening to a serial port

The serial port is instantiated using the currently selected settings:

The actual serial port reading

The actual serial port reading runs in a threadpool. When data is received on the serial port, an event is raised and _serialPort_DataReceived is called.

The received byte array is sent to those listening for the event. The class SerialDataEventArgs houses a byte array.

Stop listening

We stop listening by simply closing the serial port. Note that this might deadlock your UI-thread if you are using Invoke in the event handling in your form.

To work around this possible deadlock, a BeginInvoke is needed. And, that is generally good practice as well.

Summary

Serial

A rather simple sample in how to implement serial port listening has been provided.

Updates

Serial Port Communication

  • 27 April 2010 - Code clean-up and getting < > to show in the article.
  • 10 May 2010 - Fixing some misspells in the article.

Serial Port Programming