liblightmodbus
2.0
A lightweight, cross-platform Modbus RTU library
|
Core Modbus functions. More...
Go to the source code of this file.
Typedefs | |
typedef enum modbusError | ModbusError |
Represents a library runtime error code. More... | |
typedef enum modbusFrameError | ModbusFrameError |
Provides more information on frame building/parsing error. More... | |
typedef enum modbusExceptionCode | ModbusExceptionCode |
Represents a Modbus exception code, defined by the standart. More... | |
typedef enum modbusDataType | ModbusDataType |
Stores information about Modbus data types. More... | |
Functions | |
static uint16_t | modbusBitsToBytes (uint16_t n) |
Converts number of bits to number of bytes required to store them. More... | |
static uint16_t | modbusSwapEndian (uint16_t data) |
Swaps endianness of provided 16-bit data portion. More... | |
static uint16_t | modbusMatchEndian (uint16_t data) |
Swaps endianness of provided 16-bit data portion if needed. More... | |
uint8_t | modbusMaskRead (const uint8_t *mask, uint16_t maskLength, uint16_t bit) |
Reads n-th bit from an array. More... | |
uint8_t | modbusMaskWrite (uint8_t *mask, uint16_t maskLength, uint16_t bit, uint8_t value) |
Writes n-th bit in an array. More... | |
uint16_t | modbusCRC (const uint8_t *data, uint16_t length) |
Calculates 16-bit Modbus CRC of provided data. More... | |
Core Modbus functions.
This is main header file that is ought to be included as library
typedef enum modbusDataType ModbusDataType |
Stores information about Modbus data types.
typedef enum modbusError ModbusError |
Represents a library runtime error code.
typedef enum modbusExceptionCode ModbusExceptionCode |
Represents a Modbus exception code, defined by the standart.
typedef enum modbusFrameError ModbusFrameError |
Provides more information on frame building/parsing error.
These error code should serve as an additional source of information for the user.
enum modbusDataType |
enum modbusError |
Represents a library runtime error code.
Enumerator | |
---|---|
MODBUS_ERROR_OK | No error. |
MODBUS_ERROR_EXCEPTION | Indicates that slave had thrown an exception. This exception can be thrown either by master's parsing function (indicating incoming exception frame) or by slave's building function (indicating that some problem caused the slave to build an exception frame).
When thrown on slave side, check ModbusSlave::lastException and ModbusSlave::parseError for more information. |
MODBUS_ERROR_ALLOC | Memory problem. Either one of memory allocation functions returned NULL or fixed-size buffer is not big enough to fit the data (see Disabling dynamic memory allocation).Memory allocation problem |
MODBUS_ERROR_OTHER | Other reason causing the function to abort (eg. bad function parameter) |
MODBUS_ERROR_NULLPTR | A NULL pointer provided as some crucial parameter. |
MODBUS_ERROR_PARSE | Parsing error occurred - check ModbusSlave::parseError
|
MODBUS_ERROR_BUILD | Frame building error occurred - check ModbusMaster::buildError. |
MODBUS_OK | No error. Alias of MODBUS_ERROR_OK. |
enum modbusExceptionCode |
Represents a Modbus exception code, defined by the standart.
enum modbusFrameError |
Provides more information on frame building/parsing error.
These error code should serve as an additional source of information for the user.
|
inlinestatic |
Converts number of bits to number of bytes required to store them.
n | Number of bits |
uint16_t modbusCRC | ( | const uint8_t * | data, |
uint16_t | length | ||
) |
Calculates 16-bit Modbus CRC of provided data.
data | A pointer to the data to be processed |
length | Number of bytes, starting at the data pointer, to process |
uint8_t modbusMaskRead | ( | const uint8_t * | mask, |
uint16_t | maskLength, | ||
uint16_t | bit | ||
) |
Reads n-th bit from an array.
mask | A pointer to the array |
maskLength | The length of the array in bytes |
bit | Number of the bit to be read |
uint8_t modbusMaskWrite | ( | uint8_t * | mask, |
uint16_t | maskLength, | ||
uint16_t | bit, | ||
uint8_t | value | ||
) |
Writes n-th bit in an array.
mask | A pointer to the array |
maskLength | The length of the array in bytes |
bit | Number of the bit to write |
value | Bit value to be written |
|
inlinestatic |
Swaps endianness of provided 16-bit data portion if needed.
data | A 16-bit data portion. |
|
inlinestatic |
Swaps endianness of provided 16-bit data portion.
data | A 16-bit data portion. |