Browse Source

Merge remote-tracking branch 'origin/master'

panqiuyao 4 months ago
parent
commit
45c9183372

+ 6 - 10
python/api.py

@@ -150,18 +150,16 @@ def fromExcelHandler(params: HandlerDetail):
                 "\\", "/"
             )
             check_path(image_dir)
-            for itemImg in images:
+            for idx, itemImg in enumerate(images):
                 if itemImg.image_path == "" or itemImg.image_path == None:
                     raise UnicornException(
                         f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
                     )
-                new_file_name = (
-                    str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
-                )
+                new_file_name = str(itemImg.goods_art_no) + "_" + str(idx) + ".jpg"
                 if not os.path.exists(
                     image_dir + "/" + os.path.basename(new_file_name)
                 ):
-                    shutil.copy(itemImg.image_path, image_dir + "/" + new_file_name)
+                    shutil.copy(itemImg.image_path, image_dir + new_file_name)
             dealImage = DealImage(image_dir)
             resFlag, path = dealImage.dealMoveImage(
                 image_dir=image_dir,
@@ -321,18 +319,16 @@ async def handle_detail(request: Request, params: HandlerDetail):
         if move_folder_array.get(goods_art_no) == None:
             image_dir = "{}/data/".format(os.getcwd()).replace("\\", "/")
             check_path(image_dir)
-            for itemImg in images:
+            for idx, itemImg in enumerate(images):
                 if itemImg.image_path == "" or itemImg.image_path == None:
                     raise UnicornException(
                         f"货号【{goods_art_no}】存在没有拍摄完成的图片,请重拍或删除后重试"
                     )
-                new_file_name = (
-                    str(itemImg.goods_art_no) + "_" + str(itemImg.id) + ".jpg"
-                )
+                new_file_name = str(itemImg.goods_art_no) + "_" + str(idx) + ".jpg"
                 if not os.path.exists(
                     image_dir + "/" + os.path.basename(new_file_name)
                 ):
-                    shutil.copy(itemImg.image_path, image_dir + "/" + new_file_name)
+                    shutil.copy(itemImg.image_path, image_dir + new_file_name)
             dealImage = DealImage(image_dir)
             resFlag, path = dealImage.dealMoveImage(
                 image_dir=image_dir, callback_func=None, goods_art_no=goods_art_no

+ 78 - 78
python/databases.py

@@ -8,6 +8,7 @@ from sqlalchemy import and_, desc, asc
 from utils.utils_func import check_path
 from sqlalchemy.dialects import sqlite
 from model import DeviceConfig, PhotoRecord, SysConfigs, DeviceConfigTabs
+
 check_path("C:/Zhihuiyin")
 # 创建SQLite数据库引擎
 sqlite_file_name = "C:/Zhihuiyin/database.db"
@@ -15,6 +16,7 @@ sqlite_url = f"sqlite:///{sqlite_file_name}"
 engine = create_engine(
     sqlite_url,
     echo=False,
+    connect_args={"check_same_thread": False},  # 允许多线程访问
     pool_size=10,
     max_overflow=20,
     pool_timeout=30,
@@ -36,53 +38,6 @@ def __get_session():
             session.close()
 
 
-def batch_insert_device_configs(session: Session, action_tabs: list, data_list: list):
-    """批量插入数据到设备配置表"""
-    for idx, tab in enumerate(action_tabs):
-        crud = CRUD(DeviceConfigTabs)
-        device_tab = DeviceConfigTabs(
-            mode_type=tab.get("mode_type"),
-            mode_name=tab.get("mode_name"),
-        )
-        create_obj = crud.create(session, obj_in=device_tab)
-        for data in data_list:
-            data["tab_id"] = create_obj.id
-            data["is_system"] = False
-            if idx  in [0, 6]:
-                data["is_system"] = True
-            device_config = DeviceConfig(**data)
-            session.add(device_config)
-    session.commit()
-    session.close()
-
-
-def batch_insert_sys_configs(session: Session, data_list: list):
-    """批量插入数据到设备配置表"""
-    for data in data_list:
-        config = SysConfigs(**data)
-        session.add(config)
-    session.commit()
-    session.close()
-
-
-def insert_photo_records(
-    image_deal_mode: int, goods_art_no: str, image_index: int, action_id: int
-):
-    session = SqlQuery()
-    """批量插入数据到照片记录"""
-    data = {
-        "image_deal_mode": image_deal_mode,
-        "goods_art_no": goods_art_no,
-        "image_index": image_index,
-        "action_id": action_id,
-    }
-    device_config = PhotoRecord(**data)
-    session.add(device_config)
-    session.commit()
-    session.close()
-    return True
-
-
 # 创建一个通用的 CRUD 类
 class CRUD:
     def __init__(self, model):
@@ -94,7 +49,6 @@ class CRUD:
         session.add(db_obj)
         session.commit()
         session.refresh(db_obj)
-        session.close()
         return db_obj
 
     def read(
@@ -120,7 +74,6 @@ class CRUD:
             else:
                 query = query.order_by(desc(getattr(self.model, order_by)))
         data = session.exec(query).first()
-        session.close()
         return data
 
     def read_all(
@@ -161,43 +114,16 @@ class CRUD:
             else:
                 query = query.order_by(desc(getattr(self.model, order_by)))
         data = session.exec(query).all()
-        session.close()
         return data
 
     def update(self, session: Session, obj_id: int, **kwargs):
         db_obj = session.get(self.model, obj_id)
         for key, value in kwargs.items():
-            # if value == None or value == "":
-            #     continue
             setattr(db_obj, key, value)
         session.commit()
         session.refresh(db_obj)
-        session.close()
         return db_obj
 
-    def updateConditions(
-        self, session: Session, conditions: Optional[Dict] = None, **kwargs
-    ):
-        query = select(self.model)
-        if conditions:
-            query = query.where(
-                and_(
-                    *(
-                        getattr(self.model, key) == value
-                        for key, value in conditions.items()
-                    )
-                )
-            )
-        data = session.exec(query).first()
-        for key, value in kwargs.items():
-            if value == None or value == "":
-                continue
-            setattr(data, key, value)
-        session.commit()
-        session.refresh(data)
-        session.close()
-        return data
-
     def deleteConditions(
         self,
         session: Session,
@@ -218,14 +144,88 @@ class CRUD:
         for obj in objects_to_delete:
             session.delete(obj)
         session.commit()
-        session.close()
+        # session.refresh()
         return True
 
     def delete(self, session: Session, obj_id: int):
         db_obj = session.get(self.model, obj_id)
         session.delete(db_obj)
         session.commit()
-        session.close()
+        # session.refresh()
+
+    # 恢复 updateConditions 方法
+    def updateConditions(self, session: Session, conditions: Dict, **kwargs):
+        """
+        根据条件更新记录
+        :param session: 数据库会话
+        :param conditions: 更新条件字典
+        :param kwargs: 需要更新的字段和值
+        :return: 更新后的对象
+        """
+        query = select(self.model).where(
+            and_(
+                *(
+                    getattr(self.model, key) == value
+                    for key, value in conditions.items()
+                )
+            )
+        )
+        result = session.exec(query).first()
+        if result:
+            for key, value in kwargs.items():
+                setattr(result, key, value)
+            session.commit()  # 提交事务以保存更改
+            return result
+        return None
+
+
+# 批量插入数据到设备配置表
+def batch_insert_device_configs(session: Session, action_tabs: list, data_list: list):
+    """批量插入数据到设备配置表"""
+    for idx, tab in enumerate(action_tabs):
+        crud = CRUD(DeviceConfigTabs)
+        device_tab = DeviceConfigTabs(
+            mode_type=tab.get("mode_type"),
+            mode_name=tab.get("mode_name"),
+        )
+        create_obj = crud.create(session, obj_in=device_tab)
+        for data in data_list:
+            data["tab_id"] = create_obj.id
+            data["is_system"] = False
+            if idx in [0, 6]:
+                data["is_system"] = True
+            device_config = DeviceConfig(**data)
+            session.add(device_config)
+    session.commit()  # 合并事务提交
+
+
+# 批量插入系统配置
+def batch_insert_sys_configs(session: Session, data_list: list):
+    """批量插入数据到设备配置表"""
+    for data in data_list:
+        config = SysConfigs(**data)
+        session.add(config)
+    session.commit()  # 合并事务提交
+
+
+# 插入照片记录
+async def insert_photo_records(
+    image_deal_mode: int, goods_art_no: str, image_index: int, action_id: int
+):
+    with SqlQuery() as session:  # 使用上下文管理器复用会话
+        """批量插入数据到照片记录"""
+        data = {
+            "image_deal_mode": image_deal_mode,
+            "goods_art_no": goods_art_no,
+            "image_index": image_index,
+            "action_id": action_id,
+        }
+        device_config = PhotoRecord(**data)
+        session.add(device_config)
+        session.commit()
+        session.refresh(device_config)
+        record_id = device_config.id
+        return True, record_id
 
 
 def SqlQuery():

+ 172 - 48
python/mcu/DeviceControl.py

@@ -15,6 +15,7 @@ from databases import insert_photo_records
 from .McuDeviationSet import McuDeviationSet
 from .OtherSet import OtherSet
 from .DebugUart import DebugUart
+from .LineControl import LineControl
 import copy
 
 # mcu命令
@@ -27,6 +28,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.mcu_deviation_set = McuDeviationSet(self)
         self.mcu_other_set = OtherSet(self)
         self.debug_uart = DebugUart(self)
+        self.line_control = LineControl(websocket_manager)
         self.m_t = 1
         # 0未开始  1进行中 2已结束  99异常
         self.action_state = 2
@@ -36,7 +38,6 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.state_turntable_steering = 3
         self.state_overturn_steering = 3
         self.state_move_turntable_steering = 3
-
         self.last_from_mcu_move_respond_data = None
         self.camera_motor_speed = 0
         self.camera_motor_value = 0
@@ -52,6 +53,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.is_runn_action = False
         self.is_stop_action = False
         self.connect_state = False
+        self.is_init_while = False
         self.device_name_dict = {
             "camera_steering": 0,
             "camera_high_motor": 1,
@@ -194,10 +196,50 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         # self.sign_data.emit(
         #     {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
         # )
+        print("串口未连接,请检查")
+        self.sendSocketMessage(code=1, msg="串口未连接,请检查",device_status=-1)
         message = {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
         self.sendSocketMessage(code=1, msg="MCU 连接失败", data=message,device_status=-1)
         self.close_connect()
 
+    async def initControlLine(self,serial_handle):
+        '''实例化有线控制设备'''
+        self.line_control.connect_state = True
+        self.line_control.serial_ins = serial_handle
+        await self.line_control.run()
+        # if self.init_state == True:
+        #     print("已经初始化过,请勿重复初始化")
+        #     self.sendSocketMessage(msg="设备初始化完成", device_status=2)
+        #     return False
+        # self.serial_ins.clearn_flush()
+        # self.to_init_device_origin_point(device_name="mcu", is_force=is_force)
+        # print("MCU 开始循环~")
+        # while 1:
+        #     await asyncio.sleep(0.01)
+        #     if not self.serial_ins or not self.connect_state:
+        #         break
+        #     try:
+        #         # print("mcu   send_cmd")
+        #         self.send_cmd()
+        #         # time.sleep(0.01)
+        #         self.get_basic_info_mcu()
+        #         # self.close_other_window()
+        #     except BaseException as e:
+        #         print("121231298908", e)
+        #         break
+
+        # self.is_running = False
+        # self.connect_state = False
+        # print("MCU 循环退出~")
+        # # self.sign_data.emit(
+        # #     {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
+        # # )
+        # message = {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
+        # self.sendSocketMessage(
+        #     code=1, msg="MCU 连接失败", data=message, device_status=-1
+        # )
+        # self.close_connect()
+
     def stop_mcu(self):
         buf = [self.command["stop_mcu"]]
         buf.extend(self.encapsulation_data(data=1, len_data=1))
@@ -261,12 +303,16 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
 
     async def getDeviationInfo(self):
         await asyncio.sleep(0.01)
-        # 发送获取偏移量
-        data = [self.command["get_deviation"], 1]
-        self.add_send_data_queue(data)
-        # if self.serial_ins:
-        #     self.serial_ins.write_cmd(data)
-        print("发送获取偏移量")
+        try:
+            # 发送获取偏移量
+            data = [self.command["get_deviation"], 1]
+            self.add_send_data_queue(data)
+            # if self.serial_ins:
+            #     self.serial_ins.write_cmd(data)
+            print("发送获取偏移量")
+        except Exception as e:
+            print(e)
+            print("getDeviationInfo", "暂未获取到self.command")
 
     def set_deviation(self, device_name, _type=0, deviation=0):
         # turntable----0 angle_ratio   1 turntable_steering_deviation
@@ -458,7 +504,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.connect_state = False
             return False
         if not receive_data:
-            return
+            return False
         # print("receive_data", receive_data)
         # 数据 结构 command,按命令解析
         # command 0(9) 相机高度1-2  相机角度3-4  转盘角度5-6 灯光状态7  激光指示器状态8,运行状态9
@@ -847,7 +893,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         }
         self.sendSocketMessage(1, "串口被移除", data)
 
-    def add_port_by_linkage(self, port_name):
+    async def add_port_by_linkage(self, port_name):
         # port_value :串口基础信息
         # todo 根据prot_value 信息自动进行连接
         print("add", port_name)
@@ -860,7 +906,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.sendSocketMessage(
             msg="开始识别接口:{}".format(port_name), data=message_data, device_status=1
         )
-        time.sleep(1)
+        await asyncio.sleep(1)
         """
         步骤:
         1、进行临时连接,并发送命令,成功后,自动连接对应设备
@@ -881,9 +927,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 device_status=-1,
             )
             print("串口:{} 被占用".format(port_name))
-            return
+            return False
 
-        time.sleep(2)
+        await asyncio.sleep(2)
         print("开始发送命令")
         data = [90, 1]
         try:
@@ -896,7 +942,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 data=None,
             )
             serial_handle.close()
-            return
+            return False
         print("尝试写入数据")
 
         buf = bytearray(b"")
@@ -909,11 +955,12 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         except serial.SerialTimeoutException:
             print("写入数据错误")
             serial_handle.close()
-            return
+            return False
 
-        time.sleep(0.3)
-        print("尝试接收命令")
+        await asyncio.sleep(0.3)
+        # print("尝试接收命令")
         receive_data = self.read_cmd(serial_handle)
+        print("尝试接收命令", receive_data)
         device_id = 0
 
         if receive_data:
@@ -924,10 +971,11 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
 
         print("关闭串口:{}".format(port_name))
         serial_handle.close()
-
+        loop = asyncio.get_event_loop()
+        print("device_id============>>>", device_id)
         if device_id > 0:
             if device_id == 1:
-                self.to_connect_com(port_name)
+                await self.to_connect_com(port_name)
                 message_data = {
                     "_type": "show_info",
                     "plugins_mode": "auto_select_com",
@@ -937,32 +985,66 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     msg="MCU开始连接", data=message_data, device_status=1
                 )
                 self.connected_ports_dict[port_name] = "MCU"
-            message_data = {
-                "_type": "select_port_name",
-                "plugins_mode": "auto_select_com",
-                "data": {
-                    "device_name": "mcu" if device_id == 1 else "remote_control",
-                    "port_name": port_name,
-                },
-            }
-            self.sendSocketMessage(
-                msg="MCU连接成功", data=message_data, device_status=2
-            )
-            time.sleep(2)
-            loop = asyncio.get_event_loop()
-            loop.create_task(self.initDevice(), name="init_mcu")
+                message_data = {
+                    "_type": "select_port_name",
+                    "plugins_mode": "auto_select_com",
+                    "data": {
+                        "device_name": "mcu" if device_id == 1 else "remote_control",
+                        "port_name": port_name,
+                    },
+                }
+                self.sendSocketMessage(
+                    msg="MCU连接成功", data=message_data, device_status=2
+                )
+                await asyncio.sleep(2)
+                # await self.initDevice()
+                loop.create_task(
+                    self.initDevice(port_name),
+                    name="initDevice",
+                )
+            elif device_id == 2:
+                # 有线接收器
+                print("device_id", device_id)
+                loop.create_task(
+                    self.line_control.to_connect_com(port_name),
+                    name="line_control_to_connect_com",
+                )
+                # message_data = {
+                #     "_type": "show_info",
+                #     "plugins_mode": "auto_select_com",
+                #     "data": {"text": "有线控制器开始连接"},
+                # }
+                # self.sendSocketMessage(
+                #     msg="有线控制器开始连接", data=message_data, device_status=1
+                # )
+                # self.connected_ports_dict[port_name] = "MCU"
+                # message_data = {
+                #     "_type": "select_port_name",
+                #     "plugins_mode": "auto_select_com",
+                #     "data": {
+                #         "device_name": "mcu" if device_id == 1 else "remote_control",
+                #         "port_name": port_name,
+                #     },
+                # }
+                # self.sendSocketMessage(
+                #     msg="有线控制器开始连接", data=message_data, device_status=2
+                # )
+                # await asyncio.sleep(2)
+                # await self.initControlLine(serial_handle)
             # async def getBaseInfo():
             #     while True:
             #         await asyncio.sleep(1)
             #         # 异步循环获取设备信息
             #         self.to_get_mcu_base_info()
             # asyncio.gather(getBaseInfo())
+            return True
         else:
             print("串口无法识别")
             self.sendSocketMessage(
                 code=1,
                 msg="串口无法识别,请重新插拔拍照机USB", data=message_data, device_status=-1
             )
+            return False
             # 走其他途径处理
 
         # 检查当前MCU链接是否正常
@@ -971,11 +1053,11 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         # 连接不上,记录为其他列表
     def clearMyInstance(self):
         SingletonType.clear_instance()
-    def to_connect_com(self, port_name):
+    async def to_connect_com(self, port_name):
         # 关闭串口
         print("to_connect_com", port_name)
         self.close_connect()
-        time.sleep(0.3)
+        await asyncio.sleep(0.3)
         self.connect_state = False
         try:
             self.serial_ins = SerialIns(port_name=port_name, baud=115200, timeout=0.1)
@@ -990,7 +1072,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 )
                 self.serial_ins = None
                 self.connect_state = False
-                return False
+                return False,None
 
         except:
             message_data = {
@@ -1003,7 +1085,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             )
             self.serial_ins = None
             self.connect_state = False
-            return False
+            return False, None
 
         message_data = {
             "_type": "show_info",
@@ -1020,7 +1102,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.serial_ins.write_cmd(data)
 
         # 延迟接收数据
-        time.sleep(0.3)
+        await asyncio.sleep(0.3)
         receive_data = self.serial_ins.read_cmd(out_time=1)
         if receive_data:
             print(
@@ -1068,8 +1150,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.is_running = False
             self.connect_state = False
             self.connected_ports_dict = {}  # 已连接的ports
-            self.p_list = []
-            self.temp_ports_dict = {}
+            # self.p_list = []
+            # self.temp_ports_dict = {}
             self.init_state = False
             print("关闭MCU")
 
@@ -1144,6 +1226,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
 
         cmd = 1
         device_id = self.device_name_dict[device_name]
+        # if device_id != 1:
+        #     print("F非MCU设备,禁止处理")
+        #     return
         print("正在执行",device_name)
         match device_name:
             case "camera_high_motor":
@@ -1389,17 +1474,19 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             for idx, item in enumerate(config_list):
                 is_take_picture = item["take_picture"]
                 action_id = item["id"]
+                record_id = -1
                 if is_take_picture:
                     action_names.append(item["action_name"])
                     image_counts += 1
                     # 批量插入
                     image_deal_mode = 0 if action_info == "执行左脚程序" else 1
-                    insert_photo_records(
+                    state,record_id = insert_photo_records(
                         image_deal_mode=image_deal_mode,
                         goods_art_no=goods_art_no,
                         image_index=idx,
                         action_id=action_id,
                     )
+                config_list[idx]["record_id"] = record_id
             total_len = len(config_list)
             self.action_state = 1
             self.msg_type = "image_process"
@@ -1422,11 +1509,14 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             for index, action in enumerate(config_list):
                 await asyncio.sleep(0.1)
                 if self.is_stop_action == True:
-                    self.is_stop_action = False
+                    print("停止命令接收,立即终止")
                     break
-                action_is_take_picture = action["take_picture"]
+                # action_is_take_picture = action["take_picture"]
+                record_id = action["record_id"]
                 image_index = -1
-                if action_is_take_picture:
+                if record_id == -1:
+                    image_index = -1
+                else:
                     image_index = index
                 program_item = ProgramItem(
                     websocket_manager=self.websocket_manager,
@@ -1434,6 +1524,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     mcu=self,
                     goods_art_no=goods_art_no,
                     image_index=image_index,
+                    record_id=record_id,
                 )
                 print("self.action_state===>", self.action_state)
                 if self.action_state != 1:
@@ -1472,6 +1563,14 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     #  最后一个初始化处理
                     pass
                 # self.action_state = 2
+            if self.is_stop_action==True:
+                self.msg_type = "run_mcu_stop"
+                self.sendSocketMessage(
+                    code=0,
+                    msg=f"货号:{goods_art_no},执行终止",
+                    device_status=2,
+                )
+                self.is_stop_action = False
             self.action_state = 2
             self.is_runn_action = False
             self.msg_type = "photo_take_finish"
@@ -1483,7 +1582,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.msg_type = "mcu"
             self.controlDevice("laser_position", 1)
 
-    async def run_mcu_config_single(self, config_info, goods_art_no,msg_type="run_mcu_single_finish",image_index=-1):
+    async def run_mcu_config_single(self, config_info, goods_art_no,msg_type="run_mcu_single_finish",image_index=-1,record_id=-1):
         '''独立拍照  仅作测试用'''
         if self.checkDevice() == False:
             return
@@ -1497,6 +1596,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     mcu=self,
                     goods_art_no=goods_art_no,
                     image_index=image_index,
+                    record_id=record_id,
                 )
             print("self.action_state===>", self.action_state)
             if self.action_state != 1:
@@ -1531,6 +1631,26 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 )
             self.msg_type = "mcu"
 
+    async def only_take_photo(self, goods_art_no, image_index, record_id):
+        await asyncio.sleep(0.1)
+        print("only_take_photo=====>",goods_art_no, image_index, record_id)
+        if goods_art_no == "":
+            print("only_take_photo 数据查询异常")
+            return
+        # 关闭led
+        self.controlDevice("laser_position", 0)
+        program_item = ProgramItem(
+            websocket_manager=self.websocket_manager,
+            action_data={},
+            mcu=self,
+            goods_art_no=goods_art_no,
+            image_index=image_index,
+            record_id=record_id,
+        )
+        program_item.digicam_take_picture()
+        # 打开led
+        self.controlDevice("laser_position", 1)
+
 
 async def checkMcuConnection(device_ctrl: DeviceControl):
     if device_ctrl.is_running == True:
@@ -1542,9 +1662,12 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
         device_ctrl.device_status = 2
         device_ctrl.sendSocketMessage(code=0, msg="MCU连接成功", data=message)
         return
+    if device_ctrl.is_init_while:
+        return
+    device_ctrl.is_init_while = True
     """实时检测串口是否连接"""
     while True:
-        await asyncio.sleep(0.5)
+        await asyncio.sleep(1)
         if device_ctrl.mcu_exit:
             break
         ports_dict = device_ctrl.scan_serial_port()
@@ -1554,8 +1677,6 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
             if device_ctrl.p_list:
                 _p = device_ctrl.p_list.pop()
                 device_ctrl.remove_port(_p)
-            print("串口未连接,请检查")
-            device_ctrl.sendSocketMessage(code=1, msg="串口未连接,请检查",device_status=-1)
             continue
         if ports_dict:
             for index, _i in enumerate(device_ctrl.p_list):
@@ -1565,8 +1686,11 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
             for _port_name, _port_value in ports_dict.items():
                 if _port_name not in device_ctrl.p_list:
                     try:
+                        flag = await device_ctrl.add_port_by_linkage(_port_name)
+                        if flag == False:
+                            continue
                         device_ctrl.p_list.append(_port_name)
-                        device_ctrl.add_port_by_linkage(_port_name)
                     except BaseException as e:
                         print("串口不存在{} {}".format(_port_name, e))
+    device_ctrl.is_init_while = False
     print("MCU断开连接,已释放")

+ 245 - 0
python/mcu/LineControl.py

@@ -0,0 +1,245 @@
+import time
+
+# from import_qt_mode import *
+import asyncio
+from .SerialIns import SerialIns
+from .BaseClass import BaseClass
+from utils.SingletonType import SingletonType
+from databases import SqlQuery, PhotoRecord, DeviceConfig, CRUD, insert_photo_records
+from .capture.module_digicam import DigiCam
+from .capture.module_watch_dog import FileEventHandler
+from sockets.connect_manager import ConnectionManager
+
+class LineControl(BaseClass):
+    # sign_data = Signal(dict)
+
+    def __init__(self, websocket_manager: ConnectionManager):
+        super().__init__(websocket_manager)
+        self.serial_ins = None
+        self.connect_state = False
+        self.is_running = False
+        self.msg_type = "blue_tooth"
+        self.goods_art_no = None
+        # 0 闲置;1进行中;2已完成;
+        self.photo_take_state = 0
+
+    async def to_connect_com(self, port_name):
+        self.close_connect()
+        await asyncio.sleep(0.5)
+        try:
+            # 原值为9600
+            self.serial_ins = SerialIns(port_name=port_name, baud=115200)
+            if self.serial_ins.serial_handle:
+                self.connect_state = True
+                message = {
+                    "_type": "show_info",
+                    "plugins_mode": "remote_control",
+                    "data": {"msg": "有线遥控器 打开串口成功", "port_name": port_name},
+                }
+                self.sendSocketMessage(
+                    code=0,
+                    msg="有线遥控器 打开串口成功",
+                    data=message,
+                    device_status=2,
+                )
+                # 循环监听消息
+                await self.run()
+                return True
+            else:
+                message = {
+                    "_type": "show_info",
+                    "plugins_mode": "remote_control",
+                    "data": {"msg": "有线遥控器 打开串口失败"},
+                }
+                self.sendSocketMessage(
+                    code=1,
+                    msg="有线遥控器 打开串口失败",
+                    data=message,
+                    device_status=-1,
+                )
+                self.serial_ins = None
+                self.connect_state = False
+        except:
+            message = {
+                "_type": "show_info",
+                "plugins_mode": "remote_control",
+                "data": {"msg": "有线遥控器 打开串口失败"},
+            }
+            self.sendSocketMessage(
+                code=1,
+                msg="有线遥控器 打开串口失败",
+                data=message,
+                device_status=-1,
+            )
+            self.serial_ins = None
+            self.connect_state = False
+            return False
+
+    def close_connect(self):
+        if self.connect_state:
+            self.serial_ins.close_serial_port()
+            self.connect_state = False
+
+    def __del__(self):
+        self.close_connect()
+
+    async def to_connect_linecontrol(self):
+        """连接有线控制器"""
+        print("to_connect_linecontrol 连接有线控制器,连接状态", self.connect_state)
+        if self.connect_state:
+            return
+        message = {
+            "_type": "show_info",
+            "plugins_mode": "remote_control",
+            "data": "有线遥控器 打开成功",
+        }
+        self.close_connect()
+        print(message)
+        self.sendSocketMessage(
+            code=0, msg="有线遥控器 打开蓝牙成功", data=message, device_status=2
+        )
+        self.connect_state = True
+        self.is_running = True
+        await self.run()
+
+    def handlerAction(self, button_value):
+        """处理拍照动作按键[左 右]"""
+        control_program = "执行左脚程序" if button_value == 1 else "执行右脚程序"
+        match button_value:
+            case 1:
+                control_program = "执行左脚程序"
+            case 2:
+                control_program = "执行右脚程序"
+        if self.goods_art_no == None or self.goods_art_no == "":
+            input_data = {
+                "data": {
+                    "action": control_program,
+                    "goods_art_no": "",
+                },
+                "type": "run_mcu",
+            }
+            self.msg_type = "blue_tooth_scan"
+            self.sendSocketMessage(
+                code=0,
+                msg=f"准备执行[{control_program}]",
+                data=input_data,
+                device_status=2,
+            )
+            self.msg_type = "blue_tooth"
+            return
+        self.photo_take_state = 1
+        input_data = {
+            "data": {
+                "action": control_program,
+                "goods_art_no": self.goods_art_no,
+            },
+            "type": "run_mcu",
+        }
+        self.msg_type = "blue_tooth_scan"
+        self.sendSocketMessage(
+            code=0,
+            msg=f"准备执行[{control_program}]",
+            data=input_data,
+            device_status=2,
+        )
+        self.goods_art_no = None
+        self.msg_type = "blue_tooth"
+        self.photo_take_state = 2
+
+    async def analysis_received_data(self,):
+        await asyncio.sleep(0.01)
+        if not self.connect_state:
+            return
+        receive_data = self.serial_ins.read_cmd(out_time=1, check=0x6B)
+        if receive_data is False:
+            self.connect_state = False
+            return False
+
+        if not receive_data:
+            return
+        else:
+            print("有线控制器receive_data", receive_data)
+            # print(
+            #     "有线控制器 read receive_data {}".format(
+            #         self.serial_ins.change_hex_to_int(receive_data)
+            #     )
+            # )
+            pass
+        # 数据 结构 command,按命令解析
+        if receive_data[0] == 1:
+            # 扫码数据
+            bar_code = receive_data[1:].decode()
+            bar_code = bar_code.replace("\r", "")
+            bar_code = bar_code.replace("\n", "")
+            # self.sign_data.emit(
+            #     {"_type": 0, "plugins_mode": "remote_control", "data": bar_code}
+            # )
+            message = {"_type": 0, "plugins_mode": "remote_control", "data": bar_code}
+            print("有线控制器 扫码数据1", message)
+            self.goods_art_no = bar_code
+            self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
+            return
+        if receive_data[0] == 9:
+            button_value = receive_data[1]
+            data = {"button_value": button_value}
+            message = {"_type": 9, "plugins_mode": "remote_control", "data": data}
+            if button_value in [1, 2]:
+                # 扫描货号
+                if self.photo_take_state != 0:
+                    self.sendSocketMessage(1, "前置拍照未完成,请稍后", device_status=-1)
+                    return
+                print("收到货号信息", self.goods_art_no)
+                self.handlerAction(button_value)
+                self.photo_take_state = 0
+            if button_value in [3]:
+                # 处理遥控器单拍
+                self.msg_type = "handler_take_picture"
+                # 0 闲置;1进行中;2已完成;
+                _data = {"type": self.msg_type, "data": None}
+                self.sendSocketMessage(0, "处理单拍消息", data=_data, device_status=-1)
+                self.msg_type = "blue_tooth"
+            if button_value in [9]:
+                # 处理停止
+                self.msg_type = "stop_action"
+                # 0 闲置;1进行中;2已完成;
+                _data = {"type": self.msg_type, "data": None}
+                self.sendSocketMessage(
+                    0, "停止执行组合动作", data=_data, device_status=-1
+                )
+                self.msg_type = "blue_tooth"
+            self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
+            return
+        pass
+
+    async def run(self):
+        self.is_running = True
+        while True:
+            await asyncio.sleep(0.06)
+            if not self.connect_state:
+                message = {
+                    "_type": "show_info",
+                    "plugins_mode": "remote_control",
+                    "data": {"msg": "有线遥控器 未连接"},
+                }
+                self.sendSocketMessage(
+                    code=1,
+                    msg="有线遥控器 未连接",
+                    data=message,
+                    device_status=-1,
+                )
+                break
+            await self.analysis_received_data()
+
+        self.is_running = False
+        if not self.connect_state:
+            message = {
+                "_type": "show_info",
+                "plugins_mode": "remote_control",
+                "data": {"msg": "有线遥控器 未连接"},
+            }
+            self.sendSocketMessage(
+                code=1,
+                msg="有线遥控器 未连接",
+                data=message,
+                device_status=-1,
+            )

+ 4 - 5
python/mcu/McuDeviationSet.py

@@ -21,8 +21,8 @@ class McuDeviationSet:
         self.last_value = defaultdict(float)
         is_debug = True if settings.IS_DEBUG == "true" else False
         self.mcu_debug = McuDebug(mcu, is_debug=is_debug, is_deviation=False)
-        loop = asyncio.get_event_loop()
-        loop.create_task(self.get_mcu_deviation(), name="get_mcu_deviation")
+        # loop = asyncio.get_event_loop()
+        self.get_mcu_deviation()
         # # 运动到设定位
         # QTimer.singleShot(2500, self.init_pos)
 
@@ -235,9 +235,8 @@ class McuDeviationSet:
     def _to_init_all(self, *args):
         self.mcu.to_init_device_origin_point(device_name="mcu", is_force=True)
 
-    async def get_mcu_deviation(self):
-        await self.mcu.getDeviationInfo()
-
+    def get_mcu_deviation(self):
+        asyncio.run(self.mcu.getDeviationInfo())
     def get_mcu_deviation_info(self, data):
         if "_type" not in data:
             return

+ 27 - 5
python/mcu/ProgramItem.py

@@ -7,11 +7,20 @@ import time
 from .capture.module_digicam import DigiCam
 from .capture.module_watch_dog import FileEventHandler
 
+
 class ProgramItem(BaseClass):
     # program_sign = Signal(dict)
     # program_refresh_photo_list_sign = Signal()
 
-    def __init__(self,websocket_manager, action_data:any, mcu, goods_art_no:str=None,image_index:int=-1):
+    def __init__(
+        self,
+        websocket_manager,
+        action_data: any,
+        mcu,
+        goods_art_no: str = None,
+        image_index: int = -1,
+        record_id: int = -1,
+    ):
         super().__init__(BaseClass)
         # 1 表示等待中,2表示没有等待
         self.wait_state = 2
@@ -23,6 +32,7 @@ class ProgramItem(BaseClass):
         self.watch_dog = FileEventHandler()
         self.watch_dog.goods_art_no = goods_art_no
         self.watch_dog.image_index = image_index
+        self.watch_dog.record_id = record_id
         self.watch_dog.mcu = mcu
         self.watch_dog.start_observer(captrure_folder_path)
         print("21 =========ProgramItem=======action_data=====")
@@ -93,7 +103,7 @@ class ProgramItem(BaseClass):
         }
         if self.is_wait:
             msg = "{}--等待".format(self.action_name)
-            self.sendSocketMessage(msg=msg,device_status=0)
+            self.sendSocketMessage(msg=msg, device_status=0)
         else:
             msg = "{}".format(self.action_name)
             self.sendSocketMessage(msg=msg, device_status=2)
@@ -137,12 +147,12 @@ class ProgramItem(BaseClass):
                 # 外部终止,停止运行
                 return False
             cr_time = time.time()
-            print(cr_time - _s, cr_time,_s)
+            print(cr_time - _s, cr_time, _s)
             if cr_time - _s > 8:
                 self.error_info_text = "MCU检测运动未停止,自动退出"
                 self.set_state(state_value=99)  # 标记异常
                 print("MCU检测运动未停止,自动退出")
-                self.sendSocketMessage(msg=self.error_info_text,device_status=-1)
+                self.sendSocketMessage(msg=self.error_info_text, device_status=-1)
                 return False
                 # return True
             # 存在时间间隙,导致误认为所有设备已完成运动
@@ -218,7 +228,11 @@ class ProgramItem(BaseClass):
             if self.mode_type != "其他配置" and self.check_mcu_move_is_stop() is False:
                 # MCU运动是否有停止检查,设定超时时间
                 return
-            print("{} 检查停止时间1:{}".format(self.action_name, time.time() - start_time))
+            print(
+                "{} 检查停止时间1:{}".format(
+                    self.action_name, time.time() - start_time
+                )
+            )
             if self.is_led:
                 self.mcu.to_deal_device(device_name="laser_position", value=1)
             else:
@@ -280,6 +294,14 @@ class ProgramItem(BaseClass):
             time.sleep(self.after_delay_time)
         return True
 
+    def digicam_take_picture(self):
+        self.mcu.to_deal_device(device_name="buzzer", times=1)
+        # 用于临时拍照计数
+        is_af = True
+        self.capture_one.photograph(is_af=is_af)
+        self.last_photograph_time = time.time()  # 记录最近一次拍照时间
+        print("仅拍照执行完成")
+
     def rephotograph_one_pic(self, *args):
         """
         1、获取最近一张照片

+ 13 - 3
python/mcu/RemoteControlV2.py

@@ -7,7 +7,7 @@ import settings
 from .SerialIns import SerialIns
 from .BaseClass import BaseClass
 from sockets.connect_manager import ConnectionManager
-from databases import SqlQuery, PhotoRecord, CRUD, insert_photo_records
+from databases import SqlQuery, PhotoRecord, DeviceConfig, CRUD, insert_photo_records
 from .capture.module_digicam import DigiCam
 from .capture.module_watch_dog import FileEventHandler
 
@@ -262,13 +262,22 @@ class RemoteControlV2(BaseClass):
                 )
                 self.msg_type = "blue_tooth"
                 return
+            deviceConfig = CRUD(DeviceConfig)
+            deviceConfigData = deviceConfig.read(session=session, conditions={"id": record.action_id})
+            select_tab_id = deviceConfigData.tab_id
+            AllTabConfig = deviceConfig.read_all(session=session, conditions={"tab_id": select_tab_id})
+            action_id = 0
+            if AllTabConfig[len(AllTabConfig) - 1].take_picture == True:
+                action_id = AllTabConfig[0].id
+            else:
+                action_id = AllTabConfig[len(AllTabConfig) - 1].id
             image_index = record.image_index + 1
             self.photo_take_state = 1
-            insert_photo_records(
+            state, record_id = insert_photo_records(
                 record.image_deal_mode,
                 record.goods_art_no,
                 image_index,
-                record.action_id,
+                action_id,
             )
             print("开始单拍1-插入数据")
             capture_one = DigiCam()
@@ -279,6 +288,7 @@ class RemoteControlV2(BaseClass):
                     watch_dog.start_observer(captrure_folder_path)
                 watch_dog.goods_art_no = record.goods_art_no
                 watch_dog.image_index = image_index
+                watch_dog.record_id = record_id
                 print("开始单拍1-检查相机")
                 # camera_is_connect = capture_one.checkCameraConnect()
                 # if camera_is_connect is not True:

+ 16 - 4
python/mcu/capture/module_watch_dog.py

@@ -10,7 +10,7 @@ from databases import CRUD, SqlQuery, PhotoRecord
 import asyncio
 
 
-def updateImageRaw(time_str, image_path, goods_art_no, image_index):
+def updateImageRaw(time_str, image_path, goods_art_no, record_id):
     session = SqlQuery()
     crud = CRUD(PhotoRecord)
     res = crud.read(
@@ -18,7 +18,15 @@ def updateImageRaw(time_str, image_path, goods_art_no, image_index):
         conditions={
             "image_path": None,
             "goods_art_no": goods_art_no,
-            "image_index": image_index,
+            "id": record_id,
+        },
+    )
+    print(
+        "更新图片数据库======>",
+        {
+            "image_path": image_path,
+            "goods_art_no": goods_art_no,
+            "id": record_id,
         },
     )
     if res:
@@ -29,7 +37,7 @@ def updateImageRaw(time_str, image_path, goods_art_no, image_index):
         }
         crud.update(
             session,
-            res.id,
+            record_id,
             **update,
         )
 
@@ -45,6 +53,7 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
         #     self.init_flag = True
         self.goods_art_no = None
         self.image_index = -1
+        self.record_id = -1
         self.mcu = None
         super().__init__()
         # self.window = window
@@ -176,7 +185,10 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
                 )
                 loop.close()
                 updateImageRaw(
-                    create_time, file_path, self.goods_art_no, self.image_index
+                    create_time,
+                    file_path,
+                    self.goods_art_no,
+                    self.record_id,
                 )
             except BaseException as e:
                 print("获取文件create_time失败", e)

+ 1 - 1
python/service/OnePicTest.py

@@ -91,7 +91,7 @@ class OnePicTest():
         if not os.path.exists(self.pic_path):
             raise UnicornException("图片不存在")
         image_pth = Image.open(self.pic_path)
-        if image_pth.mode != "RGB":
+        if image_pth.mode == "RGBA":
             raise UnicornException("抠图图片不能是PNG")
         return_data = self.deal_image(self.pic_path)
         # if return_data["message"]:

+ 7 - 4
python/service/generate_main_image/grenerate_main_image_test.py

@@ -402,11 +402,14 @@ class GeneratePic(object):
         print("242  need_time_1:{}".format(time.time() - _s))
 
         orign_x, orign_y = orign_im.size
-        time.sleep(1)
+        time.sleep(3)
         cut_image = Image.open(cut_image_path)  # 原始图的已扣图
-        cut_image, new_box = get_mini_crop_img(img=cut_image)
-        im_shadow = orign_im.crop(new_box)  # 切图
-        new_x, new_y = im_shadow.size
+        try:
+            cut_image, new_box = get_mini_crop_img(img=cut_image)
+            im_shadow = orign_im.crop(new_box)  # 切图
+            new_x, new_y = im_shadow.size
+        except Exception as e:
+            im_shadow = cut_image
 
         # ================自动色阶处理
         _s = time.time()

+ 43 - 13
python/sockets/message_handler.py

@@ -6,6 +6,7 @@ from mcu.BlueToothMode import BlueToothMode
 from databases import DeviceConfig, SqlQuery, CRUD, PhotoRecord, SysConfigs
 from mcu.capture.module_digicam import DigiCam
 
+
 # socket消息发送逻辑处理方法
 async def handlerSend(
     manager: ConnectionManager, receiveData: str, websocket: WebSocket
@@ -30,7 +31,7 @@ async def handlerSend(
             pass
         case "forward_message":
             data = receiveData.get("data")
-            dictMsg = {"code":code,"msg":msg,"data":data}
+            dictMsg = {"code": code, "msg": msg, "data": data}
             await manager.broadcast(dictMsg)
         case "connect_mcu":
             device_ctrl = DeviceControl(websocket_manager=manager)
@@ -48,7 +49,7 @@ async def handlerSend(
         case "init_mcu":
             device_ctrl = DeviceControl(websocket_manager=manager)
             # 是否强制初始化
-            is_force_init = data.get("value",False)
+            is_force_init = data.get("value", False)
             loop.create_task(device_ctrl.initDevice(is_force_init), name="init_mcu")
         case "control_mcu":
             device_name = data.get("device_name")
@@ -56,9 +57,7 @@ async def handlerSend(
             if (device_name == "" or device_name == None) or (
                 value == "" or value == None
             ):
-                data = manager.jsonMessage(
-                    code=1, msg="参数错误", msg_type="mcu"
-                )
+                data = manager.jsonMessage(code=1, msg="参数错误", msg_type="mcu")
                 await manager.send_personal_message(data, websocket)
                 return
             device_ctrl = DeviceControl(websocket_manager=manager)
@@ -74,7 +73,7 @@ async def handlerSend(
             msg_type = "run_mcu"
             action_info = data.get("action", "执行左脚程序")
             goods_art_no = data.get("goods_art_no", None)
-            if goods_art_no == None or goods_art_no =="":
+            if goods_art_no == None or goods_art_no == "":
                 # 判断货号是否存在
                 data = manager.jsonMessage(
                     code=1, msg="goods_art_no不能为空", msg_type=msg_type
@@ -92,7 +91,9 @@ async def handlerSend(
                 action_flag = "right"
             tab_id = action_configs_json.get(action_flag)
             photoRecord = CRUD(PhotoRecord)
-            goods_art_record = photoRecord.read(session,conditions={"goods_art_no": goods_art_no})
+            goods_art_record = photoRecord.read(
+                session, conditions={"goods_art_no": goods_art_no}
+            )
             if goods_art_record != None:
                 data = manager.jsonMessage(
                     code=1,
@@ -111,7 +112,7 @@ async def handlerSend(
                 data = manager.jsonMessage(code=1, msg="当前没有可用配置")
                 await manager.send_personal_message(data, websocket, msg_type=msg_type)
                 return
-            action_list = [device.model_dump() for device in all_devices]
+            action_list = [dict(device.__dict__) for device in all_devices]
             print("action_list", action_list)
             device_ctrl = DeviceControl(websocket_manager=manager)
             loop.create_task(
@@ -130,7 +131,7 @@ async def handlerSend(
                 blue_tooth.remote_control_v2.handlerTakePhoto(),
                 name="run_mcu_config",
             )
-        case "re_take_picture":#重拍
+        case "re_take_picture":  # 重拍
             # try:
             #     # 判断拍照软件是否初始化
             #     digicam = DigiCam()
@@ -166,9 +167,8 @@ async def handlerSend(
             image_index = goods_art_record.image_index
             crud = CRUD(DeviceConfig)
             condtions = {"id": action_id}
-            device_action = crud.read(
-                session, conditions=condtions
-            )
+            device_action = crud.read(session, conditions=condtions)
+            device_result = dict(device_action.__dict__)
             if device_action == None:
                 # 判断是否有可用配置
                 data = manager.jsonMessage(code=1, msg="当前没有可用配置")
@@ -180,7 +180,11 @@ async def handlerSend(
             device_ctrl = DeviceControl(websocket_manager=manager)
             loop.create_task(
                 device_ctrl.run_mcu_config_single(
-                    device_action.model_dump(), goods_art_no, msg_type=msg_type,image_index=image_index
+                    device_result,
+                    goods_art_no,
+                    msg_type=msg_type,
+                    image_index=image_index,
+                    record_id=record_id,
                 ),
                 name="run_mcu_config_single",
             )
@@ -224,6 +228,32 @@ async def handlerSend(
                 device_ctrl.sendCommand(data.get("command", None)),
                 name="sendCommand",
             )
+        case "digicam_take_picture":
+            msg_type = "re_take_picture"
+            id = data.get("id", 0)
+            goods_art_no = data.get("goods_art_no", "")
+            session = SqlQuery()
+            photoRecord = CRUD(PhotoRecord)
+            goods_art_record = photoRecord.read(session, conditions={"id": id})
+            if goods_art_record == None:
+                data = manager.jsonMessage(
+                    code=1,
+                    msg=f"记录不存在,请核实后重新操作~",
+                    msg_type=msg_type,
+                )
+                await manager.send_personal_message(data, websocket)
+                return
+            reset_data = {"image_path": None}
+            photoRecord.update(session, id, **reset_data)
+            device_ctrl = DeviceControl(websocket_manager=manager)
+            loop.create_task(
+                device_ctrl.only_take_photo(
+                    goods_art_no=goods_art_no,
+                    image_index=goods_art_record.image_index,
+                    record_id=id,
+                ),
+                name="sendCommand",
+            )
         case _:
             data = manager.jsonMessage(code=1, msg="未知消息")
             await manager.send_personal_message(data, websocket)

+ 0 - 1
python/sockets/socket_server.py

@@ -58,7 +58,6 @@ async def websocket_endpoint(websocket: WebSocket):
                 except Exception as e:
                     print(e)
                     break
-
         await asyncio.gather(handler_messages(), send_message())
     except WebSocketDisconnect:
         # socket_manager.close()