Explorar o código

【软件版本】
V
【模块名称】
查找测试精灵时,需要快速响应读写,所以超时值要设置更小;
【问题原因】

【修改描述】

【测试结果】

sat23 %!s(int64=3) %!d(string=hai) anos
pai
achega
b6e5ff0ed4

+ 62 - 0
TestWizardTool/TestWizardTool/TestWizardToolDlg.cpp

@@ -137,6 +137,7 @@ CTestWizardToolDlg::CTestWizardToolDlg(CWnd* pParent /*=NULL*/)
     m_nComboHeight = 20;
     m_nDefaultWidth = 360;
     m_nDefaultHeight = 600;
+    m_bFindTestWizardPort = false;
 }
 
 void CTestWizardToolDlg::DoDataExchange(CDataExchange* pDX)
@@ -312,6 +313,10 @@ void CTestWizardToolDlg::InitSerialCombobox()
     for (std::vector<std::string>::iterator it = m_vtPorts.begin(); it != m_vtPorts.end(); it++) 
     {
         m_cbCOM.AddString(it->c_str());
+        if ( !m_bFindTestWizardPort )
+        {
+            m_bFindTestWizardPort = IsTestWizardPort(it->c_str());
+        }
     }
 }
 
@@ -748,6 +753,7 @@ void CTestWizardToolDlg::OnSignalBtnClick(UINT uId) // 
         KeyInfo *pKey = m_map_key.find(id)->second;
 
         if ( m_Serial.IsOpen() ){
+            m_Serial.SetTimeouts();
             // 封装发送包;
             byte szSendData[MAX_PATH] = {0};
             _stprintf_s((TCHAR*)szSendData, MAX_PATH, _T("*INPUT %s %s\r"), pKey->strType.c_str(), pKey->strValue.c_str());
@@ -940,4 +946,60 @@ void CTestWizardToolDlg::AutoSetDroppedWidth(CComboBox* pCombobox)
     // Set the horizontal extent so every character of all strings can
     // be scrolled to.
     pCombobox->SetHorizontalExtent(dx);
+}
+
+bool CTestWizardToolDlg::IsTestWizardPort(CString strCOMPort)
+{
+    CString strText = _T("");
+    GetDlgItemText(BTN_OPEN_COM, strText);
+    if ( strText == _T("Close") )
+    {// 串口已打开;
+        return false;
+    }
+
+    /* 
+       发送:*about 
+       返回:
+            Product name:      Test Wizard
+            Firmware version:  v3.6.210811
+            SN:                30FF6B064243393036140457
+            Active state:      Activated
+
+            Developer:         sun shengpeng
+            Email:             sunsp@tcl.com
+    */
+    m_Serial.SetIOMode();
+    if ( m_Serial.Open(atol(strCOMPort.Mid(3).GetString()), 115200) )
+    {
+        // 快速响应读写,不需要设置过长的超时;
+        m_Serial.SetTimeouts(0,1,20,1,150);
+        // 封装发送包;
+        byte szSendData[MAX_PATH] = _T("*about\r");
+        if ( m_Serial.WriteSync(szSendData, _tcslen((TCHAR*)szSendData)) )
+        {
+            memset(szSendData, 0, MAX_PATH);
+            m_Serial.ReadSync(szSendData, MAX_PATH);
+            if ( _tcsstr((TCHAR*)szSendData, _T("Product name:      Test Wizard\r")) )
+            {
+                // 设置当前串口为选中状态;
+                m_cbCOM.SelectString(0, strCOMPort);
+                Global::g_Config.twPort = strCOMPort;
+                WritePrivateProfileString("TestWizard", "Com", strCOMPort.GetString(), Global::g_szConfig);
+                // SetDlgItemText(BTN_OPEN_COM, _T("Close"));
+                // m_cbCOM.EnableWindow(FALSE);
+                // 关闭后,重新打开在设置超时值;
+                m_Serial.Close();
+                return true;
+            }
+            TRACE("发送单信号成功\n");
+        }
+        else
+        {
+            TRACE("发送单信号失败\n");
+        }
+
+        m_Serial.Close();
+    }
+
+    return false;
 }

+ 4 - 0
TestWizardTool/TestWizardTool/TestWizardToolDlg.h

@@ -88,6 +88,10 @@ public:
     std::vector<BTNInfo*> m_vtBTNInfo;
     CBaseSerial m_Serial;
     CRect m_rcGroup;
+    // 是否找到测试精灵串口;
+    bool m_bFindTestWizardPort;
+    // 查找测试精灵串口;
+    bool IsTestWizardPort(CString strCOMPort);
 
     void AdjustLayout();
     void InitSerialCombobox();