User:Uli/Serial port latency testing

From eLinux.org
< User:Uli
Revision as of 01:32, 15 February 2018 by Uli (talk | contribs) (Created page with "This describes how to determine the receive latency of a serial port, using a loopback cable. It is assumed that the serial port to be tested is connected through a USB-to-ser...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This describes how to determine the receive latency of a serial port, using a loopback cable. It is assumed that the serial port to be tested is connected through a USB-to-serial converter to a USB port on the same system. The receiving serial port is called /dev/ttySC1.

Make sure the python-serial package is installed. Run this Python script:

#!/usr/bin/python
import time
import serial
ser_in = serial.Serial('/dev/ttySC1', 921600)
ser_out = serial.Serial('/dev/ttyUSB0', 921600)

ser_out.write('a')
t1 = time.time()
x = ser_in.read()
t2 = time.time()
print x,(t2-t1)*1000000

It will output the time passing between sending of a character and it being available from the receiving character device, in microseconds.