天天看点

C++打开虚拟串口失败

转自:https://blog.csdn.net/baidu_37503452/article/details/87004621

// get a handle to the port

m_hComm = CreateFile(_T("\\.\COM11"), // 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

if (m_hComm == INVALID_HANDLE_VALUE)

{

// port not found

delete [] szPort;

delete [] szBaud;

return FALSE;

}

com10以上,CreateFile的第一个参数要变成\\.\ + COM11

C++打开虚拟串口失败

继续阅读