How do I send single character ASCII data to a serial port with python


Question

I'v looked at pyserial but I can't seem to figure out how to do it. I only need to send one at a time? Please help?

1
3
10/21/2010 5:42:13 AM

Using pySerial:

Python 2.x:

import serial
byte = 42
out = serial.Serial("/dev/ttyS0")  # "COM1" on Windows
out.write(chr(byte))

Python 3.x:

import serial
byte = 42
out = serial.Serial("/dev/ttyS0")  # "COM1" on Windows
out.write(bytes(byte))
8
10/21/2010 6:22:57 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon