Created
January 16, 2021 21:53
-
-
Save rsaxvc/36302d9ab8eb60ca1457404f45c5ffe5 to your computer and use it in GitHub Desktop.
scan serial ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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