Skip to content

Instantly share code, notes, and snippets.

@nos486
Created April 27, 2018 09:39
Show Gist options
  • Save nos486/4088fba76efcddef2dc340f25f9593a6 to your computer and use it in GitHub Desktop.
Save nos486/4088fba76efcddef2dc340f25f9593a6 to your computer and use it in GitHub Desktop.
import serial
import serial.tools.list_ports
def getSerialPorts():
ports = list(serial.tools.list_ports.comports())
for p in ports:
print(p)
def serialRead(serial_url, baudrate, timeout, bytesize, stopbits, parity="N", xonxoff=0, rtscts=0):
s = serial.Serial(serial_url, baudrate, timeout, bytesize, parity, stopbits, xonxoff, rtscts)
for char in s.read():
print(char)
pass
pass
if __name__ == '__main__':
serial_url = "/dev/cu.wchusbserial1410"
baudrate = 9600
timeout = None
bytesize = 8
stopbits = 1
while True:
serialRead(serial_url, baudrate, timeout, bytesize, stopbits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment