Start a new topic

New Event OnChange

I have a scenario where the host sends a value/string.

I have to visualize this value/string in text objects on more then one display page, say 5.

The only possibility to solve this is to send the value/string 5 times from the host to the assigned display text objects. That is crucial and sub optimal.


Is there any possibility that Itead provide an OnChange event for variables or text objects?

With this I could send the value/string just 1 time to the variable or text object and could distribute the value/text to the other objects using the OnChange event.


Perhaps there are other possibilities to solve the described problem?


Best Regards

Ulrich


So  Short answers


1) Components on Nextion are records and not objects

    - so "OnChange" event is not really applicable.


2) Pages not the current page are not in Memory

   - In order to have such a big HMI run, pages are dumped when page changes.

   - exception: if a component is global then .val or .txt is stored, but nothing else.

   - so sending values to a non global destination is simply a "wasted" move.


You need a different approach, in field and record style thinking.


1) Global Variable on first page  say page0.va0.txt

2) Send your string from MCU to this page0.va0.txt

3) In each page postinitalize event t0.txt=page0.va0.txt to display on loading page

4) track current page in MCU using either the sendme command or get dp

5) knowing the current page, update the single t0 of current page that needs updating.

Thank you Patrick for clarification,
I will track current page to decide to which text objekt I have to send from MCU.

 

Still a slightly different approach to further reduce communication from host MCU to Nextion:


1) Always and only send your string from MCU to global var, i.e.. page0.va0.txt

2) On each page, place a timer with the desired refresh rate, i.e. 200ms

3) In the timer event, set  

if(t0.txt!=page0.va0.txt)

{

    t0.txt=page0.va0.txt

}


Thank you Thierry!
I think your approach is the best solution.

 

Again just tossing this out there for thought

 - something considered as "easier" to implement with less effort

   does not necessarily equate to "best"


Nextion can only have 6 timers max

  - every scrollingtext also uses a timer

As the project complexity increases and you build your HMI

  you will have many things going on, more and more needing updates

  - you will re-evaluate your remaining resources

  - you may find that being direct (changing as changes occurs)

    may consume far less resources than the timer trigger


Thierry's code snippet does not reduce communications from MCU to Nextion

but he has brought out a good point.  If you have resources to shadow

the Nextion side variable with a last sent versus a current value and only

send across the serial when this has changed - it is a good resource saver

Login or Signup to post a comment