Created
August 19, 2020 03:49
-
-
Save yptheangel/fcd62ad59a569ace75eb07025b8e9c4f to your computer and use it in GitHub Desktop.
pyserial read write example
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 as port_list | |
ports = list(port_list.comports()) | |
print(ports[0].device) | |
port = ports[0].device | |
baudrate = 9600 | |
serialPort = serial.Serial(port=port, baudrate=baudrate, | |
bytesize=8, timeout=1, stopbits=serial.STOPBITS_ONE) | |
serialString = "" | |
# serialPort.write(bytes.fromhex("A551F6")) | |
serialPort.write(bytes.fromhex("A555FA")) | |
while True: | |
try: | |
# serialPort.reset_input_buffer() | |
# serialPort.reset_output_buffer() | |
# serialString = serialPort.read(10).hex() | |
serialString = serialPort.read() | |
print(serialString) | |
except KeyboardInterrupt: | |
break | |
serialPort.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, this just print empty strings, b' '