EVE 1.0
modbus.h File Reference

Main public header file for the Modbus client/server/sniffer over TCP/UART EVE module. More...

#include <sys/process.h>
#include <core/uwork.h>
#include <core/mwork.h>
Include dependency graph for modbus.h:

Go to the source code of this file.

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.
 

Detailed Description

Main public header file for the Modbus client/server/sniffer over TCP/UART EVE module.

Author
SE, Jetro AS

Definition in file modbus.h.