3/30/2018
Posted by 
Serial Communications In Win32 Sample 6,5/10 3024reviews

• • Introduction The purpose of this article is to describe how to interface to serial port on Win32. The serial port can be implemented by several techniques such as ActiveX, access I/O and file operation. This article explains the use of serial port on Win32 platform by file operation technique.

Give More FeedbackSerial Communications In Win32

Demonstration of the use of Win32 function for serial port communication. Non Overlapped Serial Port Communication. The following code is a sample shown.

The programmer can use kernel32.lib library that is provided with the Microsoft Visual C++ Version 6.0. In Microsoft Windows (2000, Me, XP and 95/98), serial port can be treated as a file. Therefore it's possible to open a serial port by using Windows file-creating function. This article explains not only about serial port communication but also how to implement multi-tasking that can apply with our project 'serial port' application.

The reason why the software (serial communication) will be implemented with multi-tasking method is that the serial communication application has to handle work with more than one task at the same time. For example data-reading task, data-sending task, GUI task etc. These topics describe the basic operation of interfacing a serial port on Win32: Initial/Open serial port communication. • • • • • Receive/Send data • • • Design approach Initial/Open serial port The first step in opening a serial port is initiation or setting a serial port's configuration. The purpose of this is to create the serial port agent. Aircraft Maintenance Training Programs here. All throughout the article we are going to use a file handle as serial port agent. The serial port's handle is a handle that can be used to access the object of serial port.

The function that is used to create the serial port handle is the CreateFile function. The following code shows the function that is used to create a handle: handlePort_ = CreateFile(portName, // Specify port device: default 'COM1' GENERIC_READ GENERIC_WRITE, // Specify mode that open device.

0, // the devide isn't shared. NULL, // the object gets a default security. OPEN_EXISTING, // Specify which action to take on file.

0, // default. NULL); // default. As figure 2 shows, portName = 'COM1': the portName is a variable that is declared by const char*.