我正在尝试编写一个名为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
答案 0 :(得分:6)
答案 1 :(得分:6)
如果端口已经打开,您可以调用setBaudrate
进行一些检查并重新配置该端口。
ser.setBaudrate(115200)