So what this script is doing is running two processes: one for the modbus server and one to perform background tasks. This works by doing the following:
1. Create one process that is listening to an IPC queue (device_writer)
2. Initialize a new modbus server whose datastore actually just writes to that queue (CallbackDataBlock)
3. Start up the modbus server (StartTCPServer)
All of the other functions are helpers to initialize or convert data:
a. rescale_value converts the value written to the queue to the value used by the controlled device (0..100) -> (-3200..3200)
b. read_device_map initializes the lookup map: every modbus write operation basically changes the controller value for a given device
c. as a convenience, we store the number of devices at register 0xbeef
This was an actually use case of a user who wanted a modbus server that could be used to control N devices. By writing to the register mapped to that device, they could change the value that was currently set on the device controller (which was attached to the server machine). The reason we performed the write to the device out of process was so that the modbus server wouldn't have to block while waiting for the command to finish (in case of a slow device). Also, a queue makes sure we don't attempt to write to the same or multiple devices at once (which might cause weird errors).
To change the behavior of this example, just redefine what your registers/values map to, change the device_writer function to do your work, and remove/add initialization code to suit your purpose. Does this help?