![]() |
EVE 1.0
|
![]() |
Data Structures | |
struct | mb_transfer_file_t |
Structure for holding variables related to Transfer File function. More... | |
struct | MbFunctionDescriptor_t |
Structure for holding a callback serving one of Modbus commands. A pointer of array of these structures must be settled as the FuncHandlers member of the modbus_t structure. More... | |
struct | MbVirtualfunc_t |
Structure for holding a number of protocol specific virtual functions. UART related functions are the part of Modbus driver. Other protocols must be implemented on the application level. It is not necessary to implement MbStart and/or MbStop functions, if there is nothing to do. Thus functions can be settlet to NULL in the structure. However MbSendData/MbReceiveData functions are mandatory. A pointer of array of these structures must be settled as the Virtualfunc member of the modbus_t structure. More... | |
struct | modbus_state_t |
modbus_state_t structure holds internal state of the Modbus driver. More... | |
struct | modbus_t |
modbus_t structure is used for configuration of Modbus instance. The structure must be initialized before the Modbus driver may be used. More... | |
Macros | |
#define | MB_SLAVEID_BUF_LEN 32 |
Number of bytes which should be allocated for the Report Slave ID command. More... | |
#define | MB_SER_PDU_SIZE_MAX 255 |
Maximum size of a Modbus RTU frame. 1 byte less than standard because of internal UART limitation. | |
#define | MB_TFILE_TARGET_SIZE 31 |
Length of bit vector of targets for Transfer File function. | |
#define | MB_TFILE_FNAMELEN_MAX 32 |
Length of the buffer holding filename for Transfer File function. As file name is null-terminated, actual filenane length cannot exceed 31. | |
#define | MB_TFILE_LAST_PACKET (1 << 31) |
Bit flag in the packet number field of TransferFilePart frame denoting the last packet (file end). | |
#define | MB_TFILE_PART_REGADDR 0xFF00 |
Server's pseudo-register containing last part number for verification from client (2 registers actually: MB_TFILE_PART_REGADDR and MB_TFILE_PART_REGADDR+1) | |
#define | MB_ADDRESS_BROADCAST ( 0 ) |
Modbus server addresses. More... | |
#define | MB_ADDRESS_MIN ( 1 ) |
Smallest possible slave address. | |
#define | MB_ADDRESS_MAX ( 247 ) |
Biggest possible slave address. | |
#define | MB_TCP_PSEUDO_ADDRESS ( 255 ) |
Server address on Modbus over TCP. | |
#define | MB_FUNC_NONE (0x00) |
Modbus function codes. More... | |
#define | MB_FUNC_READ_COILS (0x01) |
Read Coils. | |
#define | MB_FUNC_READ_DISCRETE_INPUTS (0x02) |
Read Discrete Inputs. | |
#define | MB_FUNC_READ_HOLDING_REGISTER (0x03) |
Read Holding Registers. | |
#define | MB_FUNC_READ_INPUT_REGISTER (0x04) |
Read Input Registers. | |
#define | MB_FUNC_WRITE_SINGLE_COIL (0x05) |
Write Single Coil. | |
#define | MB_FUNC_WRITE_REGISTER (0x06) |
Write Single Register. | |
#define | MB_FUNC_DIAG_READ_EXCEPTION (0x07) |
Read Exception Status (Serial Line only) | |
#define | MB_FUNC_DIAG_DIAGNOSTIC (0x08) |
Diagnostics (Serial Line only) | |
#define | MB_FUNC_DIAG_GET_COM_EVENT_CNT (0x0B) |
Get Comm Event Counter (Serial Line only) | |
#define | MB_FUNC_DIAG_GET_COM_EVENT_LOG (0x0C) |
Get Comm Event Log (Serial Line only) | |
#define | MB_FUNC_WRITE_MULTIPLE_COILS (0x0F) |
Write Multiple Coils. | |
#define | MB_FUNC_WRITE_MULTIPLE_REGISTERS (0x10) |
Write Multiple registers. | |
#define | MB_FUNC_REPORT_SERVER_ID (0x11) |
Report Server ID (Serial Line only) | |
#define | MB_FUNC_READ_FILE_RECORD (0x14) |
Read File Record. | |
#define | MB_FUNC_WRITE_FILE_RECORD (0x15) |
Write File Record. | |
#define | MB_FUNC_READWRITE_MULTIPLE_REGISTERS (0x17) |
Read/Write Multiple registers. | |
#define | MB_FUNC_TRANSFER_FILE (0x64) |
Transfer file - Jetro proprietary. | |
#define | MB_FUNC_TRANSFER_FILE_COMPLETED (0x65) |
Transfer file complete - Jetro proprietary. | |
#define | MB_FUNC_NEW_FILE (0x66) |
New file arrived - pseudo function, Jetro proprietary. | |
#define | MB_FUNC_ERROR (0x80) |
Error flag for responses (ORed with function code) | |
Typedefs | |
typedef MbException_t(* | MbVfuncStart_t) (const struct modbus_t *Mb, void *data) |
Callback specific to the protocol and called on the protocol start. More... | |
typedef MbException_t(* | MbVfuncStop_t) (const struct modbus_t *Mb) |
Callback specific to the protocol and called on the protocol stop. More... | |
typedef MbException_t(* | MbVfuncSend_t) (const struct modbus_t *Mb) |
Callbacks specific to the protocol and called when the driver wants to send data. More... | |
typedef MbException_t(* | MbVfuncReceive_t) (const struct modbus_t *Mb) |
Callbacks specific to the protocol and called when the driver wants to receive data. More... | |
typedef MbException_t(* | MbHoldingHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, uint16_t RegAddr, uint16_t *Value) |
Callbacks specific to the Read/Write Holding Register(s) command. They're called when Modbus command or response requires to read or write specific register. It could be both command request on the server side, or command response on the client side. More... | |
typedef MbException_t(* | MbTransferFileHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, mb_transfer_file_t *TransferFile) |
Callback specific to the Transfer File command. It is called when Modbus command requests to write a file. More... | |
typedef MbException_t(* | MbTransferFileCompletedHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, uint32_t PartNumber) |
Callback specific to the Transfer File Completed command. More... | |
typedef void(* | MbNewFileHandler_t) (const struct modbus_t *Mb, uint8_t *FileName) |
Callback specific to the Transfer File command. It is called after a new file arrives to server or sniffer. More... | |
typedef MbException_t(* | MbSessionClosed_t) (const struct modbus_t *Mb, MbException_t Error) |
Callback called on the command processing end (reporting overall success/error) More... | |
Enumerations |
Functions | |
MbException_t | MbInit (const struct modbus_t *Mb, uint8_t MbAddress) |
Initialise resources used by the protocol stack instance. More... | |
MbException_t | MbClose (const struct modbus_t *Mb) |
Release resources used by the protocol stack instance. More... | |
MbException_t | MbEnable (const struct modbus_t *Mb, void *Data) |
Enable the Modbus protocol stack instance. More... | |
MbException_t | MbDisable (const struct modbus_t *Mb) |
Disable the Modbus protocol stack instance. More... | |
MbException_t | MbReqWriteHolding (const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t RegData, int32_t TimeOut) |
Request to write holding register. More... | |
MbException_t | MbReqWriteMultiple (const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t NRegs, uint16_t *DataBuffer, int32_t TimeOut) |
Request to write multiple holding registers. More... | |
MbException_t | MbReqReadHolding (const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t NRegs, int32_t TimeOut) |
Request to read holding registers. More... | |
MbException_t | MbReqWriteFile (const struct modbus_t *Mb, uint8_t DestAddr, uint16_t FileNum, uint16_t RecNum, uint8_t *Data, uint16_t DataLen, int32_t TimeOut) |
Request to write file. More... | |
MbException_t | MbReqTransferFile (const struct modbus_t *Mb, uint8_t *Targets, uint32_t FileSize, uint32_t Crc32, uint8_t *FileName, int32_t TimeOut) |
Request to transfer file header. More... | |
MbException_t | MbReqTransferFileData (const struct modbus_t *Mb, uint32_t PartNumber, uint8_t PartSize, uint8_t *Data, int32_t TimeOut) |
Request to transfer file data. More... | |
MbException_t | MbReqTransferFileCompleted (const struct modbus_t *Mb, uint8_t MyAddress, uint32_t PartNumber, int32_t TimeOut) |
Request to send "transfer file complete" message. More... | |
Variables | |
const struct MbVirtualfunc_t | MbVirtualFuncRtu |
Virtual functions for the UART protocol. Included in the driver and ready to be included in modbus_t as an address of this structure. | |
const struct MbVirtualfunc_t | MbVirtualFuncTcp |
Virtual functions for the standard unsecured TCP protocol (using socket API). Included in the driver and ready to be included in modbus_t as an address of this structure. | |
#define MB_SLAVEID_BUF_LEN 32 |
Number of bytes which should be allocated for the Report Slave ID command.
This module defines the Modbus driver interface for the application. It contains the basic functions and types required to use the Modbus protocol stack. A typical application will want to call MbInit() first. If the device is ready to answer network requests it must then call MbEnable() to activate the protocol stack.
#define MB_ADDRESS_BROADCAST ( 0 ) |
#define MB_FUNC_NONE (0x00) |
typedef MbException_t(* MbVfuncStart_t) (const struct modbus_t *Mb, void *data) |
Callback specific to the protocol and called on the protocol start.
This callback can be implemented in the application for transport layers other than UART if some special processing required and settled to the Virtualfunc member of the modbus_t structure.
Mb | Modbus driver instance that should be started |
Error | Error code occured while command was processed |
typedef MbException_t(* MbVfuncStop_t) (const struct modbus_t *Mb) |
Callback specific to the protocol and called on the protocol stop.
This callback can be implemented in the application for transport layers other than UART if some special processing required and settled to the Virtualfunc member of the modbus_t structure.
Mb | Modbus driver instance that should be stopped. |
typedef MbException_t(* MbVfuncSend_t) (const struct modbus_t *Mb) |
Callbacks specific to the protocol and called when the driver wants to send data.
This callback must be implemented in the application for transport layers other than UART and settled to the Virtualfunc member of the modbus_t structure.
Implementation must write Mb->State->MbFrameLen bytes from the Mb->State->MbFrame pointer to the callback specific interface.
Mb | Modbus driver instance which called the callback |
typedef MbException_t(* MbVfuncReceive_t) (const struct modbus_t *Mb) |
Callbacks specific to the protocol and called when the driver wants to receive data.
This callback must be implemented in the application for transport layers other than UART and settled to the Virtualfunc member of the modbus_t structure.
Implementation must read all available bytes from the callback specific interface to the Mb->State->MbFrame pointer. Mb->State->MbFrameLen must be settled to the received data length.
Mb | Modbus driver instance which called the callback |
typedef MbException_t(* MbHoldingHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, uint16_t RegAddr, uint16_t *Value) |
Callbacks specific to the Read/Write Holding Register(s) command. They're called when Modbus command or response requires to read or write specific register. It could be both command request on the server side, or command response on the client side.
These callbacks must be implemented in the application for Read Holding Register, Write Holding Register, Write Multiple Registers command support and settled via the FuncHandlers member of the modbus_t structure.
Implementation must read or write one register.
Mb | Modbus driver instance which called the callback |
SlaveAddr | Slave address from the Modbus request/response frame |
RegAddr | Register address to read or write |
Value | Pointer to the value to set / buffer for output value |
typedef MbException_t(* MbTransferFileHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, mb_transfer_file_t *TransferFile) |
Callback specific to the Transfer File command. It is called when Modbus command requests to write a file.
This callback must be implemented in the application for Transfer File command support and settled via the FuncHandlers member of the modbus_t structure.
Mb | Modbus driver instance which called the callback |
SlaveAddr | Slave address from the Modbus request/response frame |
TransferFile | Structure with information about the file and current part |
typedef MbException_t(* MbTransferFileCompletedHandler_t) (const struct modbus_t *Mb, uint16_t SlaveAddr, uint32_t PartNumber) |
Callback specific to the Transfer File Completed command.
Mb | Modbus driver instance which called the callback |
SlaveAddr | Slave address from the Modbus request/response frame |
PartNumber | Reported file part number completed |
typedef void(* MbNewFileHandler_t) (const struct modbus_t *Mb, uint8_t *FileName) |
typedef MbException_t(* MbSessionClosed_t) (const struct modbus_t *Mb, MbException_t Error) |
Callback called on the command processing end (reporting overall success/error)
This callback should be implemented in the application and settled to the MbSessionClosedCb member of the modbus_t structure.
Mb | Modbus driver instance which called the callback |
Error | Error code occured while command was processed |
enum MbEvent_t |
Modbus events used in ModbusServerProcess and ModbusClientProcess.
enum MbMode_t |
enum MbRole_t |
enum MbException_t |
Modbus standard exception codes plus internal error codes used by all function in the protocol stack.
enum MbState_t |
Modbus driver state.
MbException_t MbInit | ( | const struct modbus_t * | Mb, |
uint8_t | MbAddress | ||
) |
Initialise resources used by the protocol stack instance.
This function initialises Modbus instance' state (modbus_state_t) and starts a new OS process for the instance. MbInit() does not allow to use the instance, MbEnable() call is required after initialisation in order to send/receive frames.
Mb | Modbus driver instance which called the callback |
MbAddress | Slave address for the instance (ignored for Client role and for TCP protocol) |
MbException_t MbClose | ( | const struct modbus_t * | Mb | ) |
Release resources used by the protocol stack instance.
This function releases all the resources and stops the OS process for the instance.
Mb | Modbus driver instance which called the callback |
MbException_t MbEnable | ( | const struct modbus_t * | Mb, |
void * | Data | ||
) |
Enable the Modbus protocol stack instance.
This function enables processing of Modbus frames. Enabling the protocol stack is only possible if it is in the disabled state: after MbInit() or MbDisable().
Mb | Modbus driver instance which called the callback |
Data | Pointer to the transport level instance descriptor (uart_t for UART, tls_conn_t for TLS). |
MbException_t MbDisable | ( | const struct modbus_t * | Mb | ) |
Disable the Modbus protocol stack instance.
Enabling the protocol stack is only possible if it is in the enabled state: after MbEnable().
Mb | Modbus driver instance which called the callback |
MbException_t MbReqWriteHolding | ( | const struct modbus_t * | Mb, |
uint8_t | DestAddr, | ||
uint16_t | RegAddr, | ||
uint16_t | RegData, | ||
int32_t | TimeOut | ||
) |
Request to write holding register.
Send Modbus command "write holding register" to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
DestAddr | Slave address to send to (can be MB_ADDRESS_BROADCAST) |
RegAddr | Register to write to |
RegData | Data to write |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqWriteMultiple | ( | const struct modbus_t * | Mb, |
uint8_t | DestAddr, | ||
uint16_t | RegAddr, | ||
uint16_t | NRegs, | ||
uint16_t * | DataBuffer, | ||
int32_t | TimeOut | ||
) |
Request to write multiple holding registers.
Send Modbus command "write multiple registers" to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
DestAddr | Slave address to send to (can be MB_ADDRESS_BROADCAST) |
RegAddr | First register to write to |
NRegs | Number of registers to write |
DataBuffer | Pointer to the data to write (must be NRegs*2 bytes long). |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqReadHolding | ( | const struct modbus_t * | Mb, |
uint8_t | DestAddr, | ||
uint16_t | RegAddr, | ||
uint16_t | NRegs, | ||
int32_t | TimeOut | ||
) |
Request to read holding registers.
Send Modbus command "read holding registers" to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
DestAddr | Slave address to send to |
RegAddr | First register to read from |
NRegs | Number of registers to read |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqWriteFile | ( | const struct modbus_t * | Mb, |
uint8_t | DestAddr, | ||
uint16_t | FileNum, | ||
uint16_t | RecNum, | ||
uint8_t * | Data, | ||
uint16_t | DataLen, | ||
int32_t | TimeOut | ||
) |
Request to write file.
Send Modbus command "write file record" to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
DestAddr | Slave address to send to (can be MB_ADDRESS_BROADCAST) |
FileNum | File number to write to |
RecNum | Record number to write |
Data | Pointer to the data to write. |
DataLen | Data length in bytes. |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqTransferFile | ( | const struct modbus_t * | Mb, |
uint8_t * | Targets, | ||
uint32_t | FileSize, | ||
uint32_t | Crc32, | ||
uint8_t * | FileName, | ||
int32_t | TimeOut | ||
) |
Request to transfer file header.
Send Jetro proprietary Modbus command "transfer file" with file header information (the first PDU in file transfer procedure) to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
Targets | uint8_t[31] is actually 248 bit array of Modbus device addresses the file transfers to. |
FileSize | File size in bytes |
Crc32 | File Crc calculated by crc32_compute() from nRF SDK from 1) file name, 2) file size (4 bytes), 3) file content. |
FileName | Pointer to an ASCII null-terminated string containing file name. |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqTransferFileData | ( | const struct modbus_t * | Mb, |
uint32_t | PartNumber, | ||
uint8_t | PartSize, | ||
uint8_t * | Data, | ||
int32_t | TimeOut | ||
) |
Request to transfer file data.
Send Jetro proprietary Modbus command "transfer file" with file data (all but the first PDU in file transfer procedure) to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
PartNumber | File part number (1-0x7FFFFFFF). Can't be 0 as 0th part transfers with MbReqTransferFileHeader() function. Highest bit denotes last part. |
PartSize | Part size in bytes (247 bytes max) |
Data | Pointer to the data to transfer. |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |
MbException_t MbReqTransferFileCompleted | ( | const struct modbus_t * | Mb, |
uint8_t | MyAddress, | ||
uint32_t | PartNumber, | ||
int32_t | TimeOut | ||
) |
Request to send "transfer file complete" message.
Send Jetro proprietary Modbus command "transfer file complete" to the bus and set the response timer. It is impossible to send another request before the current one is finished (with success, error or timeout): in such case MB_EX_BUSY is returned. In the end of command execution the callback Mb->MbSessionClosedCb will be called with the result.
Mb | Modbus driver instance which called the callback |
MyAddress | Modbus own sniffer address of the device |
PartNumber | Part number received |
TimeOut | Command timeout in ms (if 0, the default for modbus_t is used). |