ImodbusRTUmasterAdd() registers a Master request for repeated execution.
bool ImodbusRTUmasterAdd(HardwareSerial& serialPort, uint8_t slaveId, uint8_t functionCode, uint16_t address, uint16_t quantity, uint16_t* data, uint16_t timeoutMs = 100)
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
ImodbusRTUmasterAdd(serialPort, slaveId, functionCode, address, quantity, data, timeoutMs) | HardwareSerial& serialPort — Serial port connected to RS-485uint8_t slaveId — Slave addressuint8_t functionCodeuint16_t addressuint16_t quantityuint16_t* datauint16_t timeoutMs = 100 | bool | Registers a Master request for repeated execution. |
void setup() { ImodbusRTUmasterInit(Serial2, 9600); // Set the Master's communication port and baud rate. ImodbusRTUmasterAdd(Serial2, 1, 0x03, 0x00, 1, &D[1]); // Register a Master request for repeated execution. ImodbusRTUmasterAdd(Serial2, 1, 0x03, 0x01, 1, &D[2]); // Register a Master request for repeated execution. } void loop() { ImodbusRTUmasterRun(); // Execute registered requests or the specified single request. }
loop().M and D with Cnet/MC Protocol, define a single final size and initialization order. Do not call ImodbusRTUMem() or ICnetMem() again at runtime.M and D are not nullptr before accessing them in user code.