ソースを参照

```
refactor(mcu): 移除异步任务创建并简化命令发送方法

- 将 DeviceControl.send_all_cmd 方法从异步改为同步方法
- 在 ProgramItem 中直接调用同步方法替代 asyncio.create_task
- 移除多余的事件循环任务创建代码
- 保持功能一致性的同时简化异步处理逻辑
```

rambo 2 週間 前
コミット
154d100dd9

+ 2 - 2
python/mcu/DeviceControl.py

@@ -403,8 +403,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.send_data_queue.append(data)
         self.lock.release()
 
-    async def send_all_cmd(self):
-        await asyncio.sleep(0.001)
+    def send_all_cmd(self):
+        # await asyncio.sleep(0.001)
         while True:
             if self.send_data_queue:
                 # self.sendSocketMessage(msg="正在发送命令", device_status=1)

+ 7 - 5
python/mcu/ProgramItem.py

@@ -174,7 +174,8 @@ class ProgramItem(BaseClass):
                 return True
             else:
                 self.mcu.to_get_mcu_base_info()
-                asyncio.create_task(self.mcu.send_all_cmd())
+                # asyncio.create_task(self.mcu.send_all_cmd())
+                self.mcu.send_all_cmd()
                 await asyncio.sleep(0.5)
                 self.mcu.get_basic_info_mcu()
                 # return True
@@ -230,9 +231,9 @@ class ProgramItem(BaseClass):
                     device_name="turntable_steering", value=self.turntable_angle
                 )
                 time.sleep(0.1)
-            loop = asyncio.get_event_loop()
-            # self.mcu.send_all_cmd()
-            loop.create_task(self.mcu.send_all_cmd())
+            # loop = asyncio.get_event_loop()
+            self.mcu.send_all_cmd()
+            # loop.create_task(self.mcu.send_all_cmd())
 
     async def do_run(self, *args):
         await asyncio.sleep(0.001)
@@ -283,7 +284,8 @@ class ProgramItem(BaseClass):
                 # time.sleep(0.1)
 
             # MCU运动是否有停止检查,设定超时时间
-            asyncio.create_task(self.mcu.send_all_cmd())
+            self.mcu.send_all_cmd()
+            # asyncio.create_task(self.mcu.send_all_cmd())
             if self.mode_type != "其他配置":
                 await asyncio.sleep(1.2)
                 print("二次检查")

+ 0 - 8
python/mcu/capture/smart_shooter_class.py

@@ -454,14 +454,6 @@ class SmartShooter(metaclass=SingletonType):
                 "msg_type": self.msg_type,
                 "device_status": 2,
             }
-            msg_send = "相机未连接或软件未打开"
-            message = {
-                "code": 1,
-                "msg": msg_send,
-                "data": None,
-                "msg_type": self.msg_type,
-                "device_status": -1,
-            }
             await self.websocket_manager.send_personal_message(message, self.websocket)
             return True, "拍照成功"
         except zmq.Again: