|
@@ -15,6 +15,7 @@ from databases import insert_photo_records
|
|
|
from .McuDeviationSet import McuDeviationSet
|
|
from .McuDeviationSet import McuDeviationSet
|
|
|
from .OtherSet import OtherSet
|
|
from .OtherSet import OtherSet
|
|
|
from .DebugUart import DebugUart
|
|
from .DebugUart import DebugUart
|
|
|
|
|
+from .LineControl import LineControl
|
|
|
import copy
|
|
import copy
|
|
|
|
|
|
|
|
# mcu命令
|
|
# mcu命令
|
|
@@ -27,6 +28,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.mcu_deviation_set = McuDeviationSet(self)
|
|
self.mcu_deviation_set = McuDeviationSet(self)
|
|
|
self.mcu_other_set = OtherSet(self)
|
|
self.mcu_other_set = OtherSet(self)
|
|
|
self.debug_uart = DebugUart(self)
|
|
self.debug_uart = DebugUart(self)
|
|
|
|
|
+ self.debug_uart = DebugUart(self)
|
|
|
|
|
+ self.line_control = LineControl(websocket_manager)
|
|
|
self.m_t = 1
|
|
self.m_t = 1
|
|
|
# 0未开始 1进行中 2已结束 99异常
|
|
# 0未开始 1进行中 2已结束 99异常
|
|
|
self.action_state = 2
|
|
self.action_state = 2
|
|
@@ -198,6 +201,44 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
+ 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):
|
|
def stop_mcu(self):
|
|
|
buf = [self.command["stop_mcu"]]
|
|
buf = [self.command["stop_mcu"]]
|
|
|
buf.extend(self.encapsulation_data(data=1, len_data=1))
|
|
buf.extend(self.encapsulation_data(data=1, len_data=1))
|
|
@@ -851,7 +892,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
}
|
|
}
|
|
|
self.sendSocketMessage(1, "串口被移除", data)
|
|
self.sendSocketMessage(1, "串口被移除", data)
|
|
|
|
|
|
|
|
- def add_port_by_linkage(self, port_name):
|
|
|
|
|
|
|
+ async def add_port_by_linkage(self, port_name):
|
|
|
# port_value :串口基础信息
|
|
# port_value :串口基础信息
|
|
|
# todo 根据prot_value 信息自动进行连接
|
|
# todo 根据prot_value 信息自动进行连接
|
|
|
print("add", port_name)
|
|
print("add", port_name)
|
|
@@ -864,7 +905,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.sendSocketMessage(
|
|
self.sendSocketMessage(
|
|
|
msg="开始识别接口:{}".format(port_name), data=message_data, device_status=1
|
|
msg="开始识别接口:{}".format(port_name), data=message_data, device_status=1
|
|
|
)
|
|
)
|
|
|
- time.sleep(1)
|
|
|
|
|
|
|
+ await asyncio.sleep(1)
|
|
|
"""
|
|
"""
|
|
|
步骤:
|
|
步骤:
|
|
|
1、进行临时连接,并发送命令,成功后,自动连接对应设备
|
|
1、进行临时连接,并发送命令,成功后,自动连接对应设备
|
|
@@ -887,7 +928,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
print("串口:{} 被占用".format(port_name))
|
|
print("串口:{} 被占用".format(port_name))
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- time.sleep(2)
|
|
|
|
|
|
|
+ await asyncio.sleep(2)
|
|
|
print("开始发送命令")
|
|
print("开始发送命令")
|
|
|
data = [90, 1]
|
|
data = [90, 1]
|
|
|
try:
|
|
try:
|
|
@@ -915,7 +956,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
serial_handle.close()
|
|
serial_handle.close()
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- time.sleep(0.3)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.3)
|
|
|
print("尝试接收命令")
|
|
print("尝试接收命令")
|
|
|
receive_data = self.read_cmd(serial_handle)
|
|
receive_data = self.read_cmd(serial_handle)
|
|
|
device_id = 0
|
|
device_id = 0
|
|
@@ -928,10 +969,10 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
|
|
|
|
|
print("关闭串口:{}".format(port_name))
|
|
print("关闭串口:{}".format(port_name))
|
|
|
serial_handle.close()
|
|
serial_handle.close()
|
|
|
-
|
|
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
if device_id > 0:
|
|
if device_id > 0:
|
|
|
if device_id == 1:
|
|
if device_id == 1:
|
|
|
- self.to_connect_com(port_name)
|
|
|
|
|
|
|
+ await self.to_connect_com(port_name)
|
|
|
message_data = {
|
|
message_data = {
|
|
|
"_type": "show_info",
|
|
"_type": "show_info",
|
|
|
"plugins_mode": "auto_select_com",
|
|
"plugins_mode": "auto_select_com",
|
|
@@ -941,20 +982,52 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
msg="MCU开始连接", data=message_data, device_status=1
|
|
msg="MCU开始连接", data=message_data, device_status=1
|
|
|
)
|
|
)
|
|
|
self.connected_ports_dict[port_name] = "MCU"
|
|
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():
|
|
# async def getBaseInfo():
|
|
|
# while True:
|
|
# while True:
|
|
|
# await asyncio.sleep(1)
|
|
# await asyncio.sleep(1)
|
|
@@ -975,11 +1048,11 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# 连接不上,记录为其他列表
|
|
# 连接不上,记录为其他列表
|
|
|
def clearMyInstance(self):
|
|
def clearMyInstance(self):
|
|
|
SingletonType.clear_instance()
|
|
SingletonType.clear_instance()
|
|
|
- def to_connect_com(self, port_name):
|
|
|
|
|
|
|
+ async def to_connect_com(self, port_name):
|
|
|
# 关闭串口
|
|
# 关闭串口
|
|
|
print("to_connect_com", port_name)
|
|
print("to_connect_com", port_name)
|
|
|
self.close_connect()
|
|
self.close_connect()
|
|
|
- time.sleep(0.3)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.3)
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
try:
|
|
try:
|
|
|
self.serial_ins = SerialIns(port_name=port_name, baud=115200, timeout=0.1)
|
|
self.serial_ins = SerialIns(port_name=port_name, baud=115200, timeout=0.1)
|
|
@@ -994,7 +1067,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
)
|
|
)
|
|
|
self.serial_ins = None
|
|
self.serial_ins = None
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
- return False
|
|
|
|
|
|
|
+ return False,None
|
|
|
|
|
|
|
|
except:
|
|
except:
|
|
|
message_data = {
|
|
message_data = {
|
|
@@ -1007,7 +1080,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
)
|
|
)
|
|
|
self.serial_ins = None
|
|
self.serial_ins = None
|
|
|
self.connect_state = False
|
|
self.connect_state = False
|
|
|
- return False
|
|
|
|
|
|
|
+ return False, None
|
|
|
|
|
|
|
|
message_data = {
|
|
message_data = {
|
|
|
"_type": "show_info",
|
|
"_type": "show_info",
|
|
@@ -1024,7 +1097,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.serial_ins.write_cmd(data)
|
|
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)
|
|
receive_data = self.serial_ins.read_cmd(out_time=1)
|
|
|
if receive_data:
|
|
if receive_data:
|
|
|
print(
|
|
print(
|
|
@@ -1148,6 +1221,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
|
|
|
|
|
cmd = 1
|
|
cmd = 1
|
|
|
device_id = self.device_name_dict[device_name]
|
|
device_id = self.device_name_dict[device_name]
|
|
|
|
|
+ if device_id != 1:
|
|
|
|
|
+ print("F非MCU设备,禁止处理")
|
|
|
|
|
+ return
|
|
|
print("正在执行",device_name)
|
|
print("正在执行",device_name)
|
|
|
match device_name:
|
|
match device_name:
|
|
|
case "camera_high_motor":
|
|
case "camera_high_motor":
|
|
@@ -1577,7 +1653,7 @@ async def checkMcuConnection(device_ctrl: DeviceControl):
|
|
|
if _port_name not in device_ctrl.p_list:
|
|
if _port_name not in device_ctrl.p_list:
|
|
|
try:
|
|
try:
|
|
|
device_ctrl.p_list.append(_port_name)
|
|
device_ctrl.p_list.append(_port_name)
|
|
|
- device_ctrl.add_port_by_linkage(_port_name)
|
|
|
|
|
|
|
+ await device_ctrl.add_port_by_linkage(_port_name)
|
|
|
except BaseException as e:
|
|
except BaseException as e:
|
|
|
print("串口不存在{} {}".format(_port_name, e))
|
|
print("串口不存在{} {}".format(_port_name, e))
|
|
|
print("MCU断开连接,已释放")
|
|
print("MCU断开连接,已释放")
|