|
|
@@ -7,6 +7,10 @@ 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 .capture.module_digicam import DigiCam
|
|
|
+from .capture.module_watch_dog import FileEventHandler
|
|
|
+
|
|
|
|
|
|
# from .BlueToothMode import BlueToothMode
|
|
|
class RemoteControlV2(BaseClass):
|
|
|
@@ -56,7 +60,7 @@ class RemoteControlV2(BaseClass):
|
|
|
"plugins_mode": "remote_control",
|
|
|
"data": port_name,
|
|
|
}
|
|
|
- self.sendSocketMessage(code=0, msg="", data=message,device_status=2)
|
|
|
+ self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
|
|
|
print(message)
|
|
|
self.port_name = port_name
|
|
|
|
|
|
@@ -72,8 +76,10 @@ class RemoteControlV2(BaseClass):
|
|
|
"data": "遥控设备V2 打开串口失败",
|
|
|
}
|
|
|
self.sendSocketMessage(
|
|
|
- code=1, msg="遥控设备V2 打开串口失败", data=message,
|
|
|
- device_status=-1
|
|
|
+ code=1,
|
|
|
+ msg="遥控设备V2 打开串口失败",
|
|
|
+ data=message,
|
|
|
+ device_status=-1,
|
|
|
)
|
|
|
print(message)
|
|
|
self.serial_ins = None
|
|
|
@@ -114,7 +120,9 @@ class RemoteControlV2(BaseClass):
|
|
|
"data": "遥控设备V2 打开蓝牙成功",
|
|
|
}
|
|
|
print(message)
|
|
|
- self.sendSocketMessage(code=0, msg="遥控设备V2 打开蓝牙成功", data=message,device_status=2)
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=0, msg="遥控设备V2 打开蓝牙成功", data=message, device_status=2
|
|
|
+ )
|
|
|
self.connect_state = True
|
|
|
self.is_running = True
|
|
|
self.set_voltage_value(0)
|
|
|
@@ -143,7 +151,9 @@ class RemoteControlV2(BaseClass):
|
|
|
flag = "接收器已连接 {}".format(
|
|
|
"蓝牙" if self.bluetooth_address else "串口"
|
|
|
)
|
|
|
- self.sendSocketMessage(code=0, msg="遥控设备V2 打开蓝牙成功", data=None,device_status=2)
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=0, msg="遥控设备V2 打开蓝牙成功", data=None, device_status=2
|
|
|
+ )
|
|
|
self.connect_state = True
|
|
|
self.is_running = True
|
|
|
else:
|
|
|
@@ -167,6 +177,7 @@ class RemoteControlV2(BaseClass):
|
|
|
msg="电量:{}%".format(voltage_value), device_status=device_status
|
|
|
)
|
|
|
# print("打印===>", flag)
|
|
|
+
|
|
|
def close_connect(self):
|
|
|
self.port_name = ""
|
|
|
self.bluetooth_address = ""
|
|
|
@@ -183,44 +194,89 @@ class RemoteControlV2(BaseClass):
|
|
|
self.windows.playsound.start()
|
|
|
|
|
|
def handlerAction(self, button_value):
|
|
|
- '''处理拍照动作按键[左 右]'''
|
|
|
+ """处理拍照动作按键[左 右]"""
|
|
|
control_program = "执行左脚程序" if button_value == 1 else "执行右脚程序"
|
|
|
- if self.goods_art_no == None or self.goods_art_no =="":
|
|
|
+ if self.goods_art_no == None or self.goods_art_no == "":
|
|
|
input_data = {
|
|
|
- "data": {
|
|
|
- "action": control_program,
|
|
|
- "goods_art_no": "",
|
|
|
- },
|
|
|
- "type": "run_mcu",
|
|
|
- }
|
|
|
+ "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,
|
|
|
- )
|
|
|
+ code=0,
|
|
|
+ msg=f"准备执行[{control_program}]",
|
|
|
+ data=input_data,
|
|
|
+ device_status=2,
|
|
|
+ )
|
|
|
self.msg_type = "blue_tooth"
|
|
|
return
|
|
|
input_data = {
|
|
|
- "data": {
|
|
|
- "action": control_program,
|
|
|
- "goods_art_no": self.goods_art_no,
|
|
|
- },
|
|
|
- "type": "run_mcu",
|
|
|
- }
|
|
|
+ "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,
|
|
|
- )
|
|
|
+ code=0,
|
|
|
+ msg=f"准备执行[{control_program}]",
|
|
|
+ data=input_data,
|
|
|
+ device_status=2,
|
|
|
+ )
|
|
|
self.goods_art_no = None
|
|
|
self.msg_type = "blue_tooth"
|
|
|
+
|
|
|
def handlerTakePhoto(self):
|
|
|
"""处理单独拍照"""
|
|
|
- pass
|
|
|
+ session = SqlQuery()
|
|
|
+ crud = CRUD(PhotoRecord)
|
|
|
+ record = crud.read(session=session, order_by="id", ascending=False)
|
|
|
+ if record == None:
|
|
|
+ # 发送失败消息
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=1,
|
|
|
+ msg="单拍失败,请先输入货号或扫码进行组合拍摄",
|
|
|
+ data=None,
|
|
|
+ device_status=2,
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ image_index = record.image_index + 1
|
|
|
+ insert_photo_records(
|
|
|
+ record.image_deal_mode, record.goods_art_no, image_index
|
|
|
+ )
|
|
|
+ capture_one = DigiCam()
|
|
|
+ try:
|
|
|
+ captrure_folder_path = capture_one.getCaptureFolderPath()
|
|
|
+ watch_dog = FileEventHandler()
|
|
|
+ watch_dog.goods_art_no = record.goods_art_no
|
|
|
+ watch_dog.image_index = image_index
|
|
|
+ watch_dog.start_observer(captrure_folder_path)
|
|
|
+ camera_is_connect = capture_one.checkCameraConnect()
|
|
|
+ if camera_is_connect is not True:
|
|
|
+ self.sendSocketMessage(1, "相机未连接,请检查", device_status=-1)
|
|
|
+ return
|
|
|
+ capture_one.getCaptureFolderPath()
|
|
|
+ capture_one.run_capture_action("Capture")
|
|
|
+ time.sleep(1)
|
|
|
+ self.msg_type = "photo_take"
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=0,
|
|
|
+ msg="{} 执行完成~".format(
|
|
|
+ "执行右脚程序"
|
|
|
+ if record.image_deal_mode == 1
|
|
|
+ else "执行左脚程序"
|
|
|
+ ),
|
|
|
+ device_status=2,
|
|
|
+ )
|
|
|
+ self.msg_type = "blue_tooth"
|
|
|
+ except Exception as e:
|
|
|
+ print("错误信息:",e)
|
|
|
+ self.sendSocketMessage(1, "digicam未初始化,请检查", device_status=-1)
|
|
|
+
|
|
|
def analysis_received_data(self):
|
|
|
if not self.connect_state:
|
|
|
return
|
|
|
@@ -258,13 +314,12 @@ class RemoteControlV2(BaseClass):
|
|
|
data = {"button_value": button_value}
|
|
|
message = {"_type": 9, "plugins_mode": "remote_control", "data": data}
|
|
|
print(message)
|
|
|
- if button_value in [1,2]:
|
|
|
+ if button_value in [1, 2]:
|
|
|
# 扫描货号
|
|
|
print("收到货号信息", self.goods_art_no)
|
|
|
self.handlerAction(button_value)
|
|
|
if button_value in [3]:
|
|
|
- # 处理单拍
|
|
|
- print("收到货号信息", self.goods_art_no)
|
|
|
+ # 处理遥控器单拍
|
|
|
self.handlerTakePhoto()
|
|
|
self.sendSocketMessage(code=0, msg="", data=message, device_status=2)
|
|
|
if settings.IS_DEBUG:
|
|
|
@@ -393,7 +448,9 @@ class RemoteControlV2(BaseClass):
|
|
|
"data": "遥控设备V2 未连接",
|
|
|
}
|
|
|
print(message)
|
|
|
- self.sendSocketMessage(code=1, msg="遥控设备V2 未连接", data=message,device_status=-1)
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=1, msg="遥控设备V2 未连接", data=message, device_status=-1
|
|
|
+ )
|
|
|
break
|
|
|
self.analysis_received_data()
|
|
|
|