Noiasca Modbus Server Simple
A lightweight Modbus Server Library
|
Class for Modbus Server Modbus Server (aka Modbus Slave) More...
#include <NoiascaModbusServerSimple.h>
Public Member Functions | |
ModbusServer (uint8_t serverId, Stream &serial) | |
This is the constructor of the ModbusServer Simple class. More... | |
void | setPreTransmission (void(*cbPreTransmission)()) |
action before the first byte will be transmitted. More... | |
void | setPostTransmission (void(*cbPostTransmission)()) |
action after the last byte was transmitted. More... | |
void | setIsValidAddress (bool(*cbIsValidAddress)(uint16_t)) |
validate received additional addresses. FC3/FC6/FC16. More... | |
void | setIsValidInputRegister (bool(*cbIsValidInputRegister)(uint16_t)) |
validate input register. FC4 Read input register More... | |
void | setRegisterSent (const CallBack cbRegisterSent) |
Client has sent an additional register FC6/FC16 Write Holding Registers if Holding Register is an additional address. More... | |
void | setRegisterWritten (const CallBack cbRegisterWritten) |
Client has written to a holding register. FC6/FC16 Write Holding Register. More... | |
void | setRegisterRead (const CallBack cbRegisterRead) |
Client has read a holding register. FC3 Read Multiple Holding register. More... | |
void | setRegisterViewed (uint16_t(*cbRegisterViewed)(uint16_t)) |
Client has viewed an additional address FC3 Read Multiple Holding Register. More... | |
void | setInputRegisterViewed (uint16_t(*cbInputRegisterViewed)(uint16_t)) |
Client has viewed an input register. FC4 Read Input Register. More... | |
int | setNoOfCoils (uint16_t newValue) |
sets the valid number of coils FC1/FC5/FC15 More... | |
void | setReadCoil (uint16_t(*cbReadCoil)(uint16_t)) |
returns one readed Coil from user sketch FC1 Read Coils. More... | |
void | setWriteCoil (const CallBack cbWriteCoil) |
Writes value to coil. FC5 Write Single Coil. FC15 Write Multiple Coils. More... | |
void | setReadDiscreteInput (uint16_t(*cbReadDiscreteInput)(uint16_t)) |
returns one discrete input from user sketch. FC2 Read Discrete Input. More... | |
void | setStreamEnd (const CallBack cbStreamEnd) |
transmission of several registers has ended. FC16 Write Multiple Hodling Registers. More... | |
void | setOnClientActivity (void(*cbOnClientActivitiy)()) |
Client activity. More... | |
int | setNoOfDiscreteInputs (uint16_t newValue) |
sets the valid number of discrete inputs FC2 Read Discrete Input More... | |
void | begin (Stream *SerialPort, long baud, uint8_t byteFormat, uint8_t serverId, uint16_t holdingRegsSize, uint16_t *regs) |
configures the Modbus instance More... | |
void | modbus_update_comms (long baud, unsigned char byteFormat) |
modify Modbus parameters during runtime More... | |
void | setServerId (uint8_t serverId) |
modifies the Modbus Server ID (slave ID) More... | |
uint16_t | update () |
Main "run" function to be called in loop() More... | |
Protected Member Functions | |
void | exceptionResponse (unsigned char exception) |
sends exception message | |
unsigned int | calculateCRC (unsigned char bufferSize) |
calculates CRC of bufferSize More... | |
Class for Modbus Server Modbus Server (aka Modbus Slave)
|
inline |
This is the constructor of the ModbusServer Simple class.
serverId | the server ID (slave ID) of this device |
serial | a reference to the serial interface. Can be an instance of HW Serial, SoftSerial or AltSerial. |
|
inline |
configures the Modbus instance
Init function. Call this function in setup() former modbus_configure
SerialPort | a pointer to your serial interface. |
baud | the baud rate of your serial interface. |
byteFormat | e.g. 8N1 |
serverId | the server ID (slave ID) of your device. |
holdingRegsSize | the total number of all holding registers. |
regs | a pointer to your array of holding registers. |
|
inlineprotected |
calculates CRC of bufferSize
bufferSize | the used number of bytes in the frame buffer |
|
inline |
modify Modbus parameters during runtime
Can be used to modify Modbus parameters. Will adopt frame rates based on baud. Don't forget to set baud (and byte format) of your interface.
baud | speed of serial interface. |
byteFormat | e.g. 8N1 |
|
inline |
Client has viewed an input register. FC4 Read Input Register.
Set callback to receive value from input register.
|
inline |
validate received additional addresses. FC3/FC6/FC16.
This function validates should validate if the received address is correct.
|
inline |
validate input register. FC4 Read input register
Set callback to to validate if the address should be handled as valid input register.
|
inline |
sets the valid number of coils FC1/FC5/FC15
FC1 Read Coils. FC5 Write Single Coil. FC15 Write Multiple Coils.
|
inline |
sets the valid number of discrete inputs FC2 Read Discrete Input
Define the number of discrete Inputs.
|
inline |
Client activity.
Set callback to a function which gets called if client has send a to this server.
|
inline |
action after the last byte was transmitted.
This function gets called after a Modbus message has finished sending (i.e. after all data has been physically transmitted onto the serial bus).
Typical usage of this callback is to enable an RS485 transceiver's Receiver Enable pin, and disable its Driver Enable pin.
|
inline |
action before the first byte will be transmitted.
This function gets called just before a Modbus message is responded over serial. Typical usage of this callback is to enable an RS485 transceiver's Driver Enable pin, and optionally disable its Receiver Enable pin.
|
inline |
returns one readed Coil from user sketch FC1 Read Coils.
Set callback to retrieves coil status from user sketch.
|
inline |
returns one discrete input from user sketch. FC2 Read Discrete Input.
Set callback to retrieves discrete input status from user sketch.
|
inline |
Client has read a holding register. FC3 Read Multiple Holding register.
Set callback to acknowledge the user sketch about client read activity.
|
inline |
Client has sent an additional register FC6/FC16 Write Holding Registers if Holding Register is an additional address.
Set callback to take over received data to user sketch
|
inline |
Client has viewed an additional address FC3 Read Multiple Holding Register.
Set callback to read from an additional address (outside of Holding Register Array).
|
inline |
Client has written to a holding register. FC6/FC16 Write Holding Register.
Set callback to acknowledge the user sketch about client write activity
|
inline |
modifies the Modbus Server ID (slave ID)
Assigns a new Modbus server ID to this device. Currently the new server ID is not check, but don't use other values than 1..247.
serverId | the server ID (slave ID) from 1 to 247. |
|
inline |
transmission of several registers has ended. FC16 Write Multiple Hodling Registers.
Set callback to function when several values were send using FC16 / end of transmission of several values.
|
inline |
Writes value to coil. FC5 Write Single Coil. FC15 Write Multiple Coils.
Set callback to write coil commands. User must implement the On or Off of the coil (output).
|
inline |
Main "run" function to be called in loop()
former modbus_unsigned intupdate()