Perform a "Read Coils" operation for the specified address for a single coil.
int coilRead(int address);
int coilRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
coil value on success, -1 on failure.
Perform a "Read Discrete Inputs" operation for the specified address for a single discrete input.
int discreteInputRead(int address);
int discreteInputRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
discrete input value on success, -1 on failure.
Perform a "Read Holding Registers" operation for a single holding register.
long holdingRegisterRead(int address);
long holdingRegisterRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address start address to use for operation
- holding register value on success, -1 on failure.
Perform a "Read Input Registers" operation for a single input register.
long inputRegisterRead(int address);
long inputRegisterRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
input register value on success, -1 on failure.
Perform a "Write Single Coil" operation for the specified address and value.
int coilWrite(int address, uint8_t value);
int coilWrite(int id, int address, uint8_t value);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- value coi -l value to write
1 on success, 0 on failure.
Perform a "Write Single Holding Register" operation for the specified address and value.
int holdingRegisterWrite(int address, uint16_t value);
int holdingRegisterWrite(int id, int address, uint16_t value);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- value - holding register value to write
1 on success, 0 on failure.
Perform a "Mask Write Registers" operation for the specified address, AND mask and OR mask.
int registerMaskWrite(int address, uint16_t andMask, uint16_t orMask);
int registerMaskWrite(int id, int address, uint16_t andMask, uint16_t orMask);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- andMask - AND mask to use for operation
- orMask - OR mask to use for operation
1 on success, 0 on failure.
Begin the process of a writing multiple coils or holding registers. Use write(value) to set the values you want to send, and endTransmission() to send request on the wire.
int beginTransmission(int type, int address, int nb);
int beginTransmission(int id, int type, int address, int nb);
- id (slave) - id of target, defaults to 0x00 if not specified
- type - type of write to perform, either COILS or HOLDING_REGISTERS
- address start address to use for operation
- nb - number of values to write
1 on success, 0 on failure
Set the values of a write operation started by beginTransmission(...).
int write(unsigned int value);
- value - value to write
1 on success, 0 on failure
End the process of a writing multiple coils or holding registers.
int endTransmission();
none
1 on success, 0 on failure
Read multiple coils, discrete inputs, holding registers, or input register values. Use available() and read() to process the read values.
int requestFrom(int type, int address, int nb);
int requestFrom(int id, int type, int address,int nb);
- id (slave) - id of target, defaults to 0x00 if not specified
- type - type of read to perform, either COILS, DISCRETE_INPUTS, HOLDING_REGISTERS, or INPUT_REGISTERS
- address start address to use for operation
- nb - number of values to read
0 on failure, number of values read on success
Query the number of values available to read after calling requestFrom(...)
int available();
none
number of values available for reading use read()
Read a value after calling requestFrom(...)
long read();
None
-1 on failure, value on success
Read the last error reason as a string
const char* lastError();
none
Last error reason as a C string
Stop the client and clean up
void end();
None
nothing
Start the Modbus RTU client with the specified parameters.
ModbusRTUClient.begin(baudrate);
ModbusRTUClient.begin(baudrate, config);
- baudrate - Baud rate to use for serial
- config - Config to use for serial (see Serial.begin(...) for more info.) defaults to SERIAL_8N1 if not provided
1 on success, 0 on failure
Creates a Modbus TCP client using the provided Client for the transport.
ModbusTCPClient(client);
- Client - to use for the transport
Start the Modbus TCP client with the specified parameters.
modbusTCPClient.begin(ip, port);
- ip - the IP Address the client will connect to
- port - port to the client will connect to
1 on success, 0 on failure
Returns the connection status.
modbusTCPClient.connected();
None
Returns true if the client is connected, false if not.
Disconnect from the server.
modbusTCPClient.stop();
None
Nothing
Configure the servers coils.
int configureCoils(int startAddress, int nb);
- startAddress - start address of coils
- nb - number of coils to configure
0 on success, 1 on failure
Configure the servers discrete inputs.
int configureDiscreteInputs(int startAddress, int nb);
- startAddress - start address of discrete inputs
- nb - number of discrete inputs to configure
0 on success, 1 on failure
Configure the servers holding registers.
int configureHoldingRegisters(int startAddress, int nb);
- startAddress - start address of holding registers
- nb - number of holding registers to configure
0 on success, 1 on failure
Configure the servers input registers.
int configureInputRegisters(int startAddress, int nb);
- startAddress - start address of input registers
- nb - number of input registers to configure
0 on success, 1 on failure
Perform a "Read Coils" operation for the specified address for a single coil.
int coilRead(int address);
int coilRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
coil value on success, -1 on failure.
Perform a "Read Discrete Inputs" operation for the specified address for a single discrete input.
int discreteInputRead(int address);
int discreteInputRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
discrete input value on success, -1 on failure.
Perform a "Read Holding Registers" operation for a single holding register.
long holdingRegisterRead(int address);
long holdingRegisterRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address start address to use for operation
- holding register value on success, -1 on failure.
Perform a "Read Input Registers" operation for a single input register.
long inputRegisterRead(int address);
long inputRegisterRead(int id, int address);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
input register value on success, -1 on failure.
Perform a "Write Single Coil" operation for the specified address and value.
int coilWrite(int address, uint8_t value);
int coilWrite(int id, int address, uint8_t value);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- value coi -l value to write
1 on success, 0 on failure.
Perform a "Write Single Holding Register" operation for the specified address and value.
int holdingRegisterWrite(int address, uint16_t value);
int holdingRegisterWrite(int id, int address, uint16_t value);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- value - holding register value to write
1 on success, 0 on failure.
Perform a "Mask Write Registers" operation for the specified address, AND mask and OR mask.
int registerMaskWrite(int address, uint16_t andMask, uint16_t orMask);
int registerMaskWrite(int id, int address, uint16_t andMask, uint16_t orMask);
- id (slave) - id of target, defaults to 0x00 if not specified
- address address to use for operation
- andMask - AND mask to use for operation
- orMask - OR mask to use for operation
1 on success, 0 on failure.
Write the value of the server's Discrete Input for the specified address and value.
int discreteInputWrite(int address, uint8_t value);
- address address to use for operation
- value - discrete input value to write
1 on success, 0 on failure.
Write values to the server's Discrete Inputs for the specified address and values.
int writeDiscreteInputs(int address, uint8_t values[], int nb);
- address address to use for operation
- values - array of discrete inputs values to write
- nb - number of discrete inputs to write
1 on success, 0 on failure.
Write the value of the server's Input Register for the specified address and value.
int inputRegisterWrite(int address, uint16_t value);
- address address to use for operation
- value - input register value to write
1 on success, 0 on failure.
Write values to the server's Input Registers for the specified address and values.
int writeInputRegisters(int address, uint16_t values[], int nb);
- address address to use for operation
- values - array of input registers values to write
- nb - number of input registers to write
1 on success, 0 on failure.
Poll for requests
virtual void poll() = 0;
None
nothing
Stop the server
void end();
None
nothing
Start the Modbus RTU server with the specified parameters.
ModbusRTUServer.begin(id, baudrate);
ModbusRTUServer.begin(id, baudrate, config);
- id - (slave) id of the server baudrate - Baud rate to use for serial
- config - Config to use for serial (see Serial.begin(...) for more info.) defaults to SERIAL_8N1 if not provided
1 on success, 0 on failure
Creates a Modbus TCP server.
ModbusTCPServer();
None
Start the Modbus TCP server.
modbusTCPserver.begin();
modbusTCPserver.begin(id);
- id - the (slave) id of the server, defaults to 0xff (TCP);
1 on success, 0 on failure
Accept a client connection.
modbusTCPserver.accept(client);
- client - the Client to accept a connection from;
Nothing