Click here to Skip to main content
Click here to Skip to main content

Serial Port Configuration Dialog

, 28 Oct 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Generic configuration dialog for a serial port
Screenshot - frmComm.png

Introduction

Quite a few times in my hardware projects, I had to send some calibration data between a microcontroller (Microchip PIC) and a PC through a serial port (RS-232). The software on the PC side is written in VB6 with an MSComm control. The latter has to be configured with parameters: port number, baud rate, number of data bits, number of stop bits. Configuration of an MSComm is a fairly common task (it used to be even more common in the past). So, at first I thought that there should be a dialog for that available on the web. Unfortunately, such a dialog was nowhere to be found, and I wrote one myself. Hopefully, it turned out generic and reusable enough.

Features

  • Automatic detection of serial ports
  • The most recent port settings are stored in the INI file
  • Interface supports configuration of multiple ports in the same program

Dialog

Configuration is done in the frmComm dialog.

ShowConfig

Declaration

Public Function ShowConfig( _ 
    ByRef comm As MSComm, _ 
    Optional ByRef strIniFile As String, _ 
    Optional ByRef strSection As String) _ 
    As VbMsgBoxResult 

Purpose

Set-up the configuration dialog and show it to the user. cboPort is copulated with a list of available COM ports.

Parameters

  • ByRef comm As MSComm

    MSComm which will be configured in the dialog. If the comm is already open, the GUI is pre-loaded with its configuration and is comm closed.

  • Optional ByRef strIniFile As String

    Optional name of the INI file containing configuration information. GUI is pre-loaded with the settings from the INI file.

  • Optional ByRef strSection As String

    Optional name of the section in the INI file containing the configuration information. If the section name is not supplied, default name serial_port is used.

Return Value

  • vbOK when configuration was successful
  • vbCancel when user decided to cancel configuration

QuietConfig

Declaration

Public Function QuietConfig( _ 
    ByRef comm As MSComm, _ 
    ByRef strIniFile As String, _ 
    ByRef strSection As String) _ 
    As VbMsgBoxResult 

Purpose

Configure the target MSComm with parameters from the local file without showing the configuration dialog.

Pre-conditions

The supplied INI file contains the configuration information.

Post-conditions

The target MSComm is configured but not opened.

Parameters

  • ByRef comm As MSComm

    MSComm will be configured from the INI file. If the comm is already open, it will be closed.

  • ByRef strIniFile As String

    Optional name of the INI file containing configuration information. GUI is pre-loaded with the settings from the INI file.

  • ByRef strSection As String

    Optional name of the section in the INI file containing the configuration information. If the section name is not supplied, default name serial_port is used.

Return Value

  • vbOK when configuration was successful
  • vbAbort if the INI file was erroneous or non-existent

INI file

Loading and Saving

The dialog is populated with the parameters from the INI file, if the name of the file is supplied.

Structure

Multiple sections for multiple ports within the same INI file, or individual INI files for multiple ports. The name of the INI file section can be chosen by the user, the default name is serial_port.

KEY: CommPort - port number as in MSComm.CommPort

KEY: Settings - port settings same format as in MSComm.Settings

Closing Remarks

Please let me know if you find any bugs or have any suggestions!

References

[1] Serial port configuration dialog in HyperTerminal

[2] Root MSDN article for MSComm control
http://msdn2.microsoft.com/en-us/library/aa259393.aspx

Revision History

Rev# Notes Date Author(s)
0.1 Initial draft June 4, 2007 Nick Alexeev
0.2 Added missing frmComm.frx to the project files June 18, 2007 Nick Alexeev
0.3 Updated the article July 23, 2007 Nick Alexeev

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Nick Alexeev
Systems Engineer Prolitech
United States United States
doing business as Prolitech
Redwood City, CA
http://www.prolifictec.com

Comments and Discussions

 
GeneralNeed frmAbout.frx file ... Pinmemberaaaaazzerty9-Sep-08 0:08 
GeneralRe: Need frmAbout.frx file ... PinmemberNick Alexeev28-Oct-08 20:57 
Generalmicrocontroller AduC + C# PinmemberJuan Silva4-Nov-07 11:32 
AnswerRe: microcontroller AduC + C# PinmemberNick Alexeev5-Nov-07 0:14 
QuestionHow can read from HyperTerminal? Pinmemberulduz6-Oct-07 2:20 
Questionwhat is this method for ? Pinmemberbesthms31-Jul-07 4:43 
Generali try that method and dosent work Pinmemberbesthms31-Jul-07 4:13 
GeneralRe: i try that method and dosent work PinmemberYAIR-I22-Sep-07 10:45 
QuestionHelp please in Serial Port ? Pinmemberbesthms27-Jul-07 7:47 
AnswerRe: Help please in Serial Port ? PinmemberNick Alexeev27-Jul-07 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 29 Oct 2008
Article Copyright 2007 by Nick Alexeev
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid