diff --git a/MPPT/read.py b/MPPT/read.py index 63af67d..f2a2887 100644 --- a/MPPT/read.py +++ b/MPPT/read.py @@ -68,6 +68,7 @@ def read_vedirect(port='/dev/ttyAMA4', baudrate=19200, timeout=20, max_attempts= # Initialize data dictionary and tracking variables data = {} start_time = time.time() + checksum_found = False while time.time() - start_time < timeout: line = ser.readline().decode('utf-8', errors='ignore').strip() @@ -82,18 +83,23 @@ def read_vedirect(port='/dev/ttyAMA4', baudrate=19200, timeout=20, max_attempts= print(f"{key}: {value}") else: print(f"Info: {line}") + # Check if this is the checksum line (end of data block) + if line.lower().startswith('checksum') or 'checksum' in line.lower(): + checksum_found = True # Check if we have a complete data block - if 'Checksum' in data: + if checksum_found: # Check if we have all required keys missing_keys = [key for key in required_keys if key not in data] if not missing_keys: + print("✓ Complete data block received!") ser.close() return data else: print(f"Incomplete data, missing: {', '.join(missing_keys)}") - # Clear data and continue reading + # Reset and continue reading data = {} + checksum_found = False # Timeout occurred print(f"Timeout on attempt {attempt+1}: Could not get complete data")