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