python3向Nextion显示器发送串行数据

python3向Nextion显示器发送串行数据,python,python-3.x,serial-port,pyserial,Python,Python 3.x,Serial Port,Pyserial,我正试图通过Python3脚本控制Nextion显示 使用Windows终端,我能够控制它 例如,要更改控件的文本,我发送以下命令: import serial s = serial.Serial(port='COM5',baudrate=9600) escape='\xff'.encode('iso-8859-1') test=b't0.txt="test"' s.write(test) s.write(escape) s.write(escape) s.write(escape) s.clo

我正试图通过Python3脚本控制Nextion显示

使用Windows终端,我能够控制它

例如,要更改控件的文本,我发送以下命令:

import serial
s = serial.Serial(port='COM5',baudrate=9600)
escape='\xff'.encode('iso-8859-1')
test=b't0.txt="test"'
s.write(test)
s.write(escape)
s.write(escape)
s.write(escape)
s.close()
t0.txt=“test”后跟通过“send hex”的3次0xFF

我使用PySerial的Python3脚本如下所示:

import serial
s = serial.Serial(port='COM5',baudrate=9600)
escape='\xff'.encode('iso-8859-1')
test=b't0.txt="test"'
s.write(test)
s.write(escape)
s.write(escape)
s.write(escape)
s.close()
但它不起作用

有什么想法吗


非常感谢

您可以尝试以下代码:

import serial
import time
import struct

ser = serial.Serial("/dev/ttyAMA0")
print ser
time.sleep(1)
i=1
k=struct.pack('B', 0xff)
while True:
    ser.write(b"n0.val=")
    ser.write(str(i))
    ser.write(k)
    ser.write(k)
    ser.write(k)
    print " NEXT"
    time.sleep(1)
    i=i+1

从gpiopins上raspberry pi3上的nextion EEPROM读取字节

#import time
import serial

ser = serial.Serial(
    port='/dev/ttyS0',
    baudrate =9600,           
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1)
commandToSend = b'rept 0,32\xff\xff\xff' #read 32 bytes of hex data from EEPROM to UART, start address is 0
while True:
    ser.write(commandToSend)
    #time.sleep(0.5)
    x=ser.readline()    
    print (x)