UsbSerial/integration/validate_serial_tx.py

25 wiersze
342 B
Python
Czysty Zwykły widok Historia

2019-02-23 22:45:56 +00:00
import serial
import sys
import os
2019-02-23 22:49:26 +00:00
port = sys.argv[0]
2019-02-23 22:45:56 +00:00
size = sys.argv[1]
speed = sys.argv[2]
2019-02-23 22:49:26 +00:00
comm = serial.Serial(port, int(speed))
2019-02-23 22:45:56 +00:00
2019-02-23 22:49:26 +00:00
data_tx = os.urandom(size)
comm.write(data_tx)
data_rx = comm.read(size)
if data_tx == data_rx:
print("Success: Data was transmitted correctly")
else:
print("Error: Data was not transmitted")
2019-02-23 22:45:56 +00:00