#include "mbs.h"
The API documentation is splitted into different parts. A typical application will only to have use the API function shown in this module. The most important functions are the functions for opening and closing a MODBUS slave instances. There are different function depending on the type of transmission you are going to use. For serial transmission modes the function eMBSSerialInit should be used. For MODBUS/TCP the function eMBSTCPInit should be used.
Modules | |
MODBUS Configuration | |
Typedefs | |
typedef void * | xMBSHandle |
typedef eMBException(* | peMBSCoilCB )(UBYTE *pubRegBuffer, USHORT usAddress, USHORT usNRegs, eMBSRegisterMode eRegMode) MB_CDECL_SUFFIX |
typedef eMBException(* | peMBSDiscreteInputCB )(UBYTE *pubRegBuffer, USHORT usAddress, USHORT usNRegs) MB_CDECL_SUFFIX |
typedef eMBException(* | peMBSRegisterInputCB )(UBYTE *pubRegBuffer, USHORT usAddress, USHORT usNRegs) MB_CDECL_SUFFIX |
typedef eMBException(* | peMBSRegisterHoldingCB )(UBYTE *pubRegBuffer, USHORT usAddress, USHORT usNRegs, eMBSRegisterMode eRegMode) MB_CDECL_SUFFIX |
typedef eMBException(* | peMBSGatewayCB )(UBYTE ubSlaveAddress, UBYTE *pubMBPDU, USHORT *pusMBPDULength) MB_CDECL_SUFFIX |
typedef eMBException(* | peMBSSerialDiagCB )(eMBSSerialDiagQueryType_t eQueryType, UBYTE *pubMBPDU, USHORT *pusMBPDULength, const USHORT usMBPDULengthMax) MB_CDECL_SUFFIX |
Enumerations | |
enum | eMBSRegisterMode { MBS_REGISTER_WRITE, MBS_REGISTER_READ } |
enum | eMBSSerialDiagQueryType_t { DEVICE_IDENTIFICATION_OBJECT_ID_VENDORNAME = 0x00, DEVICE_IDENTIFICATION_OBJECT_ID_PRODUCTCODE = 0x01, DEVICE_IDENTIFICATION_OBJECT_ID_MAJORMINORREVISION = 0x02, DEVICE_IDENTIFICATION_OBJECT_ID_VENDORURL = 0x03, DEVICE_IDENTIFICATION_OBJECT_ID_PRODUCTNAME = 0x04, DEVICE_IDENTIFICATION_OBJECT_ID_MODELNAME = 0x05, DEVICE_IDENTIFICATION_OBJECT_ID_USERAPPLICATIONNAME = 0x06, DEVICE_IDENTIFICATION_OBJECT_ID_USER_START = 0x80, DEVICE_IDENTIFICATION_OBJECT_ID_USER_END = 0xFF, REPORT_SLAVE_ID_REQUEST_SLAVE_ID = 0x1000, REPORT_SLAVE_ID_REQUEST_STATUS = 0x1001, REPORT_SLAVE_ID_REQUEST_ADDITIONAL_DATA = 0x1002 } |
Functions | |
eMBErrorCode | eMBSGetRequestSlaveAddress (xMBSHandle xHdl, UBYTE *pubAddress) |
eMBErrorCode | eMBSGetStatistics (xMBSHandle xHdl, xMBStat *pxMBSCurrentStat) |
eMBErrorCode | eMBSResetStatistics (xMBSHandle xHdl) |
eMBErrorCode | eMBSRegisterProtAnalyzer (xMBSHandle xHdl, void *pvCtxArg, pvMBAnalyzerCallbackCB pvMBAnalyzerCallbackFN) |
eMBErrorCode | eMBSRegisterFunctionCB (xMBSHandle xHdl, UBYTE ubFuncIdx, peMBSCustomFunctionCB peFuncCB) |
eMBErrorCode | eMBSRegisterCoilCB (xMBSHandle xHdl, peMBSCoilCB peMBSCoilsCB) |
eMBErrorCode | eMBSRegisterDiscreteCB (xMBSHandle xHdl, peMBSDiscreteInputCB peDiscInputCB) |
eMBErrorCode | eMBSRegisterInputCB (xMBSHandle xHdl, peMBSRegisterInputCB peRegInputCB) |
eMBErrorCode | eMBSRegisterHoldingCB (xMBSHandle xHdl, peMBSRegisterHoldingCB peRegHoldingCB) |
eMBErrorCode | eMBSRegisterSerialDiagCB (xMBSHandle xHdl, peMBSSerialDiagCB peMBSSerDiagCB) |
eMBErrorCode | eMBSRegisterGatewayCB (xMBSHandle xHdl, peMBSGatewayCB peGatewayCB) |
eMBErrorCode | eMBSClose (xMBSHandle xHdl) |
eMBErrorCode | eMBSPoll (xMBSHandle xHdl) |
eMBErrorCode | eMBSSerialInit (xMBSHandle *pxHdl, eMBSerialMode eMode, UBYTE ubSlaveAddress, UBYTE ubPort, ULONG ulBaudRate, eMBSerialParity eParity) |
eMBErrorCode | eMBSSerialInitExt (xMBSHandle *pxHdl, eMBSerialMode eMode, UBYTE ubSlaveAddress, UBYTE ubPort, ULONG ulBaudRate, eMBSerialParity eParity, UCHAR ucStopBits) |
eMBErrorCode | eMBSTCPInit (xMBSHandle *pxHdl, CHAR *pcBindAddress, USHORT usTCPPort) |
eMBErrorCode | eMBSTCPSetGatewayMode (xMBSHandle xHdl, BOOL bEnable) |
|
Callback function if a coil register is read or written by the protocol stack.
The callback may read or write up to 2000 coils where the first coil is address by the parameter
|
|
Callback function if an discrete register is read by the protocol stack.
The callback may request up to 2000 discrete inputs where the first input to be returned is
|
|
Callback function for gateway mode. The argument pubMBPDU contains the complete MODBUS protocol data unit.
|
|
Callback function if a holding register is read or written by the protocol stack.
If the MODBUS slave stack needs to now the value of holding registers it executes this callback with
|
|
Callback function if an input register is read by the protocol stack.
If the MODBUS slave stack needs to now the values of input registers this callback function must store the current value of the registers starting at
|
|
This function is used by the serial diagnosis function codes to request device specific information. This function is used for the MODBUS requests
When ever an object is need the callback function is called. It should then store the request data in the buffer pointed to by pubMBPDU. The number of bytes stored should be stored in pusMBPDULength. The function is not allowed to write more than usMBPDULengthMax bytes.
|
|
A handle to a MODBUS slave instance.
|
|
If a register is written or read by the stack.
|
|
Objects used in the peMBSSerialDiagCB callbacks. These codes are used to identifiy different objects used for the report slave id and device identificiation calls. |
|
Close the stack. Shutdown the slave stack. This function waits until all pending MODBUS requests have been answered and then operation is stop. All resources are returned to the porting layer.
|
|
Retrieve the current slave address for this request. This function can only be called during a register callback. It then returns the slave address for this request in pubAddress.
|
|
Retrieve the current slave statistics. This function populates the argument pxMBSCurrentStat with the current internal counters.
|
|
The main polling loop of the MODBUS stack. This function must be called periodically. The timer interval required is given by the application but a good starting point is somewhere around 50ms. Internally the function checks if any events have happened and if yes processes them.
|
|
Register a function callback for coils.
|
|
Register a function callback for discrete inputs.
|
|
Register a new custom function for MODBUS function code
|
|
Register function callback for serial diagnosis functions.
|
|
Register a function callback for holding registers.
|
|
Register a function callback for input registers.
|
|
Register an protocol analyzer. If a protocol analyzer has been registered a callback is made whenever a frame has been sent or received.
|
|
Register function callback for gateway mode.
|
|
Clears the current statistic counters.
|
|
Create a new instances for a serial MODBUS slave instance using either ASCII or RTU transmission mode. Note that after the stack has been created function pointers for input, holding, coil and discrete registers have to be provided. They can be set by calling any of the functions:
|
|
Create a new instances for a serial MODBUS slave instance using either ASCII or RTU transmission mode.
|
|
Create a new MODBUS TCP slave instance.
This function tries to create a new MODBUS TCP slave listening on the address
|
|
Enable gateway mode where the MODBUS TCP slave answers on all addresses. Addresses 0 and 255 are MODBUS requests targeted to this slave. Other addresses from 1 - 247 should be forwarded to the appropriate clients. |