|
@@ -38,7 +38,6 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.state_turntable_steering = 3
|
|
self.state_turntable_steering = 3
|
|
|
self.state_overturn_steering = 3
|
|
self.state_overturn_steering = 3
|
|
|
self.state_move_turntable_steering = 3
|
|
self.state_move_turntable_steering = 3
|
|
|
-
|
|
|
|
|
self.last_from_mcu_move_respond_data = None
|
|
self.last_from_mcu_move_respond_data = None
|
|
|
self.camera_motor_speed = 0
|
|
self.camera_motor_speed = 0
|
|
|
self.camera_motor_value = 0
|
|
self.camera_motor_value = 0
|
|
@@ -54,6 +53,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.is_runn_action = False
|
|
self.is_runn_action = False
|
|
|
self.is_stop_action = False
|
|
self.is_stop_action = False
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
|
|
+ self.is_init_while = False
|
|
|
self.device_name_dict = {
|
|
self.device_name_dict = {
|
|
|
"camera_steering": 0,
|
|
"camera_steering": 0,
|
|
|
"camera_high_motor": 1,
|
|
"camera_high_motor": 1,
|
|
@@ -196,6 +196,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# self.sign_data.emit(
|
|
# self.sign_data.emit(
|
|
|
# {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
|
|
# {"_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 连接失败"}
|
|
message = {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
|
|
|
self.sendSocketMessage(code=1, msg="MCU 连接失败", data=message,device_status=-1)
|
|
self.sendSocketMessage(code=1, msg="MCU 连接失败", data=message,device_status=-1)
|
|
|
self.close_connect()
|
|
self.close_connect()
|
|
@@ -502,7 +504,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
return False
|
|
return False
|
|
|
if not receive_data:
|
|
if not receive_data:
|
|
|
- return
|
|
|
|
|
|
|
+ return False
|
|
|
# print("receive_data", receive_data)
|
|
# print("receive_data", receive_data)
|
|
|
# 数据 结构 command,按命令解析
|
|
# 数据 结构 command,按命令解析
|
|
|
# command 0(9) 相机高度1-2 相机角度3-4 转盘角度5-6 灯光状态7 激光指示器状态8,运行状态9
|
|
# command 0(9) 相机高度1-2 相机角度3-4 转盘角度5-6 灯光状态7 激光指示器状态8,运行状态9
|
|
@@ -956,8 +958,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
await asyncio.sleep(0.3)
|
|
await asyncio.sleep(0.3)
|
|
|
- print("尝试接收命令")
|
|
|
|
|
|
|
+ # print("尝试接收命令")
|
|
|
receive_data = self.read_cmd(serial_handle)
|
|
receive_data = self.read_cmd(serial_handle)
|
|
|
|
|
+ print("尝试接收命令", receive_data)
|
|
|
device_id = 0
|
|
device_id = 0
|
|
|
|
|
|
|
|
if receive_data:
|
|
if receive_data:
|
|
@@ -1147,8 +1150,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.is_running = False
|
|
self.is_running = False
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
self.connected_ports_dict = {} # 已连接的ports
|
|
self.connected_ports_dict = {} # 已连接的ports
|
|
|
- self.p_list = []
|
|
|
|
|
- self.temp_ports_dict = {}
|
|
|
|
|
|
|
+ # self.p_list = []
|
|
|
|
|
+ # self.temp_ports_dict = {}
|
|
|
self.init_state = False
|
|
self.init_state = False
|
|
|
print("关闭MCU")
|
|
print("关闭MCU")
|
|
|
|
|
|
|
@@ -1659,9 +1662,12 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
|
|
|
device_ctrl.device_status = 2
|
|
device_ctrl.device_status = 2
|
|
|
device_ctrl.sendSocketMessage(code=0, msg="MCU连接成功", data=message)
|
|
device_ctrl.sendSocketMessage(code=0, msg="MCU连接成功", data=message)
|
|
|
return
|
|
return
|
|
|
|
|
+ if device_ctrl.is_init_while:
|
|
|
|
|
+ return
|
|
|
|
|
+ device_ctrl.is_init_while = True
|
|
|
"""实时检测串口是否连接"""
|
|
"""实时检测串口是否连接"""
|
|
|
while True:
|
|
while True:
|
|
|
- await asyncio.sleep(0.5)
|
|
|
|
|
|
|
+ await asyncio.sleep(1)
|
|
|
if device_ctrl.mcu_exit:
|
|
if device_ctrl.mcu_exit:
|
|
|
break
|
|
break
|
|
|
ports_dict = device_ctrl.scan_serial_port()
|
|
ports_dict = device_ctrl.scan_serial_port()
|
|
@@ -1671,8 +1677,6 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
|
|
|
if device_ctrl.p_list:
|
|
if device_ctrl.p_list:
|
|
|
_p = device_ctrl.p_list.pop()
|
|
_p = device_ctrl.p_list.pop()
|
|
|
device_ctrl.remove_port(_p)
|
|
device_ctrl.remove_port(_p)
|
|
|
- print("串口未连接,请检查")
|
|
|
|
|
- device_ctrl.sendSocketMessage(code=1, msg="串口未连接,请检查",device_status=-1)
|
|
|
|
|
continue
|
|
continue
|
|
|
if ports_dict:
|
|
if ports_dict:
|
|
|
for index, _i in enumerate(device_ctrl.p_list):
|
|
for index, _i in enumerate(device_ctrl.p_list):
|
|
@@ -1688,4 +1692,5 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
|
|
|
device_ctrl.p_list.append(_port_name)
|
|
device_ctrl.p_list.append(_port_name)
|
|
|
except BaseException as e:
|
|
except BaseException as e:
|
|
|
print("串口不存在{} {}".format(_port_name, e))
|
|
print("串口不存在{} {}".format(_port_name, e))
|
|
|
|
|
+ device_ctrl.is_init_while = False
|
|
|
print("MCU断开连接,已释放")
|
|
print("MCU断开连接,已释放")
|