SensorModbusMaster.h file
Contains the modbusMaster class declarations.
Classes
- union leFrame
- A frame for holding parts of a response. Define a little-endian frame as a union - that is a special class type that can hold only one of its non-static data members at a time.
- class modbusMaster
- The class for communicating with modbus devices.
Enums
- enum endianness { littleEndian = 0, bigEndian }
- The "endianness" of returned values.
- enum pointerType { holdingRegister = 0, inputRegister, inputContacts, outputCoil }
- The types of "pointers" to other modbus addresses.
- enum modbusErrorCode { NO_ERROR = 0x00, ILLEGAL_FUNCTION = 0x01, ILLEGAL_DATA_ADDRESS = 0x02, ILLEGAL_DATA_VALUE = 0x03, SLAVE_DEVICE_FAILURE = 0x04, ACKNOWLEDGE = 0x05, SLAVE_DEVICE_BUSY = 0x06, NEGATIVE_ACKNOWLEDGE = 0x07, MEMORY_PARITY = 0x08, GATEWAY_PATH_UNAVAILABLE = 0x0A, GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 0x0B, WRONG_SLAVE_ID = 0xD, BAD_CRC = 0xE, NO_RESPONSE = 0xF }
- The types of errors that can occur during Modbus communication.
Typedefs
- using endianness = enum endianness
- The "endianness" of returned values.
- using pointerType = enum pointerType
- The types of "pointers" to other modbus addresses.
- using modbusErrorCode = enum modbusErrorCode
- The types of errors that can occur during Modbus communication.
- using leFrame = union leFrame
- A frame for holding parts of a response. Define a little-endian frame as a union - that is a special class type that can hold only one of its non-static data members at a time.
Defines
- #define RESPONSE_BUFFER_SIZE = 256
- The size of the response buffer for the modbus devices.
- #define COMMAND_BUFFER_SIZE = 256
- The size of the command buffer for the modbus devices.
- #define MODBUS_TIMEOUT = 500
- The default time to wait for response after a command (in ms)
- #define MODBUS_FRAME_TIMEOUT = 4
- The default time to wait between characters within a frame (in ms)
- #define BYTE_SIZE = 1
- The size of a single byte in bytes.
- #define UINT16_SIZE = 2
- The size of a uint16_t in bytes.
- #define INT16_SIZE = 2
- The size of an int16_t in bytes.
- #define UINT32_SIZE = 4
- The size of a uint32_t in bytes.
- #define INT32_SIZE = 4
- The size of an int32_t in bytes.
- #define FLOAT32_SIZE = 4
- The size of a float32 in bytes.
- #define TAI64_SIZE = 8
- The size of a 64-bit timestamp in bytes.
- #define TAI64N_SIZE = 12
- The size of a 64-bit timestamp plus a 32-bit nanosecond in bytes.
- #define TAI64NA_SIZE = 16
- The size of a 64-bit timestamp plus a 32-bit nanosecond plus a 32-bit attosecond in bytes.
- #define POINTER_SIZE = 2
- The size of a pointer in bytes (when using Arduino system)
Enum documentation
enum endianness
The "endianness" of returned values.
Enumerators | |
---|---|
littleEndian |
little endian |
bigEndian |
big endian |
enum pointerType
The types of "pointers" to other modbus addresses.
Sometimes values in registers are set as the address of a pointer to look at for the real value rather than being set as the values themselves. This pointer type tells you in what section of the memory map to look for the value being pointed to.
Enumerators | |
---|---|
holdingRegister |
pointer to a holding register |
inputRegister |
pointer to an input register |
inputContacts |
pointer to a input contact |
outputCoil |
pointer to a output coil |
enum modbusErrorCode
The types of errors that can occur during Modbus communication.
Enumerators | |
---|---|
NO_ERROR |
All good. |
ILLEGAL_FUNCTION |
The function code received in the query is not an allowable action for the slave. |
ILLEGAL_DATA_ADDRESS |
The data address received in the query is not an allowable address for the slave. |
ILLEGAL_DATA_VALUE |
A value contained in the query data field is not an allowable value for the slave. |
SLAVE_DEVICE_FAILURE |
An unrecoverable error occurred while the slave was attempting to perform the requested action. |
ACKNOWLEDGE |
The server has accepted the request and is processing it, but a long duration of time is required to do so. |
SLAVE_DEVICE_BUSY |
The server is engaged in processing a long-duration program command. The client should retransmit the message later when the server is free. |
NEGATIVE_ACKNOWLEDGE |
The server cannot perform the program function received in the query. |
MEMORY_PARITY |
The server attempted to read extended memory, but detected a parity error in the memory. |
GATEWAY_PATH_UNAVAILABLE |
The gateway is not available. |
GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND |
The gateway target device failed to respond. |
WRONG_SLAVE_ID |
The response is not from the correct modbus slave. |
BAD_CRC |
The CRC check on the response failed. |
NO_RESPONSE |
No response was received at all. |
Typedef documentation
typedef enum pointerType pointerType
The types of "pointers" to other modbus addresses.
Sometimes values in registers are set as the address of a pointer to look at for the real value rather than being set as the values themselves. This pointer type tells you in what section of the memory map to look for the value being pointed to.
typedef union leFrame leFrame
A frame for holding parts of a response. Define a little-endian frame as a union - that is a special class type that can hold only one of its non-static data members at a time.
With avr-gcc (Arduino's compiler), integer and floating point variables are all physically stored in memory in little-endian byte order, so this union is all that is needed to translate modbus byte data into the other data forms.
Define documentation
#define RESPONSE_BUFFER_SIZE = 256
The size of the response buffer for the modbus devices.
Per the Specification and Implementation Guide for MODBUS over serial line, the maximum response size is 256 bytes - which is the size we use.
If you know you will never make any modbus requests for a modbus response this long, decrease this number to save memory space.
#define COMMAND_BUFFER_SIZE = 256
The size of the command buffer for the modbus devices.
Per the Specification and Implementation Guide for MODBUS over serial line, the maximum command size is 256 bytes - which is the size we use.
If you know in advance the size of the largest command you will send, you can decrease this number to save memory space.
#define MODBUS_FRAME_TIMEOUT = 4
The default time to wait between characters within a frame (in ms)
The modbus protocol defines that there can be no more than 1.5 characters of silence between characters in a frame and any space over 3.5 characters defines a new frame.