佚名通过本文主要向大家介绍了cserialport使用,cserialport类使用,cserialport,cserialport类,cserialport类下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 使用CSerialPort类时的一个问题
描述:
m_hComm = CreateFile("\\\\.\\"+strPort, // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE, // read/write types
0, // comm devices must be opened with exclusive access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // Async I/O
0); // template must be 0 for comm devices
在单文档视图的OnInitUpdate函数中是这样写的:
void CMainView::OnInitialUpdate()
{
CView::OnInitialUpdate();
g_pMainView = this;
GetPrivateProfileString("DeviceInfo","com","com1",g_strPort.GetBuffer(MAX_PATH),MAX_PATH,".\\system.ini");
if(g_port.InitPort(this,g_strPort)==TRUE)
{
g_port.StartMonitoring();
}
else
{
AfxMessageBox("连接异常,请检查连接。");
}
}
问题是,每次启动程序时总是报错,错误码:123,(ERROR_INVALID_NAME 123 The filename, directory name, or volume label syntax is incorrect. ),然后手动执行下同样的连接代码,就不报错了,有大神知道这是为什么吗?
描述:
本帖最后由 zh17286540 于 2015-01-16 10:05:08 编辑
COM通信
CSerialPort中的连接代码,为实现可以连接大于10的串口改成了:m_hComm = CreateFile("\\\\.\\"+strPort, // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE, // read/write types
0, // comm devices must be opened with exclusive access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // Async I/O
0); // template must be 0 for comm devices
在单文档视图的OnInitUpdate函数中是这样写的:
void CMainView::OnInitialUpdate()
{
CView::OnInitialUpdate();
g_pMainView = this;
GetPrivateProfileString("DeviceInfo","com","com1",g_strPort.GetBuffer(MAX_PATH),MAX_PATH,".\\system.ini");
if(g_port.InitPort(this,g_strPort)==TRUE)
{
g_port.StartMonitoring();
}
else
{
AfxMessageBox("连接异常,请检查连接。");
}
}
问题是,每次启动程序时总是报错,错误码:123,(ERROR_INVALID_NAME 123 The filename, directory name, or volume label syntax is incorrect. ),然后手动执行下同样的连接代码,就不报错了,有大神知道这是为什么吗?