📄 d067.bmp.txt
字号:
// deal with the error code
if (!bResult)
{
port->ProcessErrorMessage("GetOverlappedResults() in WriteFile()");
}
J // end if (!bWrite)
// Verify that the data she send equals what we tried to send
if (BytesSent != strlen《char*)port->m_szWnteBuffer》
{
TRACE("WARNING: WriteFile() error.. Bytes Sent: 96d; Message Length: %d\n",
BytesSent, strlen《char*)pofi->m_szWriteBuffer》;
}
}
2.4.3程序调试和总结
本例的详细代码请读者参见随书光盘“Chapter 2\Example 3V',读者可在Visual C++ 6.0
上同时运行两个该程序进行测试,也可以利用一个“串口调试助手”和一个运行的程序来测
试。
使用该类时要注意如下几点:
1)若程序中打开其他线程,则先终止线程,停止WaitCommEvent的等待以及关闭端口
CloseHandle,平时程序会停留在WaitCommEvent的等待中,当要终止线程的时候,程序必
须从WaitCommEvent中退出来,按照Win32手册上的说明,参数为NULL的SetCommMask
会使另一个线程中的WaitCommEvent马上返回,然后用CloseHandle关闭端口。
2)在CSerialPort类中,关闭串口在辅助线程事件处理时,设置了最高的优先级。在线
程函数CommThread0中实现。
67
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -