我正在尝试为名为 uLCD32-pt 的 LCD 设备编写脚本,问题是您需要以 9600 的波特率连接到它,为了获得更高的波特率,您必须连接到它,发送更改波特率命令,然后以新设置的波特率发送新命令。我的液晶显示器在绘制像素时变得非常慢,我知道这是因为波特率,所以在连接到设备后有什么方法可以改变波特率吗?到目前为止,这是我的代码?
import serial
import time
#Connect to uLCD32-pt with autobaud
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
timeout=1,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.write("U")
while(True):
#15 x white pixels
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0001)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#1
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0002)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#2
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0003)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#3
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0004)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#4
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0005)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#5
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0006)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#6
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0007)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#7
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0008)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#8
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0009)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#9
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000A)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#10
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000B)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#11
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000C)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#12
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000D)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#13
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000E)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#14
ser.write(chr(0x0050)+chr(0x0000)+chr(0x000F)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#15
ser.write(chr(0x0050)+chr(0x0000)+chr(0x0010)+chr(0x0000)+chr(0x000A)+chr(0x00FF)+chr(0x00FF))#16
最佳答案
在 documentation 中,波特率属性的描述说:
所以我希望这条线可以工作:
ser.baudrate = 115200
关于python - 连接到设备时更改 pySerial 中的波特率?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9271777/