0

today I tried desperately to read values from a nextiondisplay in my python code. Writing to it works, but i simply can't manage to get python to read from it. 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. 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.

I'd be happy if some1 could help me out here.

1 Answers1

0

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.

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