Hi,
I would like to send messages and evaluate the response using a script. That way I don’t have to repeat everything by hand (or copy paste every line) during development.
An example would be debugging a command line interface, e.g. read and write configurations, using a script.
Any advice on how to achieve this?
Write a Python script with pyserial to interact with the serial port?
https://pyserial.readthedocs.io/en/latest/shortintro.html
A million ways to do it, really. Does it have to intergrate with PlatformIO? Does it have to leave the serial terminal open afterwards for interaction?
If you have to type lots of lines to test your platform you could consider writing higher level command that executes multiple pre-scripted test commands.
Also, as a programmer, you should make your life as easy as possible. Make sure you can display, for example, all your config values with one command. Make columns so you can easy read them.
And don’t forget to make a help function which display all your commands with a short explanation. If you have to change something in half a year or longer this will make it much easier.
Good luck.
1 Like
The excellent terminal program for embedded ‘Tio’ allows you to script it with the full power of Lua. So unlike ‘expect’ from the bad old days, you have a full programmatic interface to the port.
I haven’t used this feature, but it sounds super cool.
If I don’t need esp32_exception_monitor (and I usaually don’t) I run ‘pio run -t upload -e whatever && tio -a latest - and it’ll DTRT about connecting to whatever dev node is the most recent, it doesn’t mind if it goes away for a few seconds and comes back (like an RISC-V ESP32’s native CDC/UART mode will during a reset) and having it all in one window means I never have to play hunt to find the monitor that’s bogarting the serial port and blocking the download.
Come to think of it, since the exception monitor is really just running esp-idf’s filter that’s looking for big hex numbers and then calling readelf on them, we could probably do that in tio …. via lua. Hopefully someone will beat me to that. It sounds like an “obviously cool” idea.
For such tasks you need a terminal programmable tool like auto terminal. I use this one https://github.com/Mightinside/Modbus-Monitor-Green
It allows to make up a scenario for any device, customize logic and flow, analyze and customize data. Let me know if you need any help in creating scenario for your device
It uses simple scripts, serial native language that is adapted for such matters in favor of simplification