Prechádzať zdrojové kódy

fix: 优化串口无法打开问题
1. 优化了串口打开异常的界面提示

kindring 1 týždeň pred
rodič
commit
2ffb5ae34b

+ 1 - 0
bird_tool/Config.cs

@@ -15,6 +15,7 @@ namespace Bird_tool
         public int web_port = 8080;
         public string wifi_ssid { get; set; } = "hf_test";
         public string wifi_passwd { get; set; } = "12345678";
+        public string pir { get; set; } = "90";
     }
 
     public static class ConfigManager

+ 3 - 0
bird_tool/SerialManager.cs

@@ -9,8 +9,10 @@ namespace Bird_tool
     class SerialManager
     {
         public delegate void DisconnectHandler(bool isError);
+        public delegate void ConnectHandler();
 
         public event DisconnectHandler OnDisconnect;
+        public event ConnectHandler OnConnect;
 
         private SerialPort _uart = new SerialPort();
         private int MAX_BUFFER_SIZE = 4096; // 最大缓冲区大小
@@ -49,6 +51,7 @@ namespace Bird_tool
             {
                 _uart.Open();
                 System.Threading.Thread.Sleep(150);
+                OnConnect?.Invoke();
                 return true;
             }
             catch (Exception ex)

+ 7 - 5
bird_tool/TestEngine.cs

@@ -436,6 +436,12 @@ namespace Bird_tool
 
         private bool StartTestWithSteps(List<TestStepConfig> steps)
         {
+            if (!_serialManager.ReOpen())
+            {
+                OnLog?.Invoke("无法打开串口", LogLevel.error);
+                OnLogShow?.Invoke("串口打开失败");
+                return false;
+            }
             lock (_lock)
             {
                 if (steps == null || steps.Count == 0)
@@ -449,11 +455,7 @@ namespace Bird_tool
                     step.stepStatus = StepStatus.NotRun;
                     step.RetryCount = 0;
                 }
-                if (!_serialManager.ReOpen())
-                {
-                    OnLog?.Invoke("无法打开串口", LogLevel.error);
-                    OnLogShow?.Invoke("串口打开失败");
-                }
+                
                 _serialManager.OnLineReceived += HandleResponse;
                 EnqueueTask(async ct =>
                 {

+ 47 - 9
bird_tool/bird_tool.cs

@@ -301,6 +301,10 @@ namespace Bird_tool
                 // 判断是否在测试
                 StopTest(isError);
             };
+            _serialManager.OnConnect += () =>
+            {
+                _uart_ui_change(true);
+            };
         }
         private void load_app_config()
         {
@@ -842,25 +846,31 @@ namespace Bird_tool
             progressPanel.CurrentTest = "初始化测试环境";
             progressPanel.Message = "准备开始硬件测试...";
             progressPanel.startTest();
+            bool start_flag = false;
             if (string.IsNullOrEmpty(groupId))
             {
-                _testExecutor.StartTest();
+                start_flag = _testExecutor.StartTest();
             }
             else
             {
                 if (testType == TestType.StartFrom)
                 {
-                    _testExecutor.StartTestFromGroup(groupId);
+                    start_flag = _testExecutor.StartTestFromGroup(groupId);
                 }
                 else if (testType == TestType.TestSingle)
                 {
-                    _testExecutor.StartTestGroup(groupId);
+                    start_flag = _testExecutor.StartTestGroup(groupId);
                 }
                 else
                 {
-                    _testExecutor.StartTest();
+                    start_flag = _testExecutor.StartTest();
                 }
             }
+
+            if (!start_flag)
+            {
+                StopTest(false);
+            }
             
         }
         private void StopTest(bool isQuery = true)
@@ -886,6 +896,12 @@ namespace Bird_tool
             }
             else
             {
+                progressPanel.ShowTestResult(false, "测试已取消", LoadCancelledImage());
+
+                // 添加日志
+                logBuilder.AppendLine($"[{DateTime.Now}] 测试已取消");
+                _testExecutor.StopTestAsync();
+                progressPanel.Message = "停止异常中止";
                 Log($"[{DateTime.Now}] 测试中止");
             }
             
@@ -983,13 +999,35 @@ namespace Bird_tool
 
                 // 红外传感器测试
                 new TestStepConfig
+                {
+                    GroupId = "pir_test",
+                    ShowStep = false,
+                    Name = "配置变量",
+                    Tips = "设置变量",
+                    PrivateCammand = true,
+                    Action = ActionMode.SetVal,
+                    VariableNames = { "pir" },
+                    VariableValues = { appConfig.pir },
+                },
+                new TestStepConfig
+                {
+                    GroupId = "pir_test",
+                    Name = "配置红外",
+                    Tips = "配置红外灵敏度中",
+                    Command = "AT+SPIR={{pir}}\r\n",
+                    SuccessPattern = @"sensitivity to \d+ OK",
+                    Timeout = 3000,
+                    DelayAfter = 10,
+                    MaxRetries = 5,
+                },
+                new TestStepConfig
                 {
                     GroupId = "pir_test",
                     Name = "配置设备状态",
                     Tips = "等待任务自动执行",
                     Command = "AT+RBOT=0\r\n",
                     SuccessPattern = "OS start",
-                    Timeout = 10000,
+                    Timeout = 15000,
                     DelayBefore = 1000,
                     MaxRetries = 5,
                 },
@@ -1004,14 +1042,14 @@ namespace Bird_tool
                     DelayBefore = 1000,
                     MaxRetries = 5,
                 },
-
+                
                 new TestStepConfig
                 {
                     GroupId = "pir_test",
-                    Name = "红外触发1",
-                    Tips = "请将手移动至红外传感器上 第一次",
+                    Name = "等待设备休眠",
+                    Tips = "等待设备进入休眠状态",
                     Command = "\r\n",
-                    SuccessPattern = "SOC: <=OK cmd:17",
+                    SuccessPattern = "CAM: Close",
                     Timeout = 30000,
                     DelayAfter = 100,
                     MaxRetries = 3,