diff --git a/src/openmv/transport.py b/src/openmv/transport.py index 91e5a7e..c0121f5 100644 --- a/src/openmv/transport.py +++ b/src/openmv/transport.py @@ -227,13 +227,6 @@ def recv_packet(self, poll_events=False): start_time = time.time() continue # Continue collecting fragments - # Either last fragment or non-fragmented packet - if fragments: - # This is the last fragment - combine all - fragments.extend(packet['payload']) - packet['payload'] = bytes(fragments) - packet['length'] = len(fragments) - # Handle NAK flags if packet['flags'] & Flags.NAK: # Raise specific exception for all NAK statuses except BUSY @@ -248,6 +241,13 @@ def recv_packet(self, poll_events=False): raise OMVException(f"Command failed with status: {Status(status).name}") return False + # Either last fragment or non-fragmented packet + if fragments: + # This is the last fragment - combine all + fragments.extend(packet['payload']) + packet['payload'] = bytes(fragments) + packet['length'] = len(fragments) + # Return payload or True for ACK return True if not packet['length'] else bytes(packet['payload'])