From: Robin Krens Date: Tue, 13 Feb 2024 14:55:00 +0000 (+0100) Subject: RAFlasher.py: logic to check if connection already established X-Git-Tag: v0.0.1~36 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=83d8b08d4f86f9b08fb85d88ae49e91e8bebec36;p=renesas-ra-flasher RAFlasher.py: logic to check if connection already established --- diff --git a/src/RAConnect.py b/src/RAConnect.py index 2241275..136da14 100644 --- a/src/RAConnect.py +++ b/src/RAConnect.py @@ -18,6 +18,11 @@ class RAConnect: self.tx_ep = None self.find_device() + def reset(self): + if self.dev is None: + print(f'Device not connected') + self.dev.reset() + def find_device(self): self.dev = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id) if self.dev is None: diff --git a/src/RAFlasher.py b/src/RAFlasher.py index d6f53d5..7c534ab 100644 --- a/src/RAFlasher.py +++ b/src/RAFlasher.py @@ -12,6 +12,18 @@ def int_to_hex_list(num): hex_list = [f'0x{hex_string[c:c+2]}' for c in range(0, 8, 2)] return hex_list +def inquire_connection(dev): + packed = pack_pkt(INQ_CMD, "") + dev.send_data(packed) + info = dev.recv_data(7) + print(info) + if info == bytearray(b'\x00') or info == bytearray(b''): + return False + msg = unpack_pkt(info) + print("Connection already established") + print(msg) + return True + def get_dev_info(dev): packed = pack_pkt(SIG_CMD, "") @@ -115,8 +127,10 @@ def main(): print('read command') elif args.command == "info": dev = RAConnect(vendor_id=0x045B, product_id=0x0261) - dev.establish_connection() - dev.confirm_connection() + status_con = inquire_connection(dev) + if not status_con: + #dev.establish_connection() + dev.confirm_connection() get_dev_info(dev) else: parser.print_help()