Skip to content

Instantly share code, notes, and snippets.

@yptheangel
Created August 19, 2020 03:49
Show Gist options
  • Save yptheangel/fcd62ad59a569ace75eb07025b8e9c4f to your computer and use it in GitHub Desktop.
Save yptheangel/fcd62ad59a569ace75eb07025b8e9c4f to your computer and use it in GitHub Desktop.
pyserial read write example
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()
@paulinaacostac
Copy link

Hi, this just print empty strings, b' '

@ciscojmg
Copy link

ciscojmg commented Apr 8, 2022

Gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment