How to Read & Write the COM Port - A Step by Step Approach
CoderSource.net
How to Read & Write the COM Port - A Step by Step Approach - Article by bagavathikumar
Level: BeginnerType: Article
Rating: 3Page: 1 of 3

Date: 2/3/2006 12:00:00 AM

Environment: Windows, VC, VC.NET

Choose New Project from Visual Studio's File menu.

In the New Project dialog box, select the MFC Application template, type the name as ReadCOM, and click OK. It will open the MFC Application Wizard, accept all the defaults but two: On the Application Type page, select Single Document, and on the Generated Classes, select Base Class as CFormView. When you're finished, click Finish

Part I.

Go to the ClassView and Select the CReadCOMView Class and do the following steps.

Step 1: Create a class variable called uResult of the type UINT, which is used to hold the return value of the SetTimer function.

Right click the CReadCOMView in ClassView and select add -> add Variable. It will show the Add

Member Variable Wizard. Enter the variable type is UINT and the name is uResult.

    UINT uResult;               // SetTimer's return value


Step 2: Create a class variable called m_nPortNumber of the type int, which is used to hold COM port Number like 0, 1, 2. By Defult tha value of the port number is 0.

Right click the CReadCOMView in ClassView and select add -> add Variable. It will show the Add Member Variable Wizard. Enter the variable type is int and the name is m_nPortNumber.

    int    m_nPortNumber;


Step 3: Create a class variable called m_bConfigStatus of the type BOOL, which is used to hold the Status of the port initialization process. if it is success, it will return TRUE else FALSE.

Right click the CReadCOMView in ClassView and select add -> add Variable. It will show the Add Member Variable Wizard. Enter the variable type is BOOL and the name is m_bConfigStatus.

    BOOL m_bConfigStatus;


Step 4: Create a handle variable, which is a file handle. because we will read and write the port like a file.

Right click the CReadCOMView in ClassView and select add -> add Variable. It will show the Add Member Variable Wizard. Enter the variable type is HANDLE and the name is m_hFile.

       HANDLE m_hFile;


Attachments

Source Files Sample Program

1 2 3

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us