文件名称:串口类CSerial
文件大小:10KB
文件格式:RAR
更新时间:2022-04-22 05:28:16
串口 c++
CSerial::EPort CSerial::CheckPort (LPCTSTR lpszDevice) { // Try to open the device HANDLE hFile = ::CreateFile(lpszDevice, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); // Check if we could open the device if (hFile == INVALID_HANDLE_VALUE) { // Display error switch (::GetLastError()) { case ERROR_FILE_NOT_FOUND: // The specified COM-port does not exist return EPortNotAvailable; case ERROR_ACCESS_DENIED: // The specified COM-port is in use return EPortInUse; default: // Something else is wrong return EPortUnknownError; } } // Close handle ::CloseHandle(hFile); // Port is available return EPortAvailable; }
【文件预览】:
Serial.h
Serial.cpp