Skip to content

Instantly share code, notes, and snippets.

@rsaxvc
Created January 16, 2021 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsaxvc/36302d9ab8eb60ca1457404f45c5ffe5 to your computer and use it in GitHub Desktop.
Save rsaxvc/36302d9ab8eb60ca1457404f45c5ffe5 to your computer and use it in GitHub Desktop.
scan serial ports
#Scan a serial port at different baud rates looking for a human-readable terminal
#By: RSAXVC
import serial
#List of possible baud rates to scan
bauds = [ 110, 150, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600]
#Path to POSIX port or Windows COM#
port = '/dev/ttyUSB0'
#Device query
query = b'\n\n*IDN?\n' #Ex: GW Instek GPD-3303S
for baud in bauds:
ser = serial.Serial(port, timeout=.25, baudrate=baud, bytesize=8, parity='N', stopbits=1) # open serial port
ser.write(query)
print baud,":",
while True:
line = ser.readline()
if not line:
print ""
break
print line
ser.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment