Difference between revisions of "Modbus notes"

From Wiki at Neela Nurseries
Jump to: navigation, search
m (^ further references)
m
Line 30: Line 30:
  
 
...from this typedef looks like Modbus routines implemented by the end user/end designer must have parameter lists which match "unsigned char pointer, unsigned integer pointer".
 
...from this typedef looks like Modbus routines implemented by the end user/end designer must have parameter lists which match "unsigned char pointer, unsigned integer pointer".
 +
 +
 +
2019-11-13
 +
Further search for FreeModbus callback registering code"
 +
 +
<pre>
 +
downloads/freemodbus/freemodbus-v1.5.0$ grep -nr pxMBFunctionHandler ./*
 +
./modbus/mb.c:226:eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
 +
./modbus/include/mbproto.h:72:typedef        eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
 +
./modbus/include/mbproto.h:77:    pxMBFunctionHandler pxHandler;
 +
./modbus/include/mb.h:266:                              pxMBFunctionHandler pxHandler )
 +
</pre>
 +
 +
And the entire section of typedefs from mbproto.h:
 +
 +
<pre>
 +
/* ----------------------- Type definitions ---------------------------------*/
 +
    typedef enum
 +
{
 +
    MB_EX_NONE = 0x00,
 +
    MB_EX_ILLEGAL_FUNCTION = 0x01,
 +
    MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
 +
    MB_EX_ILLEGAL_DATA_VALUE = 0x03,
 +
    MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
 +
    MB_EX_ACKNOWLEDGE = 0x05,
 +
    MB_EX_SLAVE_BUSY = 0x06,
 +
    MB_EX_MEMORY_PARITY_ERROR = 0x08,
 +
    MB_EX_GATEWAY_PATH_FAILED = 0x0A,
 +
    MB_EX_GATEWAY_TGT_FAILED = 0x0B
 +
} eMBException;
 +
 +
typedef        eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
 +
 +
typedef struct
 +
{
 +
    UCHAR          ucFunctionCode;
 +
    pxMBFunctionHandler pxHandler;
 +
} xMBFunctionHandler;
 +
</pre>
 +
  
  

Revision as of 06:53, 14 November 2019



- 2019-11-08 FRI -

When working with FreeModbus, be sure to pay attention to the versions of protocol available, and likely, we only want to enable one of these. See Modbus/include/mbconfig.h. See also Modbus/include/mb.h for instructions on how to initialize and begin to use an instance of FreeModbus stack in given program. Also mention that eMBPoll() routine may be set up as a task in an RTOS, to realize the periodic polling which is part of the stack's runtime manifestation . . .

Looks like also this function to register callbacks for end-user-device-specific Modbus registers will be important:

  eMBErrorCode eMBRegisterCB ( UCHAR ucFunctionCode,
    pxMBFunctionHandler pxHandler
  )

This function signature part of documentation found at https://www.embedded-solutions.at/en/freemodbus/api-documentation/, which gives Doxygen generated API help in an embedded pane in the browser window on which it is visited.


2019-11-12 Tuesday - trying to figure out how pxMBFunctionHandler is defined . . . from http://www.teamfdi.com/uez/docs/mbproto_8h.html:

 Typedefs
 typedef eMBException(* pxMBFunctionHandler )(UCHAR *pucFrame, USHORT *pusLength)

...from this typedef looks like Modbus routines implemented by the end user/end designer must have parameter lists which match "unsigned char pointer, unsigned integer pointer".


2019-11-13 Further search for FreeModbus callback registering code"

downloads/freemodbus/freemodbus-v1.5.0$ grep -nr pxMBFunctionHandler ./*
./modbus/mb.c:226:eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
./modbus/include/mbproto.h:72:typedef         eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
./modbus/include/mbproto.h:77:    pxMBFunctionHandler pxHandler;
./modbus/include/mb.h:266:                               pxMBFunctionHandler pxHandler )

And the entire section of typedefs from mbproto.h:

/* ----------------------- Type definitions ---------------------------------*/
    typedef enum
{
    MB_EX_NONE = 0x00,
    MB_EX_ILLEGAL_FUNCTION = 0x01,
    MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
    MB_EX_ILLEGAL_DATA_VALUE = 0x03,
    MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
    MB_EX_ACKNOWLEDGE = 0x05,
    MB_EX_SLAVE_BUSY = 0x06,
    MB_EX_MEMORY_PARITY_ERROR = 0x08,
    MB_EX_GATEWAY_PATH_FAILED = 0x0A,
    MB_EX_GATEWAY_TGT_FAILED = 0x0B
} eMBException;

typedef         eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );

typedef struct
{
    UCHAR           ucFunctionCode;
    pxMBFunctionHandler pxHandler;
} xMBFunctionHandler;



^ further references

What do we need to pass to eMBRegisterCB()? . . .