如何使用python将单字符ASCII数据发送到串行端口

bob*_*ueb 3 python arduino

我看了pyserial,但我似乎无法弄清楚如何做到这一点.我只需要一次发送一个?请帮忙?

Fré*_*idi 8

使用pySerial:

Python 2.x:

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

Python 3.x:

import serial
byte = 42
out = serial.Serial("/dev/ttyS0")  # "COM1" on Windows
out.write(bytes(byte))
Run Code Online (Sandbox Code Playgroud)