Unofficial Nextion/TJC User Forum

Nextion Simulator Detection and Startup Messages

One of the limitations of the Nextion Simulator is that it does not emit the startup messages as the actual screens do (notably 00 00 00 ff ff ff (“start up”) and 88 ff ff ff (“ready”)). Since I rely on these messages and need my Nextion firmware to work without modification in the Simulator, I had to come up with some sort of emulation.

The easy way is obviously to just use printh for both messages in the Program.s file. However, that would cause the actual screens to send the “fake” messages, too - which might lead to issues. A better solution would be to send them only if the firmware is running in the simulator. So the question is how to detect that.
This is where another limitation of the simulator comes in handy: bauds is fixed to 9600 - even after assigning another value to it. So if bauds remains unchanged after an assignment, you know that you’re running in the debugger. That trick might be useful for other stuff, too.
Note: this limitation may drop in future versions and thus break the detection. Latest version at the time of writing: v1.63.3.

Source code using the tricks above: Nextion Simulator Detection and Startup Messages · GitHub

Kind regards,
Max

2 Likes

This is clever as heck, nice work and thanks for sharing!

1 Like

This is also documented briefly here:

https://nextion.tech/forums/topic/serial-stops-working-on-ac-power-works-thru-usb-power/#post-89726

Definitely deserves its own topic. Very useful in some applications. Thanks for posting.

Nice! To be dead clear, I did not know about that topic; at that time I didn‘t even have an account there (only 1-2 months later).

I have to admit that bauds is IMO the logical first step for simulator detection. The fact that writing to it doesn‘t work is rather easy to find afterwards and it makes life much easier (than trying to figure out if it keeps the value between sessions / after power cycles).
In that sense I‘d assume other people found this trick (or a variation of it), too. Nonetheless I totall agree that it deserves it‘s own (public!) topic.

Kind regards,
Max


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).