From 89a1270c02c2654495d7f78b7db583b49280ac62 Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 10 Sep 2024 11:47:51 +0800 Subject: [PATCH] driver: send cmd err msg to a pyqt sig --- pykirdy/driver/kirdy.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pykirdy/driver/kirdy.py b/pykirdy/driver/kirdy.py index 876f5ca..860e14b 100644 --- a/pykirdy/driver/kirdy.py +++ b/pykirdy/driver/kirdy.py @@ -642,6 +642,7 @@ class Kirdy: # PyQt Signal self._report_sig = None # Dict self._connected_sig = None # Bool + self._err_msg_sig = None # Str self.connected_event = None @@ -662,6 +663,12 @@ class Kirdy: """ self._connected_sig = sig + def set_err_msg_sig(self, sig): + """ + Emit a error message to a PyQt Signal(str) when a cmd fails to execute + """ + self._err_msg_sig = sig + def start_session(self, host='192.168.1.128', port=1337): """ Start Kirdy Connection Session. @@ -900,6 +907,10 @@ class Kirdy: elif msg["msg_type"] == msg_type: if sig is not None: sig.emit(msg) + else: + logging.warn(f"Commands fail to execute. {msg['msg_type']}:{msg['msg']}") + if self._err_msg_sig is not None and msg['msg'] is not None: + self._err_msg_sig.emit(msg['msg']) return msg async def _send_raw_cmd(self, cmd, msg_type="Acknowledge", sig=None):