Thanks Mark,
I was worried that changing the address might break something inside the Modbus Engine, but that's not the case :-). I'll also do some testing it might be that the Modbus module does takes its reply address from the transmitted message rather than from the ptrMODBUS_pars table (or can be modified to). This way the message that wrote a register changing the Modbus address would reply with its old address, before then changing the Modbus engine to use the new address.
UPDATE - I can confirm that the Modbus engine, does take its reply address from the transmitted message so, by putting a line of code in fnMODBUSPostFunction I can safely update the Modbus slave address :-)
One other question, my transmitting device (Master) will normally be in Master mode all the time but I want to be able to switch it to slave mode so that I can do a firmware upgrade, from another Master device. It looks like when reading the Modbus Documentation that a Modbus port might be able to be configured as a Master and a Slave at the same time in the ptrMODBUS_pars table.
(MODBUS_MODE_RTU | MODBUS_SERIAL_SLAVE | MODBUS_SERIAL_MASTER | MODBUS_RS485_POSITIVE), // default to RTU mode as master - serial port 0
It could then respond to slave requests directed at it. Is this a correct assumption? Obviously if my device was in firmware upgrade mode it would stop master transmissions. Alternatively if Master and Slave mode are mutually exclusive I presume just changing the port mode in the parameter table would work.
UPDATE - Initial tests seem to show that you cannot have Master and Slave modes enabled at the same time on the same port, enabling Master mode stops the port responding in slave mode
Another question is if the above were true, and I could have a port in both Master and Slave modes. Then if a slave transaction to my device was in progress and it then started a modbus master send using fnMODBUS_Master_send would this send be queued until after the Slave transmission had finished.
I know this is a bit of a weird way of using the module, but I was just after an idea of how it might react.
Cheers
Martin