Преглед на файлове

对焦失败拍照问题

rambo преди 3 месеца
родител
ревизия
d588924348
променени са 1 файла, в които са добавени 23 реда и са изтрити 5 реда
  1. 23 5
      python/mcu/capture/smart_shooter_class.py

+ 23 - 5
python/mcu/capture/smart_shooter_class.py

@@ -5,7 +5,7 @@ import zmq
 import asyncio
 from PIL import Image
 from io import BytesIO
-import base64,threading
+import base64, threading
 import zmq, sys, time
 from utils.SingletonType import SingletonType
 import settings
@@ -13,6 +13,8 @@ import logging
 from utils.common import message_queue
 
 logger = logging.getLogger(__name__)
+
+
 # 定义为单例模式,避免被重复实例化
 class SmartShooter(metaclass=SingletonType):
     SET_REQ = "tcp://127.0.0.1:54544"
@@ -61,8 +63,9 @@ class SmartShooter(metaclass=SingletonType):
         listen_socket.setsockopt(zmq.LINGER, 0)  # 设置为 0 表示不等待未完成的操作
         listen_socket.connect(self.LISTEN_REQ)
         return listen_socket, context
+
     async def GetCameraProperty(self):
-        '''获取相机属性'''
+        """获取相机属性"""
         await asyncio.sleep(0.01)
         """
             实时获取相机信息,是否连接、软件是否被打开
@@ -87,8 +90,8 @@ class SmartShooter(metaclass=SingletonType):
                 return False, "相机未连接"
             # 链接的相机
             CameraStatus = False
-            CameraIndex =-1
-            for cam_idx,item in enumerate(cameraInfo):
+            CameraIndex = -1
+            for cam_idx, item in enumerate(cameraInfo):
                 CameraStatus = item.get("CameraStatus") in ["Ready", "Busy"]
                 if CameraStatus == True:
                     CameraIndex = cam_idx
@@ -110,6 +113,7 @@ class SmartShooter(metaclass=SingletonType):
             context.term()
             msg_send = "相机未连接或软件未打开"
             return False, msg_send
+
     async def GetCameraInfo(self, is_send=True, msg_type=""):
         await asyncio.sleep(0.01)
         self.msg_type = msg_type
@@ -373,6 +377,17 @@ class SmartShooter(metaclass=SingletonType):
             print("json_msg", json_msg)
             msg_result = json_msg.get("msg_result")
             if not msg_result:
+                msg_send = "对焦失败"
+                message = {
+                    "code": 1,
+                    "msg": msg_send,
+                    "data": None,
+                    "msg_type": "smart_shooter_photo_take",
+                    "device_status": -1,
+                }
+                await self.websocket_manager.send_personal_message(
+                    message, self.websocket
+                )
                 return False, "对焦失败"
             return True, "对焦成功"
         except zmq.Again:
@@ -382,7 +397,9 @@ class SmartShooter(metaclass=SingletonType):
             context.term()
             return False, "相机未连接或软件未打开"
 
-    async def CameraShooter(self, msg_type="", goods_art_no="", id=0, is_af=False,delay=1.5):
+    async def CameraShooter(
+        self, msg_type="", goods_art_no="", id=0, is_af=False, delay=1.5
+    ):
         # 这里延迟一秒钟 等待前置命令完成
         await asyncio.sleep(delay)
         # 对焦混用
@@ -467,6 +484,7 @@ class SmartShooter(metaclass=SingletonType):
             }
             await self.websocket_manager.send_personal_message(message, self.websocket)
             return False, msg_send
+
     async def asyncMessageListen(self):
         if self.websocket.client_state.name != "CONNECTED":
             print("WebSocket连接已断开,停止发送消息")