This commit is contained in:
root
2025-05-26 14:59:18 +02:00
parent 6d997ff550
commit 5d4f7225b0

View File

@@ -68,6 +68,7 @@ def read_vedirect(port='/dev/ttyAMA4', baudrate=19200, timeout=20, max_attempts=
# Initialize data dictionary and tracking variables # Initialize data dictionary and tracking variables
data = {} data = {}
start_time = time.time() start_time = time.time()
checksum_found = False
while time.time() - start_time < timeout: while time.time() - start_time < timeout:
line = ser.readline().decode('utf-8', errors='ignore').strip() 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}") print(f"{key}: {value}")
else: else:
print(f"Info: {line}") 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 # Check if we have a complete data block
if 'Checksum' in data: if checksum_found:
# Check if we have all required keys # Check if we have all required keys
missing_keys = [key for key in required_keys if key not in data] missing_keys = [key for key in required_keys if key not in data]
if not missing_keys: if not missing_keys:
print("✓ Complete data block received!")
ser.close() ser.close()
return data return data
else: else:
print(f"Incomplete data, missing: {', '.join(missing_keys)}") print(f"Incomplete data, missing: {', '.join(missing_keys)}")
# Clear data and continue reading # Reset and continue reading
data = {} data = {}
checksum_found = False
# Timeout occurred # Timeout occurred
print(f"Timeout on attempt {attempt+1}: Could not get complete data") print(f"Timeout on attempt {attempt+1}: Could not get complete data")