How to Read & Write the COM Port - A Step by Step Approach
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
Next

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > win32 > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction