使用CSerialPort类时的一个有关问题
使用CSerialPort类时的一个问题
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. ),然后手动执行下同样的连接代码,就不报错了,有大神知道这是为什么吗?
------解决思路----------------------
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. ),然后手动执行下同样的连接代码,就不报错了,有大神知道这是为什么吗?
------解决思路----------------------