MODBUS Common


Detailed Description

This module contains utilities shared by the MASTER and SLAVE stack.


Data Structures

struct  xMBStat
 This data structure is used by the statistic interface. More...
struct  xMBAnalyzerFrame
 This data structure is used by the protocol analyzer. More...

Defines

#define MB_HDL_INVALID   ( NULL )
#define MB_ERROR_IS_EXCEPTION(eStatus)

Typedefs

typedef void * xMBHandle
typedef void(* pvMBAnalyzerCallbackCB )(xMBHandle xHdl, void *pxCtx, const xMBPTimeStamp *pxTime, const xMBAnalyzerFrame *peFrame)

Enumerations

enum  eMBException {
  MB_PDU_EX_NONE = 0x00, MB_PDU_EX_ILLEGAL_FUNCTION = 0x01, MB_PDU_EX_ILLEGAL_DATA_ADDRESS = 0x02, MB_PDU_EX_ILLEGAL_DATA_VALUE = 0x03,
  MB_PDU_EX_SLAVE_DEVICE_FAILURE = 0x04, MB_PDU_EX_ACKNOWLEDGE = 0x05, MB_PDU_EX_SLAVE_BUSY = 0x06, MB_PDU_EX_NOT_ACKNOWLEDGE = 0x07,
  MB_PDU_EX_MEMORY_PARITY_ERROR = 0x08, MB_PDU_EX_GATEWAY_PATH_UNAVAILABLE = 0x0A, MB_PDU_EX_GATEWAY_TARGET_FAILED = 0x0B
}
enum  eMBErrorCode {
  MB_ENOERR = 0, MB_ENOREG = 1, MB_EINVAL = 2, MB_EPORTERR = 3,
  MB_ENORES = 4, MB_EIO = 5, MB_EILLSTATE = 6, MB_EAGAIN = 7,
  MB_ETIMEDOUT = 8, MB_EX_ILLEGAL_FUNCTION = 10, MB_EX_ILLEGAL_DATA_ADDRESS = 11, MB_EX_ILLEGAL_DATA_VALUE = 12,
  MB_EX_SLAVE_DEVICE_FAILURE = 13, MB_EX_ACKNOWLEDGE = 14, MB_EX_SLAVE_BUSY = 15, MB_EX_MEMORY_PARITY_ERROR = 16,
  MB_EX_GATEWAY_PATH_UNAVAILABLE = 17, MB_EX_GATEWAY_TARGET_FAILED = 18
}
enum  eMBSerialMode { MB_RTU, MB_ASCII }
enum  eMBSerialParity { MB_PAR_ODD, MB_PAR_EVEN, MB_PAR_NONE }

Functions

eMBErrorCode eMBExceptionToErrorcode (UBYTE ubMBException)
eMBException eMBErrorcodeToException (eMBErrorCode eCode)


Define Documentation

#define MB_ERROR_IS_EXCEPTION eStatus   ) 
 

Value:

( ( ( eStatus ) >= MB_EX_ILLEGAL_FUNCTION ) && \
      ( ( eStatus ) <= MB_EX_GATEWAY_TARGET_FAILED ) ? TRUE : FALSE )
Tests if an error code of the type eMBErrorCode is an exception.

Parameters:
eStatus The error code returned by any of the API functions.

#define MB_HDL_INVALID   ( NULL )
 

An invalid MASTER handle.


Typedef Documentation

typedef void( * pvMBAnalyzerCallbackCB)(xMBHandle xHdl, void *pxCtx, const xMBPTimeStamp *pxTime, const xMBAnalyzerFrame *peFrame)
 

A callback function used by the protocol analyzer.

Note that for ASCII the request is already converted into its binary equivalent and the control characters are stripped. The reason for this is that otherwise the stack would require internally twice the amount of memory if requests would be stored in raw. Therefore they are automatically decoded and encoded during transmit and receive.

Parameters:
xHdl The handle which made the callback. Do NOT call any MODBUS functions from within.
pxCtx The context supplied to the init function.
pxTime Timestamp when the frame has been captured.
peFrame The captured frame.

typedef void* xMBHandle
 

A handle used to hold either MASTER or SLAVE stack handles.


Enumeration Type Documentation

enum eMBErrorCode
 

Error code reported by the protocol stack.

Enumeration values:
MB_ENOERR  No error.
MB_ENOREG  Illegal register address.
MB_EINVAL  Illegal argument.
MB_EPORTERR  Porting layer error.
MB_ENORES  Insufficient resources.
MB_EIO  I/O error.
MB_EILLSTATE  Protocol stack in illegal state.
MB_EAGAIN  Retry I/O operation.
MB_ETIMEDOUT  Timeout error occurred.
MB_EX_ILLEGAL_FUNCTION  Illegal function exception.
MB_EX_ILLEGAL_DATA_ADDRESS  Illegal data address.
MB_EX_ILLEGAL_DATA_VALUE  Illegal data value.
MB_EX_SLAVE_DEVICE_FAILURE  Slave device failure.
MB_EX_ACKNOWLEDGE  Slave acknowledge.
MB_EX_SLAVE_BUSY  Slave device busy.
MB_EX_MEMORY_PARITY_ERROR  Memory parity error.
MB_EX_GATEWAY_PATH_UNAVAILABLE  Gateway path unavailable.
MB_EX_GATEWAY_TARGET_FAILED  Gateway target device failed to respond.
Examples:
AVR/demo.c.

enum eMBException
 

MODBUS exception defined for the MODBUS PDU.

Examples:
AVR/demo.c.

enum eMBSerialMode
 

Modes supported by the serial protocol stack.

Enumeration values:
MB_RTU  RTU transmission mode.
MB_ASCII  ASCII transmission mode.

enum eMBSerialParity
 

Parity for serial transmission mode.

Enumeration values:
MB_PAR_ODD  ODD parity.
MB_PAR_EVEN  Even parity.
MB_PAR_NONE  No parity.


Function Documentation

eMBException eMBErrorcodeToException eMBErrorCode  eCode  ) 
 

Map an application exception to a MODBUS exception.

Parameters:
eCode Any of the eMBErrorCode values. Non exceptional values are mapped to eMBException::MB_PDU_EX_SLAVE_DEVICE_FAILURE.
Returns:
The exception converted to a MODBUS PDU exception.

eMBErrorCode eMBExceptionToErrorcode UBYTE  ubMBException  ) 
 

Map a MODBUS exception code to an application error code.

Parameters:
ubMBException a MODBUS exception code from a MODBUS frame.
Returns:
The MODBUS exception converted to an application error.


(C) 2007 Embedded Solutions. Last updated on 23 Aug 2014.