Lines Matching full:the

7  * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 * This module defines the interface for the application. It contains
47 * the basic functions and types required to use the Modbus protocol stack.
48 * A typical application will want to call eMBInit() first. If the device
50 * the protocol stack. In the main loop the function eMBPoll() must be called
51 * periodically. The time interval between pooling depends on the configured
53 * and the task should always call the function eMBPoll().
58 * // Enable the Modbus Protocol Stack.
62 * // Call the main polling loop of the Modbus protocol stack.
72 * \brief Use the default Modbus TCP port (502)
95 * This value is passed to the callback functions which support either
96 * reading or writing register values. Writing means that the application
97 * registers should be updated and reading means that the modbus protocol
98 * stack needs to know the current register values.
110 * \brief Errorcodes used by all function in the protocol stack.
127 * \brief Initialize the Modbus protocol stack.
129 * This functions initializes the ASCII or RTU module and calls the
130 * init functions of the porting layer to prepare the hardware. Please
131 * note that the receiver is still disabled and no Modbus frames are
135 * \param ucSlaveAddress The slave address. Only frames sent to this
136 * address or to the broadcast address are processed.
137 * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
139 * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
140 * on the porting layer.
143 * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
144 * The protocol is then in the disabled state and ready for activation
145 * by calling eMBEnable( ). Otherwise one of the following error codes
147 * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
148 * slave addresses are in the range 1 - 247.
149 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
155 * \brief Initialize the Modbus protocol stack for Modbus TCP.
157 * This function initializes the Modbus TCP Module. Please note that
160 * \param usTCPPort The TCP port to listen on.
161 * \return If the protocol stack has been initialized correctly the function
162 * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
164 * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
165 * slave addresses are in the range 1 - 247.
166 * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
171 * \brief Release resources used by the protocol stack.
173 * This function disables the Modbus protocol stack and release all
174 * hardware resources. It must only be called when the protocol stack
178 * get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
180 * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
181 * If the protocol stack is not in the disabled state it returns
187 * \brief Enable the Modbus protocol stack.
189 * This function enables processing of Modbus frames. Enabling the protocol
190 * stack is only possible if it is in the disabled state.
192 * \return If the protocol stack is now in the state enabled it returns
193 * eMBErrorCode::MB_ENOERR. If it was not in the disabled state it
199 * \brief Disable the Modbus protocol stack.
203 * \return If the protocol stack has been disabled it returns
204 * eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
210 * \brief The main pooling loop of the Modbus protocol stack.
212 * This function must be called periodically. The timer interval required
213 * is given by the application dependent Modbus slave timeout. Internally the
214 * function calls xMBPortEventGet() and waits for an event from the receiver or
217 * \return If the protocol stack is not in the enabled state the function
224 * \brief Configure the slave id of the device.
226 * This function should be called when the Modbus function <em>Report Slave ID</em>
229 * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
231 * \param xIsRunning If TRUE the <em>Run Indicator Status</em> byte is set to 0xFF.
232 * otherwise the <em>Run Indicator Status</em> is 0x00.
233 * \param pucAdditional Values which should be returned in the <em>Additional</em>
234 * bytes of the <em> Report Slave ID</em> response.
235 * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
237 * \return If the static buffer defined by MB_FUNC_OTHER_REP_SLAVEID_BUF in
249 * The callback handler supplied is responsible for interpreting the Modbus PDU and
250 * the creation of an appropriate response. In case of an error it should return
251 * one of the possible Modbus exceptions which results in a Modbus exception frame
252 * sent by the protocol stack.
254 * \param ucFunctionCode The Modbus function code for which this handler should
255 * be registers. Valid function codes are in the range 1 to 127.
256 * \param pxHandler The function handler which should be called in case
260 * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
262 * case the values in mbconfig.h should be adjusted. If the argument was not
272 * The protocol stack does not internally allocate any memory for the
273 * registers. This makes the protocol stack very small and also usable on
274 * low end targets. In addition the values don't have to be in the memory
276 * Whenever the protocol stack requires a value it calls one of the callback
277 * function with the register address and the number of registers to read
278 * as an argument. The application should then read the actual register values
279 * (for example the ADC voltage) and should store the result in the supplied
281 * If the protocol stack wants to update a register value because a write
282 * register function was received a buffer with the new register values is
283 * passed to the callback function. The function should then use these values
284 * to update the application register values.
288 * \brief Callback function used if the value of a <em>Input Register</em>
289 * is required by the protocol stack. The starting register address is given
290 * by \c usAddress and the last register is given by <tt>usAddress +
293 * \param pucRegBuffer A buffer where the callback function should write
294 * the current value of the modbus registers to.
295 * \param usAddress The starting address of the register. Input registers
296 * are in the range 1 - 65535.
297 * \param usNRegs Number of registers the callback function must supply.
299 * \return The function must return one of the following error codes:
302 * - eMBErrorCode::MB_ENOREG If the application can not supply values
305 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
306 * currently not available and the application dependent response
317 * read or written by the protocol stack. The starting register address
318 * is given by \c usAddress and the last register is given by
321 * \param pucRegBuffer If the application registers values should be updated the
322 * buffer points to the new registers values. If the protocol stack needs
323 * to now the current values the callback function should write them into
325 * \param usAddress The starting address of the register.
327 * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
328 * values should be updated from the values in the buffer. For example
329 * this would be the case when the Modbus master has issued an
331 * If the value eMBRegisterMode::MB_REG_READ the application should copy
332 * the current values into the buffer \c pucRegBuffer.
334 * \return The function must return one of the following error codes:
337 * - eMBErrorCode::MB_ENOREG If the application can not supply values
340 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
341 * currently not available and the application dependent response
352 * read or written by the protocol stack. If you are going to use
353 * this function you might use the functions xMBUtilSetBits( ) and
356 * \param pucRegBuffer The bits are packed in bytes where the first coil
357 * starting at address \c usAddress is stored in the LSB of the
358 * first byte in the buffer <code>pucRegBuffer</code>.
359 * If the buffer should be written by the callback function unused
362 * \param usAddress The first coil number.
364 * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
365 * be updated from the values supplied in the buffer \c pucRegBuffer.
366 * If eMBRegisterMode::MB_REG_READ the application should store the current
367 * values in the buffer \c pucRegBuffer.
369 * \return The function must return one of the following error codes:
372 * - eMBErrorCode::MB_ENOREG If the application does not map an coils
373 * within the requested address range. In this case a
375 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
376 * currently not available and the application dependent response
387 * read by the protocol stack.
389 * If you are going to use his function you might use the functions
392 * \param pucRegBuffer The buffer should be updated with the current
393 * coil values. The first discrete input starting at \c usAddress must be
394 * stored at the LSB of the first byte in the buffer. If the requested number
395 * is not a multiple of eight the remaining bits should be set to zero.
396 * \param usAddress The starting address of the first discrete input.
398 * \return The function must return one of the following error codes:
404 * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
405 * currently not available and the application dependent response