Hello waterfox,
What do you mean it can be added to the stack if required? Is there a way for me to customize the underlying stack, or was that an offer to extend the existing library?
You don't need to extend library. In order to read registers from your device you can use command "Read Holding Registers 0x03", and "Write Multiple Holding Registers 0x10". The modbus controller is the common interface above Modbus API for all ports which allows to read and write any parameters of your slave device. Additionally it allows to integrate this functionality with other components or networks adding abstraction object "characteristic" with its CID - characteristic iD. So you do not need to go deeper to lower layer of Modbus port and read description of its parameters (`mb_param_request_t`). I prepared the simplified example to read and write two holding registers of the device. The example has just one file and I removed as much as possible from there. Hope it will help you to understand API and read your device data.
Per your request to read rite holding register:
- Device 1
- Write Single Register
- Address 0
- Value 3000
The device address, reg type, start address of register, number of registers defined as: `MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0, 1,`
```
// Example Data (Object) Dictionary for Modbus parameters
const mb_parameter_descriptor_t device_parameters[] = {
// CID, Name, Units, Modbus addr, register type, Modbus Reg Start Addr, Modbus Reg read length,
// Instance offset (NA), Instance type, Instance length (bytes), Options (NA), Permissions
{ CID_DEV_REG0, STR("MB_hold_reg-0"), STR("Data"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0, 1,
0, PARAM_TYPE_U16, 2, OPTS( 0,0,0 ), PAR_PERMS_READ_WRITE_TRIGGER },
...
```
To write register you can use a call:
```
register_data = 3000;
err = write_modbus_parameter(CID_DEV_REG0, ®ister_data);
err = read_modbus_parameter(CID_DEV_REG0, ®ister_data);
```