Created
April 27, 2018 09:39
-
-
Save nos486/4088fba76efcddef2dc340f25f9593a6 to your computer and use it in GitHub Desktop.
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
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