Skip to content

Commit ce8df42

Browse files
committed
utils/sync_ports.py: Add sync_ports.py for local test.
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
1 parent da2d364 commit ce8df42

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

utils/sync_ports.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import serial
2+
import sys
3+
4+
JOB_START_TOKEN = "[@START_TEST@]"
5+
JOB_START_TOKEN_RESPONSE = JOB_START_TOKEN
6+
7+
def send_start_token(port_list, baudrate=115200, timeout=2):
8+
if not port_list:
9+
print("No ports provided.")
10+
return 1
11+
12+
print("\n\nINFO: Sending job start tokens ...")
13+
return_code = 0
14+
15+
for port in port_list:
16+
try:
17+
ser = serial.Serial(port, baudrate=baudrate, timeout=timeout)
18+
ser.reset_input_buffer()
19+
ser.write((JOB_START_TOKEN + "\n").encode('utf-8'))
20+
response = ser.readline().decode().strip()
21+
print(f"INFO: [{port}] response : {response}")
22+
count = 0
23+
24+
while (JOB_START_TOKEN_RESPONSE not in response) and (count < 300):
25+
response = ser.readline().decode().strip()
26+
print(f"INFO: [{port}] response : {response}")
27+
count += 1
28+
29+
if JOB_START_TOKEN_RESPONSE not in response:
30+
print(f"ERROR: Did not get proper response from job after sending job start token to port {port}. Expected was {JOB_START_TOKEN_RESPONSE}, received '{response}' !\n")
31+
return_code = 1
32+
ser.close()
33+
break
34+
ser.close()
35+
except Exception as e:
36+
print(f"ERROR: Exception for port {port}: {e}")
37+
return_code = 1
38+
break
39+
40+
return return_code
41+
42+
if __name__ == "__main__":
43+
"""
44+
Example usage:
45+
python sync_ports.py /dev/ttyUSB0 /dev/ttyUSB1
46+
This will send the JOB_START_TOKEN to each listed serial port and wait for the response.
47+
"""
48+
ports = sys.argv[1:]
49+
if not ports:
50+
print("Usage: python sync_ports.py <port1> <port2> ...")
51+
sys.exit(1)
52+
ret = send_start_token(ports)
53+
sys.exit(ret)

0 commit comments

Comments
 (0)