With The Case Of  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
ActiveX COM Products
Technical Support
  General Q & A
Discussion Board
Contact Us


Get Ready to Unleash the Power of UCanCode .NET

UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"

Visual C++ Serial Data Communication, with Open Port, Close Port and Write, data tranmission, and read data



Serial Data transmission seems a bit difficult for those who are new to the world of serial communication and Visual C++. Long ago, I had searched on for some help on serial data transmission and I got some valuable information. It was my dream to develop a simple class for implementing serial data transmission since then.

After getting seven months practical experience in the field of serial communication, I have developed a simple class for implementing serial transmission using WinAPI functions.

Serial Data Tranmission Basics

In serial data 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.

The 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 software.

The various steps to be performed for sending and receiving data through the serial port of a PC are listed below:-

  1. Open the communication port
  2. Configure the communication port by setting the Baud rate, parity, no. of data bits, etc.
  3. Set time-outs for communication.
  4. Write data to the port.
  5. Read data from the port.
  6. Close the port.


Opening The Serial Port

The CreateFile() function opens a communications port. There are two ways to call CreateFile() to open the port - OVERLAPPED and NON-OVERLAPPED. You can open a Communication Port for OVERLAPPED IO operation and NON-OVERLAPPED IO operation. The CSerialCom class is written for NON-OVERLAPPED IO operation. For more details on OVERLAPPED & NON-OVERLAPPED IO, please refer to the MSDN documentation.

Configuring Serial Ports

The most critical phase in serial communication programming is configuring the port settings with the DCB structure. Erroneously initializing the DCB structure is a common problem. When a serial communications function does not produce the expected results, the DCB structure may be in error. A call to the CreateFile() 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.

Configuring Time-Outs

An application must always set communication time-outs using the COMMTIMEOUTS 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 functions.

Writing to a Serial Port

The WriteFile() function transfers data through the serial connection to another device. Before calling this function, an application must open and configure a serial port.

Reading from a Serial Port

An application calls the ReadFile() function to receive data from a device at the other end of a serial connection.

Closing a Serial Port

You 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 NON-OVERLAPPED IO operation. Call the CloseHandle() function to close the serial port. CloseHandle() has one parameter, which is the handle returned by the CreateFile() call that opened the port.

The leader in visualization component -- FULL VC++ Source Code Shipped!

XD++ Diagrammer Suite is the the world’s leading VC++ and .NET visualization component. Renowned for incredibly rich graphics, XD++ helps thousands developers build applications that offer unparalleled functionality. Outstanding productivity lowers project risk and reduces maintenance headaches. With 20 years of dedicated research and development, UCanCode leads the market for visualization technologies, providing outstanding customer support.

Download and try it 


Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to