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