|
@@ -56,6 +56,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,
|
|
@@ -187,7 +188,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# print("mcu send_cmd")
|
|
# print("mcu send_cmd")
|
|
|
self.send_cmd()
|
|
self.send_cmd()
|
|
|
# time.sleep(0.01)
|
|
# time.sleep(0.01)
|
|
|
- self.get_basic_info_mcu()
|
|
|
|
|
|
|
+ if not self.get_basic_info_mcu():
|
|
|
|
|
+ pass
|
|
|
# self.close_other_window()
|
|
# self.close_other_window()
|
|
|
except BaseException as e:
|
|
except BaseException as e:
|
|
|
print("121231298908", e)
|
|
print("121231298908", e)
|
|
@@ -196,9 +198,10 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.is_running = False
|
|
self.is_running = False
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
print("MCU 循环退出~")
|
|
print("MCU 循环退出~")
|
|
|
- # self.sign_data.emit(
|
|
|
|
|
- # {"_type": "show_info", "plugins_mode": "mcu", "data": "MCU 连接失败"}
|
|
|
|
|
- # )
|
|
|
|
|
|
|
+ print("串口未连接,请检查")
|
|
|
|
|
+ self.sendSocketMessage(
|
|
|
|
|
+ code=1, msg="MCU串口未连接,请检查", 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()
|
|
@@ -507,7 +510,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
|
|
@@ -917,7 +920,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
try:
|
|
try:
|
|
|
# 尝试使用115200波特率链接
|
|
# 尝试使用115200波特率链接
|
|
|
serial_handle = serial.Serial(port=port_name, baudrate=115200, timeout=0.5)
|
|
serial_handle = serial.Serial(port=port_name, baudrate=115200, timeout=0.5)
|
|
|
- except:
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
message_data = {
|
|
message_data = {
|
|
|
"_type": "show_info",
|
|
"_type": "show_info",
|
|
|
"plugins_mode": "auto_select_com",
|
|
"plugins_mode": "auto_select_com",
|
|
@@ -961,8 +964,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
await asyncio.sleep(0.3)
|
|
await asyncio.sleep(0.3)
|
|
|
- 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:
|
|
@@ -999,13 +1002,11 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
msg="MCU连接成功", data=message_data, device_status=2
|
|
msg="MCU连接成功", data=message_data, device_status=2
|
|
|
)
|
|
)
|
|
|
await asyncio.sleep(2)
|
|
await asyncio.sleep(2)
|
|
|
- # await self.initDevice()
|
|
|
|
|
- loop.create_task(
|
|
|
|
|
- self.initDevice(port_name),
|
|
|
|
|
- name="initDevice",
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ # 异步处理
|
|
|
|
|
+ loop.create_task(self.initDevice(),name="initDevice")
|
|
|
elif device_id == 2:
|
|
elif device_id == 2:
|
|
|
# 有线接收器
|
|
# 有线接收器
|
|
|
|
|
+ self.connected_ports_dict[port_name] = "Line_Control"
|
|
|
print("device_id", device_id)
|
|
print("device_id", device_id)
|
|
|
loop.create_task(
|
|
loop.create_task(
|
|
|
self.line_control.to_connect_com(port_name),
|
|
self.line_control.to_connect_com(port_name),
|
|
@@ -1152,8 +1153,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")
|
|
|
|
|
|
|
@@ -1664,20 +1665,20 @@ 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
|
|
|
|
|
+ device_ctrl.is_init_while = True
|
|
|
"""实时检测串口是否连接"""
|
|
"""实时检测串口是否连接"""
|
|
|
while True:
|
|
while True:
|
|
|
- await asyncio.sleep(0.01)
|
|
|
|
|
|
|
+ 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()
|
|
|
device_ctrl.temp_ports_dict = ports_dict
|
|
device_ctrl.temp_ports_dict = ports_dict
|
|
|
|
|
+ print("device_ctrl.p_list", device_ctrl.p_list)
|
|
|
if not ports_dict:
|
|
if not ports_dict:
|
|
|
# 全部清空 移除所有串口
|
|
# 全部清空 移除所有串口
|
|
|
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):
|
|
@@ -1693,4 +1694,10 @@ 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))
|
|
|
|
|
+ # if not device_ctrl.connect_state:
|
|
|
|
|
+ # print("串口未连接,请检查")
|
|
|
|
|
+ # device_ctrl.sendSocketMessage(
|
|
|
|
|
+ # code=1, msg="串口未连接,请检查", device_status=-1
|
|
|
|
|
+ # )
|
|
|
|
|
+ device_ctrl.is_init_while = False
|
|
|
print("MCU断开连接,已释放")
|
|
print("MCU断开连接,已释放")
|