modified for nuc472

Dependents:   modbus-over-rs485-sample NTOUEE-mbed-modbus-RTU NuMaker_NuWicam_Lite

Fork of Modbus by Matthew Waddilove

Committer:
giryan
Date:
Sun Aug 22 16:34:20 2010 +0000
Revision:
0:274eb57e1df3

        

Who changed what in which revision?

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