How to send single character ASCII data to serial port using python

I looked at pyserial, but I cannot figure out how to do this. Do I need to send only one at a time? Please, help?

+3
source share
2 answers

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
source
0
source

Source: https://habr.com/ru/post/1770664/


All Articles