本文介绍了获取Windows 10中的串行端口列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 以下代码已经在许多Windows 10计算机上运行,​​但我刚刚发现它无法正常工作,因为这个特定的Windows 10副本的注册表没有SERIALCOMM文件夹。The following code has worked on a number of Windows 10 machines, but I have just found one where it does not work because the registry of this particular copy of windows 10 does not have a SERIALCOMM folder.系统COM端口必须列在某些​​地方,如果不在SERIALCOMM下,那么在哪里?The system COM ports must be listed some where so, if not under SERIALCOMM, then where?void CSerialPort::GetCOMPorts(CStringArray &strarrayCOMPorts, CWnd *pWnd){CRegKey regkey;DWORD dwI = 0, nBuffSize = BUFF_SIZE;char szKeyName[BUFF_SIZE], szKeyVal[BUFF_SIZE];LONG nCode = ERROR_SUCCESS;CString strKeyVal, strTemp, strResponse;UINT nCOMPort = 0;CSerialPort SerialPort;memset(szKeyName, 0, BUFF_SIZE);memset(szKeyVal, 0, BUFF_SIZE);if (regkey.Open(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", KEY_READ) == ERROR_SUCCESS){//LONG WINAPI RegEnumValue(_In_ HKEY hKey,//_In_ DWORD dwIndex,//_Out_ LPTSTR lpValueName,//_Inout_ LPDWORD lpcchValueName,//_Reserved_ LPDWORD lpReserved,//_Out_opt_ LPDWORD lpType,//_Out_opt_ LPBYTE lpData,//_Inout_opt_ LPDWORD lpcbData);do{nCode = RegEnumValue(regkey.m_hKey, dwI, szKeyName, &nBuffSize, NULL, NULL, NULL, NULL);if (nCode != ERROR_NO_MORE_ITEMS){nBuffSize = BUFF_SIZE;regkey.QueryStringValue(szKeyName, szKeyVal, &nBuffSize);nBuffSize = BUFF_SIZE;strKeyVal = szKeyVal;strTemp = strKeyVal;strTemp.Delete(0, 3);nCOMPort = atoi(strTemp);if ((nCOMPort >= 1) && (SerialPort.Open(strKeyVal)) && (SerialPort.isIrrigationController(strKeyVal))){SerialPort.Write("id#");if (SerialPort.Read(strResponse, 2000) > 0){strarrayCOMPorts.Add(strResponse + " (" + strKeyVal + ")");}}SerialPort.Close();dwI++;}}while (nCode != ERROR_NO_MORE_ITEMS);}elseAfxMessageBox("Cannot access the Windows registry...", MB_OK);}推荐答案 这篇关于获取Windows 10中的串行端口列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 13:38