en-us_commands:reference:imodbusrtumasterinit
Table of Contents
ImodbusRTUmasterInit()
ImodbusRTUmasterInit() sets the Master communication port and baud rate.
void ImodbusRTUmasterInit(HardwareSerial& serialPort, long baudrate)
void ImodbusRTUmasterInit(HardwareSerial& serialPort, long baudrate, uint8_t config)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
ImodbusRTUmasterInit(serialPort, baudrate) | HardwareSerial& serialPort — Serial port connected to RS-485long baudrate — Baud rate | void | Sets the Master communication port and baud rate. |
Example
uint16_t data[10]; uint16_t readValue0; uint16_t readValue1; void setup() { ImodbusRTUmasterInit(Serial2, 9600); // Set the Master's communication port and baud rate. } void loop() { uint8_t result; result = ImodbusRTUmaster(Serial2, 1, 0x03, 0, 2, data); // Execute a single Master request immediately. if (result == IMODBUS_RTU_SUCCESS) { readValue0 = data[0]; readValue1 = data[1]; } data[0] = 1234; ImodbusRTUmaster(Serial2, 1, 0x06, 10, 1, data); // Execute a single Master request immediately. }
Precautions
- Keep calling the Slave or Master execution function in
loop(). - The data array size must be at least the requested quantity.
- Do not treat return codes BUSY and IDLE as communication failures.
- When sharing
MandDwith Cnet/MC Protocol, define a single final size and initialization order. Do not callImodbusRTUMem()orICnetMem()again at runtime. - Memory allocation functions do not return success status. For nonzero sizes, verify that
MandDare notnullptrbefore accessing them in user code.
Built-in Commands in the Same Category
en-us_commands/reference/imodbusrtumasterinit.txt · Last modified: by 127.0.0.1
