This commit is contained in:
PaulVua
2025-03-18 11:50:39 +01:00
parent e674b21eaa
commit 1fd5a3e75c

View File

@@ -49,6 +49,9 @@ config = load_config(config_file)
# Access the shared variables
baudrate = config.get('SaraR4_baudrate', 115200)
try:
ser = serial.Serial(
port=port, #USB0 or ttyS0
baudrate=baudrate, #115200 ou 9600
@@ -75,25 +78,33 @@ ser.write((command + '\r').encode('utf-8'))
#ser.write(b'AT+CMUX=?')
try:
# Read lines until a timeout occurs
response_lines = []
while True:
line = ser.readline().decode('utf-8').strip()
if not line:
break # Break the loop if an empty line is encountered
start_time = time.time()
while (time.time() - start_time) < timeout:
line = ser.readline().decode('utf-8', errors='ignore').strip()
if line:
response_lines.append(line)
# Check if we received any data
if not response_lines:
print(f"ERROR: No response received from {port} after sending command: {command}")
sys.exit(1)
# Print the response
for line in response_lines:
print(line)
except serial.SerialException as e:
print(f"Error: {e}")
print(f"ERROR: Serial communication error: {e}")
sys.exit(1)
except Exception as e:
print(f"ERROR: Unexpected error: {e}")
sys.exit(1)
finally:
if ser.is_open:
# Close the serial port if it's open
if 'ser' in locals() and ser.is_open:
ser.close()
#print("Serial closed")