Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tools/flaskIfc/serial_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@

def send_serial_command(port, baudrate, command):
try:
# Open the serial port with 1 second timeout
ser = serial.Serial(port, baudrate, timeout=60)
ser = serial.Serial(port, baudrate)

ser.write(command.encode()) # Encode command to bytes
ser.write('\n'.encode()) # Encode command to bytes
ser.write((command + '\n').encode()) # Send command with newline

# Wait to read the serial port
data = '\0'
while True:
try:
line = ser.readline()
if line: # Check if line is not empty
data += line.decode('utf-8') # Keep the line as-is with newline
read_next_line = line.decode('utf-8')
if ("run-platform-done" in read_next_line) or ("@agilex7_dk_si_agf014ea" in read_next_line):
break
data += read_next_line # Keep the line as-is with newline
else:
break # Exit loop if no data is received
except serial.SerialException as e:
Expand All @@ -25,7 +26,7 @@ def send_serial_command(port, baudrate, command):
ser.close()
return ("Program interrupted by user")
ser.close()
print (data)
print(data)
return data

except serial.SerialException as e:
Expand Down