From bf35064f6e45175cc44569fadbd301d02a08d3a1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 27 Feb 2025 12:37:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96em=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=87=87=E9=9B=86=E6=95=B0=E6=8D=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/em/cd.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/em/cd.py b/apps/em/cd.py index 5b10f12f..44779f1e 100644 --- a/apps/em/cd.py +++ b/apps/em/cd.py @@ -12,9 +12,15 @@ def get_tyy_data(*args): resp = sc.recv(1024) if len(resp) < 8: raise ParseError("设备未启动") - json_data = resp[5:-4] - json_str = json_data.decode('utf-8') - return json.loads(json_str) + try: + json_data = resp[5:-4] + json_str = json_data.decode('utf-8') + res = json.loads(json_str) + except Exception: + raise + finally: + sc.close() + return res if __name__ == '__main__': print(get_tyy_data()) \ No newline at end of file