[英]Read from nextion touchdisplay via python in Win10 over USB/TTL converter
today I tried desperately to read values from a nextiondisplay in my python code. 今天,我拼命尝试从python代码中的nextiondisplay读取值。 Writing to it works, but i simply can't manage to get python to read from it. 写它的作品,但我根本无法设法从它读取python。 My code looks like this: 我的代码如下所示:
def ser_escape():
escape='\xff'.encode('iso-8859-1')
ser.write(escape)
ser.write(escape)
ser.write(escape)
import serial
import pynextion
EndCom= "\xff\xff\xff"
ser = serial.Serial(port='COM4',baudrate=9600)
test=b't0.txt="MyText"'
ser.write(test)
ser_escape()
ser.flush
ser_escape()
ser.flush
ser.write(b'get t0.txt')
print (ser.read())
ser_escape()
ser.close()
The output is just: b'\\x1a'
Which isn't anything close to the behaviour expected - at least not from me. 输出为: b'\\x1a'
这与预期的行为没有任何关系-至少不是我的行为。 Relating to this document: https://www.itead.cc/wiki/Nextion_Instruction_Set#get:_Get_variable.2Fconstant_value_with_format I should be able to use "get "variable""
to receive the Information stored there. 关于本文档: https : //www.itead.cc/wiki/Nextion_Instruction_Set#get : _Get_variable.2Fconstant_value_with_format我应该能够使用"get "variable""
来接收存储在此处的信息。
I'd be happy if some1 could help me out here. 如果有人可以在这里帮助我,我会很高兴。
Solved it on my own: For "get Start.currentPage.txt" you could insert any call for a variable you want, after that i just cut the part of interest from the string to keep, i dont need the begin and end of message symbols. 我自己解决了此问题:对于“ get Start.currentPage.txt”,您可以插入任何您想要的变量的调用,之后,我只是从字符串中保留了感兴趣的部分,所以我不需要消息的开头和结尾符号。
import time
from pynextion import PySerialNex
nexSerial=PySerialNex("COM4")
def getActPageName(nexSerial):
nexSerial.write("get Start.currentPage.txt")
time.sleep(0.1)
Var=str(nexSerial.read_all())
Var=Var[Var.find('p')+1:Var.find('\\')]
return Var
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.