I have a question about Modbus. I’m using the Modbus component in ESP-IDF. I initialize my device as a Modbus TCP slave and load an initial configuration. It runs a FreeRTOS task where it operates as a slave.
In my application, I can receive a new configuration for the slave via MQTT at runtime. I know that some parameters of the Modbus stack can be updated dynamically while the slave is running, but I’m not sure about the TCP port where the slave listens.
My question is: Is it possible to change the TCP port the Modbus TCP slave listens on at runtime, or do I need to destroy the slave instance and create it again with the new port?
Thank you very much in advance!
Can I change the Modbus TCP slave listening port at runtime in ESP-IDF?
Re: Can I change the Modbus TCP slave listening port at runtime in ESP-IDF?
In case someone else encounters the same issue, the only solution I’ve found is to destroy the Modbus stack using mbc_slave_destroy(), and then create it again with the new TCP port. It’s not the most practical approach, but it works reliably. Be careful not to have other tasks using Modbus functions at the same time, as calling slave functions after the stack has been destroyed will result in errors.
If anyone knows of a better solution, I’d really appreciate the information.
If anyone knows of a better solution, I’d really appreciate the information.
Who is online
Users browsing this forum: Google [Bot], PetalBot, Semrush [Bot] and 4 guests