Эх сурвалжийг харах

【软件版本】
V
【模块名称】
远程场测工具
【问题原因】
拨插串口时,USB模块未能自动识别。
【修改描述】

【测试结果】

sat23 3 жил өмнө
parent
commit
8549b3c8ee

+ 72 - 32
TestWizardTool/TestWizardTool/TestWizardToolDlg.cpp

@@ -277,40 +277,80 @@ BOOL CTestWizardToolDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
     DEV_BROADCAST_PORT *pbdp = (DEV_BROADCAST_PORT*)dwData;
     if ( pbdp && _tcsstr(pbdp->dbcp_name, _T("COM")) )
     {
-        // 查找是否有添加过该项;
-        int nIndex = m_cbCOMTW.FindString(0, pbdp->dbcp_name);
-        // 删除和新增前,先获取当前选中的项;
-        CString strCurCOM = _T("");
-        int nCurIndex = m_cbCOMTW.GetCurSel();
-        if ( nCurIndex != CB_ERR )
-            m_cbCOMTW.GetLBText(nCurIndex, strCurCOM);
-
-        if ( nEventType == DBT_DEVICEREMOVECOMPLETE )
-        {// 串口拨掉;
-            TRACE(_T("串口拨掉\n"));
-            if ( nIndex != CB_ERR )
-            {                
-                m_cbCOMTW.DeleteString(nIndex);
-                // 删除后, 由于索引变化了,要重新设置选中项;
-                if ( nCurIndex != CB_ERR )
-                    m_cbCOMTW.SelectString(0, strCurCOM);
+        {
+            // 查找是否有添加过该项;
+            int nIndex = m_cbCOMTW.FindString(0, pbdp->dbcp_name);
+            // 删除和新增前,先获取当前选中的项;
+            CString strCurCOM = _T("");
+            int nCurIndex = m_cbCOMTW.GetCurSel();
+            if ( nCurIndex != CB_ERR )
+                m_cbCOMTW.GetLBText(nCurIndex, strCurCOM);
+
+            if ( nEventType == DBT_DEVICEREMOVECOMPLETE )
+            {// 串口拨掉;
+                TRACE(_T("串口拨掉\n"));
+                if ( nIndex != CB_ERR )
+                {                
+                    m_cbCOMTW.DeleteString(nIndex);
+                    // 删除后, 由于索引变化了,要重新设置选中项;
+                    if ( nCurIndex != CB_ERR )
+                        m_cbCOMTW.SelectString(0, strCurCOM);
+                }
+            }
+            else if ( nEventType == DBT_DEVICEARRIVAL )
+            {// 串口插入;
+                TRACE(_T("串口插入\n"));
+                if ( nIndex == CB_ERR )
+                {
+                    m_cbCOMTW.AddString(pbdp->dbcp_name);
+                    // 新增后,由于索引变化了,要重新设置选中项;
+                    if ( nCurIndex != CB_ERR )
+                        m_cbCOMTW.SelectString(0, strCurCOM);
+                    else
+                    {
+                        IsTestWizardPort(pbdp->dbcp_name);
+                    }
+
+                }
             }
         }
-        else if ( nEventType == DBT_DEVICEARRIVAL )
-        {// 串口插入;
-           TRACE(_T("串口插入\n"));
-           if ( nIndex == CB_ERR )
-           {
-               m_cbCOMTW.AddString(pbdp->dbcp_name);
-               // 新增后,由于索引变化了,要重新设置选中项;
-               if ( nCurIndex != CB_ERR )
-                   m_cbCOMTW.SelectString(0, strCurCOM);
-               else
-               {
-                    IsTestWizardPort(pbdp->dbcp_name);
-               }
-               
-           }
+
+        {
+            // 查找是否有添加过该项;
+            int nIndex = m_cbUSBPort.FindString(0, pbdp->dbcp_name);
+            // 删除和新增前,先获取当前选中的项;
+            CString strCurCOM = _T("");
+            int nCurIndex = m_cbUSBPort.GetCurSel();
+            if ( nCurIndex != CB_ERR )
+                m_cbUSBPort.GetLBText(nCurIndex, strCurCOM);
+
+            if ( nEventType == DBT_DEVICEREMOVECOMPLETE )
+            {// 串口拨掉;
+                TRACE(_T("串口拨掉\n"));
+                if ( nIndex != CB_ERR )
+                {                
+                    m_cbUSBPort.DeleteString(nIndex);
+                    // 删除后, 由于索引变化了,要重新设置选中项;
+                    if ( nCurIndex != CB_ERR )
+                        m_cbUSBPort.SelectString(0, strCurCOM);
+                }
+            }
+            else if ( nEventType == DBT_DEVICEARRIVAL )
+            {// 串口插入;
+                TRACE(_T("串口插入\n"));
+                if ( nIndex == CB_ERR )
+                {
+                    m_cbUSBPort.AddString(pbdp->dbcp_name);
+                    // 新增后,由于索引变化了,要重新设置选中项;
+                    if ( nCurIndex != CB_ERR )
+                        m_cbUSBPort.SelectString(0, strCurCOM);
+                    else
+                    {
+                        IsUSBSwitchPort(pbdp->dbcp_name);
+                    }
+
+                }
+            }
         }
     }