@@ -70,6 +70,7 @@ extern "C" {
7070 * \endcode
7171 */
7272
73+ struct xMBCallbacks ;
7374struct xMBInstance ;
7475
7576/* ----------------------- Defines ------------------------------------------*/
@@ -89,6 +90,7 @@ struct xMBInstance;
8990 * processed until eMBEnable( ) has been called.
9091 *
9192 * \param xInstance The pointer to instance struct.
93+ * \param xMBCallbacks The pointer to struct containing Modbus callbacks.
9294 * \param eMode If ASCII or RTU mode should be used.
9395 * \param ucSlaveAddress The slave address. Only frames sent to this
9496 * address or to the broadcast address are processed.
@@ -106,9 +108,11 @@ struct xMBInstance;
106108 * slave addresses are in the range 1 - 247.
107109 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
108110 */
109- eMBErrorCode eMBInit ( struct xMBInstance * xInstance , eMBMode eMode ,
110- uint8_t ucSlaveAddress , uint8_t ucPort ,
111- uint32_t ulBaudRate , eMBParity eParity );
111+ eMBErrorCode eMBInit ( struct xMBInstance * xInstance ,
112+ const struct xMBCallbacks * xCallbacks ,
113+ eMBMode eMode , uint8_t ucSlaveAddress ,
114+ uint8_t ucPort , uint32_t ulBaudRate ,
115+ eMBParity eParity );
112116
113117/*! \ingroup modbus
114118 * \brief Initialize the Modbus protocol stack for Modbus TCP.
@@ -117,6 +121,7 @@ eMBErrorCode eMBInit( struct xMBInstance * xInstance, eMBMode eMode,
117121 * frame processing is still disabled until eMBEnable( ) is called.
118122 *
119123 * \param xInstance The pointer to instance struct.
124+ * \param xMBCallbacks The pointer to struct containing Modbus callbacks.
120125 * \param usTCPPort The TCP port to listen on.
121126 *
122127 * \return If the protocol stack has been initialized correctly the function
@@ -127,6 +132,7 @@ eMBErrorCode eMBInit( struct xMBInstance * xInstance, eMBMode eMode,
127132 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
128133 */
129134eMBErrorCode eMBTCPInit ( struct xMBInstance * xInstance ,
135+ const struct xMBCallbacks * xCallbacks ,
130136 uint16_t usTCPPort );
131137
132138/*! \ingroup modbus
@@ -238,160 +244,6 @@ eMBErrorCode eMBRegisterCB( struct xMBInstance * xInstance,
238244 uint8_t ucFunctionCode ,
239245 pxMBFunctionHandler pxHandler );
240246
241- /* ----------------------- Callback -----------------------------------------*/
242-
243- /*! \defgroup modbus_registers Modbus Registers
244- * \code #include "mb.h" \endcode
245- * The protocol stack does not internally allocate any memory for the
246- * registers. This makes the protocol stack very small and also usable on
247- * low end targets. In addition the values don't have to be in the memory
248- * and could for example be stored in a flash.<br>
249- * Whenever the protocol stack requires a value it calls one of the callback
250- * function with the register address and the number of registers to read
251- * as an argument. The application should then read the actual register values
252- * (for example the ADC voltage) and should store the result in the supplied
253- * buffer.<br>
254- * If the protocol stack wants to update a register value because a write
255- * register function was received a buffer with the new register values is
256- * passed to the callback function. The function should then use these values
257- * to update the application register values.
258- */
259-
260- /*! \ingroup modbus_registers
261- * \brief Callback function used if the value of a <em>Input Register</em>
262- * is required by the protocol stack. The starting register address is given
263- * by \c usAddress and the last register is given by <tt>usAddress +
264- * usNRegs - 1</tt>.
265- *
266- * \param xInstance The pointer to instance struct.
267- * \param pucRegBuffer A buffer where the callback function should write
268- * the current value of the modbus registers to.
269- * \param usAddress The starting address of the register. Input registers
270- * are in the range 1 - 65535.
271- * \param usNRegs Number of registers the callback function must supply.
272- *
273- * \return The function must return one of the following error codes:
274- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
275- * Modbus response is sent.
276- * - eMBErrorCode::MB_ENOREG If the application can not supply values
277- * for registers within this range. In this case a
278- * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
279- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
280- * currently not available and the application dependent response
281- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
282- * exception is sent as a response.
283- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
284- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
285- */
286- eMBErrorCode eMBRegInputCB ( struct xMBInstance * xInstance ,
287- uint8_t * pucRegBuffer , uint16_t usAddress ,
288- uint16_t usNRegs );
289-
290- /*! \ingroup modbus_registers
291- * \brief Callback function used if a <em>Holding Register</em> value is
292- * read or written by the protocol stack. The starting register address
293- * is given by \c usAddress and the last register is given by
294- * <tt>usAddress + usNRegs - 1</tt>.
295- *
296- * \param xInstance The pointer to instance struct.
297- * \param pucRegBuffer If the application registers values should be updated the
298- * buffer points to the new registers values. If the protocol stack needs
299- * to now the current values the callback function should write them into
300- * this buffer.
301- * \param usAddress The starting address of the register.
302- * \param usNRegs Number of registers to read or write.
303- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
304- * values should be updated from the values in the buffer. For example
305- * this would be the case when the Modbus master has issued an
306- * <b>WRITE SINGLE REGISTER</b> command.
307- * If the value eMBRegisterMode::MB_REG_READ the application should copy
308- * the current values into the buffer \c pucRegBuffer.
309- *
310- * \return The function must return one of the following error codes:
311- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
312- * Modbus response is sent.
313- * - eMBErrorCode::MB_ENOREG If the application can not supply values
314- * for registers within this range. In this case a
315- * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
316- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
317- * currently not available and the application dependent response
318- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
319- * exception is sent as a response.
320- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
321- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
322- */
323- eMBErrorCode eMBRegHoldingCB ( struct xMBInstance * xInstance ,
324- uint8_t * pucRegBuffer , uint16_t usAddress ,
325- uint16_t usNRegs , eMBRegisterMode eMode );
326-
327- /*! \ingroup modbus_registers
328- * \brief Callback function used if a <em>Coil Register</em> value is
329- * read or written by the protocol stack. If you are going to use
330- * this function you might use the functions xMBUtilSetBits( ) and
331- * xMBUtilGetBits( ) for working with bitfields.
332- *
333- * \param xInstance The pointer to instance struct.
334- * \param pucRegBuffer The bits are packed in bytes where the first coil
335- * starting at address \c usAddress is stored in the LSB of the
336- * first byte in the buffer <code>pucRegBuffer</code>.
337- * If the buffer should be written by the callback function unused
338- * coil values (I.e. if not a multiple of eight coils is used) should be set
339- * to zero.
340- * \param usAddress The first coil number.
341- * \param usNCoils Number of coil values requested.
342- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
343- * be updated from the values supplied in the buffer \c pucRegBuffer.
344- * If eMBRegisterMode::MB_REG_READ the application should store the current
345- * values in the buffer \c pucRegBuffer.
346- *
347- * \return The function must return one of the following error codes:
348- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
349- * Modbus response is sent.
350- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
351- * within the requested address range. In this case a
352- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
353- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
354- * currently not available and the application dependent response
355- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
356- * exception is sent as a response.
357- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
358- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
359- */
360- eMBErrorCode eMBRegCoilsCB ( struct xMBInstance * xInstance ,
361- uint8_t * pucRegBuffer , uint16_t usAddress ,
362- uint16_t usNCoils , eMBRegisterMode eMode );
363-
364- /*! \ingroup modbus_registers
365- * \brief Callback function used if a <em>Input Discrete Register</em> value is
366- * read by the protocol stack.
367- *
368- * If you are going to use his function you might use the functions
369- * xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
370- *
371- * \param xInstance The pointer to instance struct.
372- * \param pucRegBuffer The buffer should be updated with the current
373- * coil values. The first discrete input starting at \c usAddress must be
374- * stored at the LSB of the first byte in the buffer. If the requested number
375- * is not a multiple of eight the remaining bits should be set to zero.
376- * \param usAddress The starting address of the first discrete input.
377- * \param usNDiscrete Number of discrete input values.
378- * \return The function must return one of the following error codes:
379- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
380- * Modbus response is sent.
381- * - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
382- * In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent
383- * as a response.
384- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
385- * currently not available and the application dependent response
386- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
387- * exception is sent as a response.
388- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
389- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
390- */
391- eMBErrorCode eMBRegDiscreteCB ( struct xMBInstance * xInstance ,
392- uint8_t * pucRegBuffer , uint16_t usAddress ,
393- uint16_t usNDiscrete );
394-
395247#ifdef __cplusplus
396248}
397249#endif
0 commit comments