ProgramItem.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. import asyncio
  2. import json
  3. import os
  4. import traceback
  5. from .BaseClass import BaseClass
  6. import settings
  7. import time
  8. from .capture.module_digicam import DigiCam
  9. from .capture.module_watch_dog import FileEventHandler
  10. import logging
  11. logger = logging.getLogger(__name__)
  12. class ProgramItem(BaseClass):
  13. # program_sign = Signal(dict)
  14. # program_refresh_photo_list_sign = Signal()
  15. def __init__(
  16. self,
  17. websocket_manager,
  18. action_data: any,
  19. mcu,
  20. goods_art_no: str = None,
  21. image_index: int = -1,
  22. record_id: int = -1,
  23. smart_shooter=None,
  24. is_get_mcu_state=True,
  25. ):
  26. super().__init__(BaseClass)
  27. # 1 表示等待中,2表示没有等待
  28. self.wait_state = 2
  29. self.msg_type = "mcu"
  30. print("action_data====>", action_data)
  31. self.data = action_data
  32. print("ProgramItem smart_shooter", smart_shooter)
  33. self.smart_shooter = smart_shooter
  34. if smart_shooter == None:
  35. self.capture_one = DigiCam()
  36. captrure_folder_path = self.capture_one.getCaptureFolderPath()
  37. self.watch_dog = FileEventHandler()
  38. self.watch_dog.goods_art_no = goods_art_no
  39. self.watch_dog.image_index = image_index
  40. self.watch_dog.mcu = mcu
  41. self.watch_dog.start_observer(captrure_folder_path)
  42. else:
  43. print("使用smart_shooter")
  44. print("21 =========ProgramItem=======action_data=====")
  45. print(action_data)
  46. self.action_id = self.get_value(action_data, "id")
  47. self.mode_type = self.get_value(action_data, "mode_type")
  48. # self.action_type = self.get_value(action_data, "execution_type", "程序1")
  49. self.action_name = self.get_value(action_data, "action_name", "")
  50. self.is_wait = self.get_value(action_data, "is_wait", False)
  51. self.point_name = self.get_value(action_data, "point_name", "A")
  52. self.is_move_device = self.get_value(action_data, "is_move_device", True)
  53. self.is_need_confirm = self.get_value(action_data, "is_need_confirm", False)
  54. self.image_index = self.get_value(action_data, "picture_index", 99)
  55. self.camera_height = self.get_value(action_data, "camera_height", 0)
  56. self.last_camera_height = 0
  57. self.camera_angle = float(self.get_value(action_data, "camera_angle", 0.0))
  58. self.af_times = self.get_value(action_data, "number_focus", 0)
  59. self.shoe_overturn = self.get_value(action_data, "shoe_upturn", False)
  60. # 焦段距离
  61. self.camera_focal_distance = self.get_value(action_data, "camera_focal_distance", 0)
  62. self.camera_configs = self.get_value(action_data, "camera_configs", None)
  63. self.is_photograph = self.get_value(action_data, "take_picture", True)
  64. self.turntable_position = float(
  65. self.get_value(action_data, "turntable_position", 0.0)
  66. )
  67. self.is_get_mcu_state = is_get_mcu_state
  68. self.turntable_angle = float(
  69. self.get_value(action_data, "turntable_angle", 0.0)
  70. )
  71. self.delay_time = self.get_value(action_data, "pre_delay", 0.0)
  72. self.after_delay_time = self.get_value(action_data, "after_delay", 0.0)
  73. self.is_led = self.get_value(action_data, "led_switch", False)
  74. self.last_photograph_time = None # 最近一次拍照时间
  75. self.goods_art_no = goods_art_no # 货号
  76. self.record_id = record_id # 货号
  77. self.set_other()
  78. self.error_info_text = "" # 错误提示信息
  79. self.last_move_time = None
  80. # self.setParent(parent)
  81. self.mcu = mcu
  82. # if is_show:
  83. # self.parent = parent
  84. # self.setupUi(self)
  85. # self.init()
  86. # self.show()
  87. def set_other(self):
  88. if self.mode_type == "其他配置":
  89. self.turntable_position = None
  90. self.turntable_angle = None
  91. self.delay_time = 0
  92. self.after_delay_time = 0
  93. self.is_led = False
  94. def get_value(self, data, key, default=None):
  95. if key not in data:
  96. data[key] = default
  97. print("取值模式==>获取到key:{}的值为:{}".format(key, data[key]))
  98. return default
  99. print("默认值模式==>获取到key:{}的值为:{}".format(key, data[key]))
  100. return data[key]
  101. def reset(self):
  102. self.set_state(state_value=0)
  103. self.error_info_text = "" # 错误提示信息
  104. def init(self):
  105. self.icon_dict = {
  106. 0: "resources/other_icon/0weikaishi.png",
  107. 1: "resources/other_icon/1jinxingzhong.png",
  108. 2: "resources/other_icon/2yijieshu.png",
  109. 99: "resources/other_icon/11yichang.png",
  110. }
  111. if self.is_wait:
  112. msg = "{}--等待".format(self.action_name)
  113. self.sendSocketMessage(msg=msg, device_status=0)
  114. else:
  115. msg = "{}".format(self.action_name)
  116. self.sendSocketMessage(msg=msg, device_status=2)
  117. tips_text = "程序:{},对焦:{}".format(1, 1)
  118. self.sendSocketMessage(msg=tips_text, device_status=2)
  119. self.set_state(state_value=0)
  120. # def next_step_clicked(self, *args, **kwargs):
  121. # self.windows.event.set()
  122. def set_state(self, state_value):
  123. self.state = state_value
  124. # icon = QPixmap(self.icon_dict[self.state])
  125. # icon = icon.scaled(
  126. # self.ui_icon.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation
  127. # )
  128. # self.ui_icon.setPixmap(icon)
  129. # if self.state == 0:
  130. # self.ui_retry.setText("")
  131. # self.ui_retry.setEnabled(False)
  132. # if self.state == 1:
  133. # self.ui_retry.setText("")
  134. # self.ui_retry.setEnabled(False)
  135. # if self.state == 2:
  136. # self.ui_retry.setText("单步")
  137. # self.ui_retry.setEnabled(True)
  138. # if self.state == 99:
  139. # self.ui_retry.setText("重试")
  140. # self.ui_retry.setEnabled(True)
  141. # self.ui_action_name.setToolTip(self.error_info_text)
  142. async def check_mcu_move_is_stop(self, re_check=False):
  143. self.error_info_text = ""
  144. # 发送基础数据信息
  145. # self.mcu.to_get_mcu_base_info()
  146. _s = time.time()
  147. last_num_1 = self.mcu.last_mcu_info_data["num"]
  148. await self.mcu.cleanAllReceiveData()
  149. while 1:
  150. print("\033[1;31m执行检查动作\033[0m", self.mcu.mcu_move_state)
  151. print("\033[1;31m执行检查动作\033[0m", self.mcu.action_state)
  152. if self.mcu.action_state != 1:
  153. # 外部终止,停止运行
  154. print("\033[1;31m执行结束\033[0m", "外部终止,停止运行")
  155. return False
  156. cr_time = time.time()
  157. print(cr_time - _s, cr_time, _s)
  158. if cr_time - _s > 8:
  159. self.error_info_text = "MCU检测运动未停止,自动退出"
  160. self.set_state(state_value=99) # 标记异常
  161. print("MCU检测运动未停止,自动退出")
  162. # self.sendSocketMessage(msg=self.error_info_text, device_status=-1)
  163. print("\033[1;31m执行结束\033[0m", "MCU检测运动未停止,自动退出")
  164. return False
  165. # return True
  166. # 存在时间间隙,导致误认为所有设备已完成运动
  167. if self.mcu.mcu_move_state == 2:
  168. print("\033[1;31m执行结束\033[0m", "导致误认为所有设备已完成运动")
  169. return True
  170. else:
  171. self.mcu.to_get_mcu_base_info()
  172. asyncio.create_task(self.mcu.send_all_cmd())
  173. # self.mcu.send_all_cmd()
  174. await asyncio.sleep(0.5)
  175. self.mcu.get_basic_info_mcu()
  176. # return True
  177. print("\033[1;31m执行结束\033[0m", self.mcu.action_state)
  178. # await asyncio.sleep(0.1)
  179. # self.mcu.to_get_mcu_base_info()
  180. async def _do_camera_check(self):
  181. """执行一次完整的状态查询检测,返回是否全部停止"""
  182. self.mcu.send_get_all_info_to_mcu()
  183. await asyncio.sleep(0.5)
  184. return all(
  185. value == 2
  186. for value in [
  187. self.mcu.state_camera_motor,
  188. self.mcu.state_camera_steering,
  189. self.mcu.state_turntable_steering,
  190. self.mcu.state_overturn_steering,
  191. ]
  192. )
  193. async def camera_check_mcu_move_is_stop(self, re_check=False):
  194. self.error_info_text = ""
  195. _s = time.time()
  196. check_times = 0
  197. await self.mcu.cleanAllReceiveData()
  198. while 1:
  199. if self.mcu.action_state != 1:
  200. return False
  201. # 发送获取设备状态消息
  202. if await self._do_camera_check():
  203. # 首次检测通过,追加一次确认检测,防止读到旧状态误判
  204. logger.info("拍照前运动检测首次通过,发起确认检测")
  205. if await self._do_camera_check():
  206. logger.info("拍照前运动检测状态[成功],确认通过,耗时%.1f秒", time.time() - _s)
  207. await asyncio.sleep(0.5)
  208. return True
  209. else:
  210. logger.warning("拍照前运动检测确认失败,继续等待")
  211. check_times += 1
  212. else:
  213. check_times += 1
  214. if check_times > 5:
  215. logger.info("拍照前运动检测状态[失败],耗时%.1f秒", time.time() - _s)
  216. return False
  217. await asyncio.sleep(0.2)
  218. async def run(self, total_len=5, *args):
  219. if total_len == 1:
  220. self.mode_type = "其他配置"
  221. self.set_other()
  222. print("1{} - is run".format(self.action_name))
  223. self.set_state(state_value=1)
  224. if settings.IS_TEST:
  225. await self.do_run()
  226. else:
  227. try:
  228. await self.do_run()
  229. except BaseException as e:
  230. traceback.print_exc()
  231. logger.info(f"p_item 错误 {e}")
  232. # self.sendSocketMessage(
  233. # msg="p_item 错误:{}".format(e), device_status=-1
  234. # )
  235. self.set_state(state_value=99)
  236. self.set_state(state_value=2)
  237. return True
  238. def run_only_mcu(self, *args):
  239. # ============连接MCU 处理步进电机与舵机等
  240. if settings.IS_MCU:
  241. if self.shoe_overturn:
  242. self.mcu.to_deal_device(device_name="overturn_steering")
  243. time.sleep(0.1)
  244. if self.camera_height is not None:
  245. self.mcu.to_device_move(
  246. device_name="camera_high_motor", value=self.camera_height
  247. )
  248. time.sleep(0.1)
  249. if self.camera_angle is not None:
  250. self.mcu.to_device_move(
  251. device_name="camera_steering", value=self.camera_angle
  252. )
  253. time.sleep(0.1)
  254. if self.turntable_position is not None:
  255. self.mcu.to_device_move(
  256. device_name="turntable_position_motor",
  257. value=self.turntable_position,
  258. )
  259. time.sleep(0.1)
  260. if self.turntable_angle is not None:
  261. self.mcu.to_device_move(
  262. device_name="turntable_steering", value=self.turntable_angle
  263. )
  264. time.sleep(0.1)
  265. if self.camera_focal_distance is not None:
  266. self.mcu.to_device_move(device_name="camera_zoom_motor", value=self.camera_focal_distance)
  267. loop = asyncio.get_event_loop()
  268. # self.mcu.send_all_cmd()
  269. loop.create_task(self.mcu.send_all_cmd())
  270. async def do_run(self, *args):
  271. await asyncio.sleep(0.001)
  272. # if not self.goods_art_no: # and self.action_name != "初始化位置"
  273. # return False
  274. start_time = time.time()
  275. current_time = time.time()
  276. self.mcu.is_get_mcu_state = self.is_get_mcu_state
  277. # ============连接MCU 处理步进电机与舵机等
  278. if self.is_move_device:
  279. if settings.IS_MCU:
  280. if self.mode_type != "其他配置" and await self.check_mcu_move_is_stop() is False:
  281. # MCU运动是否有停止检查,设定超时时间
  282. return
  283. print(
  284. "{} 检查停止时间1:{}".format(
  285. self.action_name, time.time() - start_time
  286. )
  287. )
  288. if self.is_led:
  289. self.mcu.to_deal_device(device_name="laser_position", value=1)
  290. else:
  291. self.mcu.to_deal_device(device_name="laser_position", value=0)
  292. if self.shoe_overturn:
  293. self.mcu.to_deal_device(device_name="overturn_steering")
  294. await asyncio.sleep(0.001)
  295. if self.camera_focal_distance is not None:
  296. # 移动距离
  297. self.mcu.to_device_move(device_name="camera_zoom_motor", value=self.camera_focal_distance)
  298. if self.camera_height is not None:
  299. if (current_time - self.last_move_time) > 110:
  300. if self.camera_height == 0:
  301. self.mcu.to_device_move(
  302. device_name="camera_high_motor", value=1
  303. )
  304. elif self.camera_height == 400:
  305. self.mcu.to_device_move(
  306. device_name="camera_high_motor", value=399
  307. )
  308. else:
  309. self.mcu.to_device_move(
  310. device_name="camera_high_motor", value=self.camera_height - 1
  311. )
  312. await asyncio.sleep(0.01)
  313. logger.info("设备延迟执行===>,%s", time.time())
  314. self.mcu.to_device_move(
  315. device_name="camera_high_motor", value=self.camera_height
  316. )
  317. self.last_camera_height = self.camera_height
  318. await asyncio.sleep(0.01)
  319. if self.camera_angle is not None:
  320. if self.turntable_position == -40:
  321. self.mcu.to_device_move(
  322. device_name="camera_steering", value=-39.9
  323. )
  324. logger.info("转盘位置首次运动===>,%s", -39.9)
  325. elif self.turntable_position == 40:
  326. self.mcu.to_device_move(
  327. device_name="camera_steering", value=39.9
  328. )
  329. logger.info("转盘位置首次运动===>,%s", 39.9)
  330. else:
  331. self.mcu.to_device_move(
  332. device_name="camera_steering", value=self.camera_angle - 0.1
  333. )
  334. logger.info("转盘位置首次运动===>,%s", self.camera_angle - 0.1)
  335. await asyncio.sleep(0.01)
  336. self.mcu.to_device_move(
  337. device_name="camera_steering", value=self.camera_angle
  338. )
  339. await asyncio.sleep(0.01)
  340. if self.turntable_position is not None:
  341. if self.turntable_position == 0:
  342. self.mcu.to_device_move(
  343. device_name="turntable_position_motor", value=1
  344. )
  345. logger.info("转盘位置首次运动===>,%s", 1)
  346. elif self.turntable_position == 800:
  347. self.mcu.to_device_move(
  348. device_name="turntable_position_motor", value=799
  349. )
  350. logger.info("转盘位置首次运动===>,%s", 799)
  351. else:
  352. self.mcu.to_device_move(
  353. device_name="turntable_position_motor", value=self.turntable_position - 1
  354. )
  355. logger.info("转盘位置首次运动===>,%s", self.turntable_position - 1)
  356. await asyncio.sleep(0.01)
  357. self.mcu.to_device_move(
  358. device_name="turntable_position_motor",
  359. value=self.turntable_position,
  360. )
  361. logger.info("转盘位置2次运动===>,%s", self.turntable_position)
  362. await asyncio.sleep(0.01)
  363. if self.turntable_angle is not None:
  364. self.mcu.to_device_move(
  365. device_name="turntable_steering", value=self.turntable_angle
  366. )
  367. await asyncio.sleep(0.01)
  368. # MCU运动是否有停止检查,设定超时时间
  369. # self.mcu.send_all_cmd()
  370. asyncio.create_task(self.mcu.send_all_cmd())
  371. if self.mode_type != "其他配置":
  372. await asyncio.sleep(0.2)
  373. print("二次检查")
  374. if await self.check_mcu_move_is_stop(re_check=True) is False:
  375. print("MCU检测运动未停止,自动退出, 提前退出")
  376. return
  377. # logger.info("设备最后一次执行时间===>,%s",current_time)
  378. self.mcu.is_get_mcu_state = True
  379. if self.delay_time:
  380. await asyncio.sleep(self.delay_time)
  381. if self.is_photograph:
  382. # print("photograph==================")
  383. self.mcu.to_deal_device(device_name="buzzer", times=1)
  384. # 用于临时拍照计数
  385. # 配置设置是否运动设备,不运动直接去拍照
  386. if self.is_move_device:
  387. if not await self.camera_check_mcu_move_is_stop(re_check=True):
  388. logger.warning("拍照前运动检测失败===>,等待0.5秒后再检测一次")
  389. await asyncio.sleep(0.5)
  390. if not await self.camera_check_mcu_move_is_stop(re_check=True):
  391. logger.warning("拍照前运动检测二次失败===>,强制拍摄")
  392. is_af = True if self.af_times > 0 else False
  393. if self.smart_shooter != None:
  394. # 拍照
  395. print("smart shooter 拍照")
  396. record_id = self.record_id
  397. goods_art_no = self.goods_art_no
  398. if record_id == -1:
  399. goods_art_no = ""
  400. camera_configs = settings.getSysConfigs(
  401. "camera_configs",
  402. "iso_config",
  403. None,
  404. )
  405. print(" camera_configs p_item", camera_configs)
  406. CameraKey = camera_configs[self.point_name].get("CameraKey", None)
  407. # print("smart shooter CameraShooter", record_id, goods_art_no, CameraKey)
  408. await self.smart_shooter.CameraShooter(
  409. msg_type="run_mcu",
  410. goods_art_no=goods_art_no,
  411. id=record_id,
  412. is_af=is_af,
  413. CameraKey=CameraKey,
  414. camera_configs=self.camera_configs,
  415. )
  416. print("smart shooter CameraShooter end")
  417. else:
  418. # 指定自动对焦
  419. self.capture_one.photograph(is_af=is_af)
  420. self.last_photograph_time = time.time() # 记录最近一次拍照时间
  421. # print("{} 拍照时间:{}".format(self.action_name, time.time() - start_time))
  422. print("{}-{}已完成".format(self.mode_type, self.action_name))
  423. if self.after_delay_time:
  424. print("拍照后延时:{}".format(self.after_delay_time))
  425. await asyncio.sleep(self.after_delay_time)
  426. return True
  427. async def RunSmartShooter(self, goods_art_no, record_id):
  428. await asyncio.gather(
  429. self.smart_shooter.CameraShooter(
  430. msg_type="run_mcu",
  431. goods_art_no=goods_art_no,
  432. id=record_id,
  433. ),
  434. )
  435. def digicam_take_picture(self):
  436. self.mcu.to_deal_device(device_name="buzzer", times=1)
  437. # 用于临时拍照计数
  438. is_af = True
  439. self.capture_one.photograph(is_af=is_af)
  440. self.last_photograph_time = time.time() # 记录最近一次拍照时间
  441. print("仅拍照执行完成")
  442. def rephotograph_one_pic(self, *args):
  443. """
  444. 1、获取最近一张照片
  445. 2、判断拍照时间距离当前节点的最近拍照时间是否小于3秒
  446. 3、删除该照片
  447. 4、重新触发进行拍照,并更新最近拍照时间
  448. """
  449. if (
  450. settings.getSysConfigs("other_configs", "running_mode", "普通模式")
  451. == "普通模式"
  452. ):
  453. return
  454. print("-----100-2--self", self)
  455. # 需要删除最近一张照片
  456. # if self.last_photograph_time is not None:
  457. # record = self.windows.image_process_data.photo_todo_list
  458. # if record:
  459. # last_record = record[-1]
  460. # if self.goods_art_no == last_record["goods_art_no"]:
  461. # if last_record["is_photo"]:
  462. # photo_create_time_formate = last_record[
  463. # "photo_create_time_formate"
  464. # ]
  465. # image_path = last_record["image_path"]
  466. # print(
  467. # "photo_create_time_formate,self.last_photograph_time",
  468. # photo_create_time_formate,
  469. # self.last_photograph_time,
  470. # )
  471. # # 如果照片的时间大于触发时间,且小于3秒,则认定是当前触发
  472. # if (
  473. # self.last_photograph_time
  474. # < photo_create_time_formate
  475. # < self.last_photograph_time
  476. # + settings.PHOTO_TRANSFER_TIME_INTERVAL
  477. # ):
  478. # if os.path.exists(image_path):
  479. # os.remove(image_path)
  480. # self.windows.add_goods_images_count(
  481. # self.goods_art_no, flag=False
  482. # )
  483. # if (
  484. # self.windows.image_process_data.goods_art_no_times_record
  485. # ):
  486. # goods_art_no = self.windows.image_process_data.goods_art_no_times_record[
  487. # 0
  488. # ][
  489. # "goods_art_no"
  490. # ]
  491. # if goods_art_no == self.goods_art_no:
  492. # self.windows.image_process_data.goods_art_no_times_record[
  493. # 0
  494. # ][
  495. # "number"
  496. # ] -= 1
  497. # self.program_refresh_photo_list_sign.emit()
  498. # if self.is_photograph:
  499. # # 重新拍照
  500. # self.last_photograph_time = time.time() # 记录最近一次拍照时间
  501. # print("last_photograph_time:", self.last_photograph_time)
  502. # print("photograph==================")
  503. # self.mcu.to_deal_device(device_name="buzzer", times=1)
  504. # # 用于临时拍照计数
  505. # self.windows.add_goods_images_count(self.goods_art_no)
  506. # if self.af_times > 0:
  507. # self.windows.capture_one.photograph(is_af=True)
  508. # else:
  509. # self.windows.capture_one.photograph(is_af=False)
  510. def do_retry(self, *args, **kwargs):
  511. """
  512. 重试操作,注意事项:
  513. 1、需要根据当前系统的角度位置,重新进行返回并拍摄
  514. :param args:
  515. :param kwargs:
  516. :return:
  517. """
  518. # self.program_sign.emit({})
  519. # print("do_retry")
  520. self.reset()
  521. self.mcu.action_state = 1
  522. self.run()
  523. self.mcu.action_state = 2
  524. def get_photo_node_name_and_sound(self, photo_take_time):
  525. data = {
  526. "action_name": self.action_name,
  527. "flag": False,
  528. "is_sound_play": False,
  529. }
  530. if self.state == 0:
  531. return data
  532. if self.last_photograph_time is None:
  533. return data
  534. # if (
  535. # self.last_photograph_time
  536. # < photo_take_time
  537. # < self.last_photograph_time + settings.PHOTO_TRANSFER_TIME_INTERVAL
  538. # ):
  539. # # 认定为当节点拍摄
  540. # # 如果为待用户确认则播放声音
  541. # data["flag"] = True
  542. # if settings.RUNNING_MODE == "待用户确认模式":
  543. # _f = False
  544. # if settings.RUNNING_MODE_DETAIL == "所有节点待确认":
  545. # _f = True
  546. # else:
  547. # print("self.is_need_confirm", self.is_need_confirm)
  548. # if self.is_need_confirm:
  549. # _f = True
  550. # else:
  551. # _f = False
  552. # if _f:
  553. # data["is_sound_play"] = True
  554. # print("========is_sound_play===========")
  555. # self.windows.playsound.tips_type = "photo_confirm"
  556. # self.windows.playsound.start()
  557. # return data
  558. return data