test public

Fork of Probleme_implementation_lwip by Tom Martins

Committer:
TomTom83
Date:
Mon Jul 02 15:18:18 2018 +0000
Revision:
2:9e76d51d9fb6
Parent:
0:0453a0a7e500
probl?mes d'adaptation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cam 0:0453a0a7e500 1 /*
cam 0:0453a0a7e500 2 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
cam 0:0453a0a7e500 3 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
cam 0:0453a0a7e500 4 * All rights reserved.
cam 0:0453a0a7e500 5 *
cam 0:0453a0a7e500 6 * Redistribution and use in source and binary forms, with or without
cam 0:0453a0a7e500 7 * modification, are permitted provided that the following conditions
cam 0:0453a0a7e500 8 * are met:
cam 0:0453a0a7e500 9 * 1. Redistributions of source code must retain the above copyright
cam 0:0453a0a7e500 10 * notice, this list of conditions and the following disclaimer.
cam 0:0453a0a7e500 11 * 2. Redistributions in binary form must reproduce the above copyright
cam 0:0453a0a7e500 12 * notice, this list of conditions and the following disclaimer in the
cam 0:0453a0a7e500 13 * documentation and/or other materials provided with the distribution.
cam 0:0453a0a7e500 14 * 3. The name of the author may not be used to endorse or promote products
cam 0:0453a0a7e500 15 * derived from this software without specific prior written permission.
cam 0:0453a0a7e500 16 *
cam 0:0453a0a7e500 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
cam 0:0453a0a7e500 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cam 0:0453a0a7e500 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
cam 0:0453a0a7e500 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
cam 0:0453a0a7e500 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
cam 0:0453a0a7e500 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
cam 0:0453a0a7e500 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
cam 0:0453a0a7e500 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
cam 0:0453a0a7e500 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
cam 0:0453a0a7e500 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cam 0:0453a0a7e500 27 *
cam 0:0453a0a7e500 28 * File: $Id: mb.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
cam 0:0453a0a7e500 29 */
cam 0:0453a0a7e500 30
cam 0:0453a0a7e500 31 #ifndef _MB_H
cam 0:0453a0a7e500 32 #define _MB_H
cam 0:0453a0a7e500 33
cam 0:0453a0a7e500 34 #include "port.h"
cam 0:0453a0a7e500 35
cam 0:0453a0a7e500 36 #ifdef __cplusplus
cam 0:0453a0a7e500 37 PR_BEGIN_EXTERN_C
cam 0:0453a0a7e500 38 #endif
cam 0:0453a0a7e500 39
cam 0:0453a0a7e500 40 #include "mbport.h"
cam 0:0453a0a7e500 41 #include "mbproto.h"
cam 0:0453a0a7e500 42
cam 0:0453a0a7e500 43 /*! \defgroup modbus Modbus
cam 0:0453a0a7e500 44 * \code #include "mb.h" \endcode
cam 0:0453a0a7e500 45 *
cam 0:0453a0a7e500 46 * This module defines the interface for the application. It contains
cam 0:0453a0a7e500 47 * the basic functions and types required to use the Modbus protocol stack.
cam 0:0453a0a7e500 48 * A typical application will want to call eMBInit() first. If the device
cam 0:0453a0a7e500 49 * is ready to answer network requests it must then call eMBEnable() to activate
cam 0:0453a0a7e500 50 * the protocol stack. In the main loop the function eMBPoll() must be called
cam 0:0453a0a7e500 51 * periodically. The time interval between pooling depends on the configured
cam 0:0453a0a7e500 52 * Modbus timeout. If an RTOS is available a separate task should be created
cam 0:0453a0a7e500 53 * and the task should always call the function eMBPoll().
cam 0:0453a0a7e500 54 *
cam 0:0453a0a7e500 55 * \code
cam 0:0453a0a7e500 56 * // Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A
cam 0:0453a0a7e500 57 * eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN );
cam 0:0453a0a7e500 58 * // Enable the Modbus Protocol Stack.
cam 0:0453a0a7e500 59 * eMBEnable( );
cam 0:0453a0a7e500 60 * for( ;; )
cam 0:0453a0a7e500 61 * {
cam 0:0453a0a7e500 62 * // Call the main polling loop of the Modbus protocol stack.
cam 0:0453a0a7e500 63 * eMBPoll( );
cam 0:0453a0a7e500 64 * ...
cam 0:0453a0a7e500 65 * }
cam 0:0453a0a7e500 66 * \endcode
cam 0:0453a0a7e500 67 */
cam 0:0453a0a7e500 68
cam 0:0453a0a7e500 69 /* ----------------------- Defines ------------------------------------------*/
cam 0:0453a0a7e500 70
cam 0:0453a0a7e500 71 /*! \ingroup modbus
cam 0:0453a0a7e500 72 * \brief Use the default Modbus TCP port (502)
cam 0:0453a0a7e500 73 */
cam 0:0453a0a7e500 74 #define MB_TCP_PORT_USE_DEFAULT 0
cam 0:0453a0a7e500 75
cam 0:0453a0a7e500 76 /* ----------------------- Type definitions ---------------------------------*/
cam 0:0453a0a7e500 77
cam 0:0453a0a7e500 78 /*! \ingroup modbus
cam 0:0453a0a7e500 79 * \brief Modbus serial transmission modes (RTU/ASCII).
cam 0:0453a0a7e500 80 *
cam 0:0453a0a7e500 81 * Modbus serial supports two transmission modes. Either ASCII or RTU. RTU
cam 0:0453a0a7e500 82 * is faster but has more hardware requirements and requires a network with
cam 0:0453a0a7e500 83 * a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
cam 0:0453a0a7e500 84 */
cam 0:0453a0a7e500 85 typedef enum
cam 0:0453a0a7e500 86 {
cam 0:0453a0a7e500 87 MB_RTU, /*!< RTU transmission mode. */
cam 0:0453a0a7e500 88 MB_ASCII, /*!< ASCII transmission mode. */
cam 0:0453a0a7e500 89 MB_TCP /*!< TCP mode. */
cam 0:0453a0a7e500 90 } eMBMode;
cam 0:0453a0a7e500 91
cam 0:0453a0a7e500 92 /*! \ingroup modbus
cam 0:0453a0a7e500 93 * \brief If register should be written or read.
cam 0:0453a0a7e500 94 *
cam 0:0453a0a7e500 95 * This value is passed to the callback functions which support either
cam 0:0453a0a7e500 96 * reading or writing register values. Writing means that the application
cam 0:0453a0a7e500 97 * registers should be updated and reading means that the modbus protocol
cam 0:0453a0a7e500 98 * stack needs to know the current register values.
cam 0:0453a0a7e500 99 *
cam 0:0453a0a7e500 100 * \see eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and
cam 0:0453a0a7e500 101 * eMBRegInputCB( ).
cam 0:0453a0a7e500 102 */
cam 0:0453a0a7e500 103 typedef enum
cam 0:0453a0a7e500 104 {
cam 0:0453a0a7e500 105 MB_REG_READ, /*!< Read register values and pass to protocol stack. */
cam 0:0453a0a7e500 106 MB_REG_WRITE /*!< Update register values. */
cam 0:0453a0a7e500 107 } eMBRegisterMode;
cam 0:0453a0a7e500 108
cam 0:0453a0a7e500 109 /*! \ingroup modbus
cam 0:0453a0a7e500 110 * \brief Errorcodes used by all function in the protocol stack.
cam 0:0453a0a7e500 111 */
cam 0:0453a0a7e500 112 typedef enum
cam 0:0453a0a7e500 113 {
cam 0:0453a0a7e500 114 MB_ENOERR, /*!< no error. */
cam 0:0453a0a7e500 115 MB_ENOREG, /*!< illegal register address. */
cam 0:0453a0a7e500 116 MB_EINVAL, /*!< illegal argument. */
cam 0:0453a0a7e500 117 MB_EPORTERR, /*!< porting layer error. */
cam 0:0453a0a7e500 118 MB_ENORES, /*!< insufficient resources. */
cam 0:0453a0a7e500 119 MB_EIO, /*!< I/O error. */
cam 0:0453a0a7e500 120 MB_EILLSTATE, /*!< protocol stack in illegal state. */
cam 0:0453a0a7e500 121 MB_ETIMEDOUT /*!< timeout error occurred. */
cam 0:0453a0a7e500 122 } eMBErrorCode;
cam 0:0453a0a7e500 123
cam 0:0453a0a7e500 124
cam 0:0453a0a7e500 125 /* ----------------------- Function prototypes ------------------------------*/
cam 0:0453a0a7e500 126 /*! \ingroup modbus
cam 0:0453a0a7e500 127 * \brief Initialize the Modbus protocol stack.
cam 0:0453a0a7e500 128 *
cam 0:0453a0a7e500 129 * This functions initializes the ASCII or RTU module and calls the
cam 0:0453a0a7e500 130 * init functions of the porting layer to prepare the hardware. Please
cam 0:0453a0a7e500 131 * note that the receiver is still disabled and no Modbus frames are
cam 0:0453a0a7e500 132 * processed until eMBEnable( ) has been called.
cam 0:0453a0a7e500 133 *
cam 0:0453a0a7e500 134 * \param eMode If ASCII or RTU mode should be used.
cam 0:0453a0a7e500 135 * \param ucSlaveAddress The slave address. Only frames sent to this
cam 0:0453a0a7e500 136 * address or to the broadcast address are processed.
cam 0:0453a0a7e500 137 * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
cam 0:0453a0a7e500 138 * is platform dependent and some ports simply choose to ignore it.
cam 0:0453a0a7e500 139 * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
cam 0:0453a0a7e500 140 * on the porting layer.
cam 0:0453a0a7e500 141 * \param eParity Parity used for serial transmission.
cam 0:0453a0a7e500 142 *
cam 0:0453a0a7e500 143 * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
cam 0:0453a0a7e500 144 * The protocol is then in the disabled state and ready for activation
cam 0:0453a0a7e500 145 * by calling eMBEnable( ). Otherwise one of the following error codes
cam 0:0453a0a7e500 146 * is returned:
cam 0:0453a0a7e500 147 * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
cam 0:0453a0a7e500 148 * slave addresses are in the range 1 - 247.
cam 0:0453a0a7e500 149 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
cam 0:0453a0a7e500 150 */
cam 0:0453a0a7e500 151 eMBErrorCode eMBInit( eMBMode eMode, UCHAR ucSlaveAddress,
cam 0:0453a0a7e500 152 UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity );
cam 0:0453a0a7e500 153
cam 0:0453a0a7e500 154 /*! \ingroup modbus
cam 0:0453a0a7e500 155 * \brief Initialize the Modbus protocol stack for Modbus TCP.
cam 0:0453a0a7e500 156 *
cam 0:0453a0a7e500 157 * This function initializes the Modbus TCP Module. Please note that
cam 0:0453a0a7e500 158 * frame processing is still disabled until eMBEnable( ) is called.
cam 0:0453a0a7e500 159 *
cam 0:0453a0a7e500 160 * \param usTCPPort The TCP port to listen on.
cam 0:0453a0a7e500 161 * \return If the protocol stack has been initialized correctly the function
cam 0:0453a0a7e500 162 * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
cam 0:0453a0a7e500 163 * codes is returned:
cam 0:0453a0a7e500 164 * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
cam 0:0453a0a7e500 165 * slave addresses are in the range 1 - 247.
cam 0:0453a0a7e500 166 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
cam 0:0453a0a7e500 167 */
cam 0:0453a0a7e500 168 eMBErrorCode eMBTCPInit( USHORT usTCPPort );
cam 0:0453a0a7e500 169
cam 0:0453a0a7e500 170 /*! \ingroup modbus
cam 0:0453a0a7e500 171 * \brief Release resources used by the protocol stack.
cam 0:0453a0a7e500 172 *
cam 0:0453a0a7e500 173 * This function disables the Modbus protocol stack and release all
cam 0:0453a0a7e500 174 * hardware resources. It must only be called when the protocol stack
cam 0:0453a0a7e500 175 * is disabled.
cam 0:0453a0a7e500 176 *
cam 0:0453a0a7e500 177 * \note Note all ports implement this function. A port which wants to
cam 0:0453a0a7e500 178 * get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
cam 0:0453a0a7e500 179 *
cam 0:0453a0a7e500 180 * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
cam 0:0453a0a7e500 181 * If the protocol stack is not in the disabled state it returns
cam 0:0453a0a7e500 182 * eMBErrorCode::MB_EILLSTATE.
cam 0:0453a0a7e500 183 */
cam 0:0453a0a7e500 184 eMBErrorCode eMBClose( void );
cam 0:0453a0a7e500 185
cam 0:0453a0a7e500 186 /*! \ingroup modbus
cam 0:0453a0a7e500 187 * \brief Enable the Modbus protocol stack.
cam 0:0453a0a7e500 188 *
cam 0:0453a0a7e500 189 * This function enables processing of Modbus frames. Enabling the protocol
cam 0:0453a0a7e500 190 * stack is only possible if it is in the disabled state.
cam 0:0453a0a7e500 191 *
cam 0:0453a0a7e500 192 * \return If the protocol stack is now in the state enabled it returns
cam 0:0453a0a7e500 193 * eMBErrorCode::MB_ENOERR. If it was not in the disabled state it
cam 0:0453a0a7e500 194 * return eMBErrorCode::MB_EILLSTATE.
cam 0:0453a0a7e500 195 */
cam 0:0453a0a7e500 196 eMBErrorCode eMBEnable( void );
cam 0:0453a0a7e500 197
cam 0:0453a0a7e500 198 /*! \ingroup modbus
cam 0:0453a0a7e500 199 * \brief Disable the Modbus protocol stack.
cam 0:0453a0a7e500 200 *
cam 0:0453a0a7e500 201 * This function disables processing of Modbus frames.
cam 0:0453a0a7e500 202 *
cam 0:0453a0a7e500 203 * \return If the protocol stack has been disabled it returns
cam 0:0453a0a7e500 204 * eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
cam 0:0453a0a7e500 205 * eMBErrorCode::MB_EILLSTATE.
cam 0:0453a0a7e500 206 */
cam 0:0453a0a7e500 207 eMBErrorCode eMBDisable( void );
cam 0:0453a0a7e500 208
cam 0:0453a0a7e500 209 /*! \ingroup modbus
cam 0:0453a0a7e500 210 * \brief The main pooling loop of the Modbus protocol stack.
cam 0:0453a0a7e500 211 *
cam 0:0453a0a7e500 212 * This function must be called periodically. The timer interval required
cam 0:0453a0a7e500 213 * is given by the application dependent Modbus slave timeout. Internally the
cam 0:0453a0a7e500 214 * function calls xMBPortEventGet() and waits for an event from the receiver or
cam 0:0453a0a7e500 215 * transmitter state machines.
cam 0:0453a0a7e500 216 *
cam 0:0453a0a7e500 217 * \return If the protocol stack is not in the enabled state the function
cam 0:0453a0a7e500 218 * returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns
cam 0:0453a0a7e500 219 * eMBErrorCode::MB_ENOERR.
cam 0:0453a0a7e500 220 */
cam 0:0453a0a7e500 221 eMBErrorCode eMBPoll( void );
cam 0:0453a0a7e500 222
cam 0:0453a0a7e500 223 /*! \ingroup modbus
cam 0:0453a0a7e500 224 * \brief Configure the slave id of the device.
cam 0:0453a0a7e500 225 *
cam 0:0453a0a7e500 226 * This function should be called when the Modbus function <em>Report Slave ID</em>
cam 0:0453a0a7e500 227 * is enabled ( By defining MB_FUNC_OTHER_REP_SLAVEID_ENABLED in mbconfig.h ).
cam 0:0453a0a7e500 228 *
cam 0:0453a0a7e500 229 * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
cam 0:0453a0a7e500 230 * <em>Report Slave ID</em> response.
cam 0:0453a0a7e500 231 * \param xIsRunning If TRUE the <em>Run Indicator Status</em> byte is set to 0xFF.
cam 0:0453a0a7e500 232 * otherwise the <em>Run Indicator Status</em> is 0x00.
cam 0:0453a0a7e500 233 * \param pucAdditional Values which should be returned in the <em>Additional</em>
cam 0:0453a0a7e500 234 * bytes of the <em> Report Slave ID</em> response.
cam 0:0453a0a7e500 235 * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
cam 0:0453a0a7e500 236 *
cam 0:0453a0a7e500 237 * \return If the static buffer defined by MB_FUNC_OTHER_REP_SLAVEID_BUF in
cam 0:0453a0a7e500 238 * mbconfig.h is to small it returns eMBErrorCode::MB_ENORES. Otherwise
cam 0:0453a0a7e500 239 * it returns eMBErrorCode::MB_ENOERR.
cam 0:0453a0a7e500 240 */
cam 0:0453a0a7e500 241 eMBErrorCode eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
cam 0:0453a0a7e500 242 UCHAR const *pucAdditional,
cam 0:0453a0a7e500 243 USHORT usAdditionalLen );
cam 0:0453a0a7e500 244
cam 0:0453a0a7e500 245 /*! \ingroup modbus
cam 0:0453a0a7e500 246 * \brief Registers a callback handler for a given function code.
cam 0:0453a0a7e500 247 *
cam 0:0453a0a7e500 248 * This function registers a new callback handler for a given function code.
cam 0:0453a0a7e500 249 * The callback handler supplied is responsible for interpreting the Modbus PDU and
cam 0:0453a0a7e500 250 * the creation of an appropriate response. In case of an error it should return
cam 0:0453a0a7e500 251 * one of the possible Modbus exceptions which results in a Modbus exception frame
cam 0:0453a0a7e500 252 * sent by the protocol stack.
cam 0:0453a0a7e500 253 *
cam 0:0453a0a7e500 254 * \param ucFunctionCode The Modbus function code for which this handler should
cam 0:0453a0a7e500 255 * be registers. Valid function codes are in the range 1 to 127.
cam 0:0453a0a7e500 256 * \param pxHandler The function handler which should be called in case
cam 0:0453a0a7e500 257 * such a frame is received. If \c NULL a previously registered function handler
cam 0:0453a0a7e500 258 * for this function code is removed.
cam 0:0453a0a7e500 259 *
cam 0:0453a0a7e500 260 * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
cam 0:0453a0a7e500 261 * more resources are available it returns eMBErrorCode::MB_ENORES. In this
cam 0:0453a0a7e500 262 * case the values in mbconfig.h should be adjusted. If the argument was not
cam 0:0453a0a7e500 263 * valid it returns eMBErrorCode::MB_EINVAL.
cam 0:0453a0a7e500 264 */
cam 0:0453a0a7e500 265 eMBErrorCode eMBRegisterCB( UCHAR ucFunctionCode,
cam 0:0453a0a7e500 266 pxMBFunctionHandler pxHandler );
cam 0:0453a0a7e500 267
cam 0:0453a0a7e500 268 /* ----------------------- Callback -----------------------------------------*/
cam 0:0453a0a7e500 269
cam 0:0453a0a7e500 270 /*! \defgroup modbus_registers Modbus Registers
cam 0:0453a0a7e500 271 * \code #include "mb.h" \endcode
cam 0:0453a0a7e500 272 * The protocol stack does not internally allocate any memory for the
cam 0:0453a0a7e500 273 * registers. This makes the protocol stack very small and also usable on
cam 0:0453a0a7e500 274 * low end targets. In addition the values don't have to be in the memory
cam 0:0453a0a7e500 275 * and could for example be stored in a flash.<br>
cam 0:0453a0a7e500 276 * Whenever the protocol stack requires a value it calls one of the callback
cam 0:0453a0a7e500 277 * function with the register address and the number of registers to read
cam 0:0453a0a7e500 278 * as an argument. The application should then read the actual register values
cam 0:0453a0a7e500 279 * (for example the ADC voltage) and should store the result in the supplied
cam 0:0453a0a7e500 280 * buffer.<br>
cam 0:0453a0a7e500 281 * If the protocol stack wants to update a register value because a write
cam 0:0453a0a7e500 282 * register function was received a buffer with the new register values is
cam 0:0453a0a7e500 283 * passed to the callback function. The function should then use these values
cam 0:0453a0a7e500 284 * to update the application register values.
cam 0:0453a0a7e500 285 */
cam 0:0453a0a7e500 286
cam 0:0453a0a7e500 287 /*! \ingroup modbus_registers
cam 0:0453a0a7e500 288 * \brief Callback function used if the value of a <em>Input Register</em>
cam 0:0453a0a7e500 289 * is required by the protocol stack. The starting register address is given
cam 0:0453a0a7e500 290 * by \c usAddress and the last register is given by <tt>usAddress +
cam 0:0453a0a7e500 291 * usNRegs - 1</tt>.
cam 0:0453a0a7e500 292 *
cam 0:0453a0a7e500 293 * \param pucRegBuffer A buffer where the callback function should write
cam 0:0453a0a7e500 294 * the current value of the modbus registers to.
cam 0:0453a0a7e500 295 * \param usAddress The starting address of the register. Input registers
cam 0:0453a0a7e500 296 * are in the range 1 - 65535.
cam 0:0453a0a7e500 297 * \param usNRegs Number of registers the callback function must supply.
cam 0:0453a0a7e500 298 *
cam 0:0453a0a7e500 299 * \return The function must return one of the following error codes:
cam 0:0453a0a7e500 300 * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
cam 0:0453a0a7e500 301 * Modbus response is sent.
cam 0:0453a0a7e500 302 * - eMBErrorCode::MB_ENOREG If the application can not supply values
cam 0:0453a0a7e500 303 * for registers within this range. In this case a
cam 0:0453a0a7e500 304 * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
cam 0:0453a0a7e500 305 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
cam 0:0453a0a7e500 306 * currently not available and the application dependent response
cam 0:0453a0a7e500 307 * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
cam 0:0453a0a7e500 308 * exception is sent as a response.
cam 0:0453a0a7e500 309 * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
cam 0:0453a0a7e500 310 * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
cam 0:0453a0a7e500 311 */
cam 0:0453a0a7e500 312 eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress,
cam 0:0453a0a7e500 313 USHORT usNRegs );
cam 0:0453a0a7e500 314
cam 0:0453a0a7e500 315 /*! \ingroup modbus_registers
cam 0:0453a0a7e500 316 * \brief Callback function used if a <em>Holding Register</em> value is
cam 0:0453a0a7e500 317 * read or written by the protocol stack. The starting register address
cam 0:0453a0a7e500 318 * is given by \c usAddress and the last register is given by
cam 0:0453a0a7e500 319 * <tt>usAddress + usNRegs - 1</tt>.
cam 0:0453a0a7e500 320 *
cam 0:0453a0a7e500 321 * \param pucRegBuffer If the application registers values should be updated the
cam 0:0453a0a7e500 322 * buffer points to the new registers values. If the protocol stack needs
cam 0:0453a0a7e500 323 * to now the current values the callback function should write them into
cam 0:0453a0a7e500 324 * this buffer.
cam 0:0453a0a7e500 325 * \param usAddress The starting address of the register.
cam 0:0453a0a7e500 326 * \param usNRegs Number of registers to read or write.
cam 0:0453a0a7e500 327 * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
cam 0:0453a0a7e500 328 * values should be updated from the values in the buffer. For example
cam 0:0453a0a7e500 329 * this would be the case when the Modbus master has issued an
cam 0:0453a0a7e500 330 * <b>WRITE SINGLE REGISTER</b> command.
cam 0:0453a0a7e500 331 * If the value eMBRegisterMode::MB_REG_READ the application should copy
cam 0:0453a0a7e500 332 * the current values into the buffer \c pucRegBuffer.
cam 0:0453a0a7e500 333 *
cam 0:0453a0a7e500 334 * \return The function must return one of the following error codes:
cam 0:0453a0a7e500 335 * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
cam 0:0453a0a7e500 336 * Modbus response is sent.
cam 0:0453a0a7e500 337 * - eMBErrorCode::MB_ENOREG If the application can not supply values
cam 0:0453a0a7e500 338 * for registers within this range. In this case a
cam 0:0453a0a7e500 339 * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
cam 0:0453a0a7e500 340 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
cam 0:0453a0a7e500 341 * currently not available and the application dependent response
cam 0:0453a0a7e500 342 * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
cam 0:0453a0a7e500 343 * exception is sent as a response.
cam 0:0453a0a7e500 344 * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
cam 0:0453a0a7e500 345 * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
cam 0:0453a0a7e500 346 */
cam 0:0453a0a7e500 347 eMBErrorCode eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress,
cam 0:0453a0a7e500 348 USHORT usNRegs, eMBRegisterMode eMode );
cam 0:0453a0a7e500 349
cam 0:0453a0a7e500 350 /*! \ingroup modbus_registers
cam 0:0453a0a7e500 351 * \brief Callback function used if a <em>Coil Register</em> value is
cam 0:0453a0a7e500 352 * read or written by the protocol stack. If you are going to use
cam 0:0453a0a7e500 353 * this function you might use the functions xMBUtilSetBits( ) and
cam 0:0453a0a7e500 354 * xMBUtilGetBits( ) for working with bitfields.
cam 0:0453a0a7e500 355 *
cam 0:0453a0a7e500 356 * \param pucRegBuffer The bits are packed in bytes where the first coil
cam 0:0453a0a7e500 357 * starting at address \c usAddress is stored in the LSB of the
cam 0:0453a0a7e500 358 * first byte in the buffer <code>pucRegBuffer</code>.
cam 0:0453a0a7e500 359 * If the buffer should be written by the callback function unused
cam 0:0453a0a7e500 360 * coil values (I.e. if not a multiple of eight coils is used) should be set
cam 0:0453a0a7e500 361 * to zero.
cam 0:0453a0a7e500 362 * \param usAddress The first coil number.
cam 0:0453a0a7e500 363 * \param usNCoils Number of coil values requested.
cam 0:0453a0a7e500 364 * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
cam 0:0453a0a7e500 365 * be updated from the values supplied in the buffer \c pucRegBuffer.
cam 0:0453a0a7e500 366 * If eMBRegisterMode::MB_REG_READ the application should store the current
cam 0:0453a0a7e500 367 * values in the buffer \c pucRegBuffer.
cam 0:0453a0a7e500 368 *
cam 0:0453a0a7e500 369 * \return The function must return one of the following error codes:
cam 0:0453a0a7e500 370 * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
cam 0:0453a0a7e500 371 * Modbus response is sent.
cam 0:0453a0a7e500 372 * - eMBErrorCode::MB_ENOREG If the application does not map an coils
cam 0:0453a0a7e500 373 * within the requested address range. In this case a
cam 0:0453a0a7e500 374 * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
cam 0:0453a0a7e500 375 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
cam 0:0453a0a7e500 376 * currently not available and the application dependent response
cam 0:0453a0a7e500 377 * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
cam 0:0453a0a7e500 378 * exception is sent as a response.
cam 0:0453a0a7e500 379 * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
cam 0:0453a0a7e500 380 * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
cam 0:0453a0a7e500 381 */
cam 0:0453a0a7e500 382 eMBErrorCode eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
cam 0:0453a0a7e500 383 USHORT usNCoils, eMBRegisterMode eMode );
cam 0:0453a0a7e500 384
cam 0:0453a0a7e500 385 /*! \ingroup modbus_registers
cam 0:0453a0a7e500 386 * \brief Callback function used if a <em>Input Discrete Register</em> value is
cam 0:0453a0a7e500 387 * read by the protocol stack.
cam 0:0453a0a7e500 388 *
cam 0:0453a0a7e500 389 * If you are going to use his function you might use the functions
cam 0:0453a0a7e500 390 * xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
cam 0:0453a0a7e500 391 *
cam 0:0453a0a7e500 392 * \param pucRegBuffer The buffer should be updated with the current
cam 0:0453a0a7e500 393 * coil values. The first discrete input starting at \c usAddress must be
cam 0:0453a0a7e500 394 * stored at the LSB of the first byte in the buffer. If the requested number
cam 0:0453a0a7e500 395 * is not a multiple of eight the remaining bits should be set to zero.
cam 0:0453a0a7e500 396 * \param usAddress The starting address of the first discrete input.
cam 0:0453a0a7e500 397 * \param usNDiscrete Number of discrete input values.
cam 0:0453a0a7e500 398 * \return The function must return one of the following error codes:
cam 0:0453a0a7e500 399 * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
cam 0:0453a0a7e500 400 * Modbus response is sent.
cam 0:0453a0a7e500 401 * - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
cam 0:0453a0a7e500 402 * In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent
cam 0:0453a0a7e500 403 * as a response.
cam 0:0453a0a7e500 404 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
cam 0:0453a0a7e500 405 * currently not available and the application dependent response
cam 0:0453a0a7e500 406 * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
cam 0:0453a0a7e500 407 * exception is sent as a response.
cam 0:0453a0a7e500 408 * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
cam 0:0453a0a7e500 409 * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
cam 0:0453a0a7e500 410 */
cam 0:0453a0a7e500 411 eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
cam 0:0453a0a7e500 412 USHORT usNDiscrete );
cam 0:0453a0a7e500 413
cam 0:0453a0a7e500 414 #ifdef __cplusplus
cam 0:0453a0a7e500 415 PR_END_EXTERN_C
cam 0:0453a0a7e500 416 #endif
cam 0:0453a0a7e500 417 #endif