Modbus RTU/ASCII/TCP with lwip TCP working partial, but with errors (retransmitions)

Dependencies:   EthernetNetIf mbed

Committer:
tmav123
Date:
Mon Dec 05 22:49:02 2011 +0000
Revision:
0:f54e9507171b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tmav123 0:f54e9507171b 1 /*
tmav123 0:f54e9507171b 2 * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
tmav123 0:f54e9507171b 3 * Copyright (c) 2006 Christian Walter <wolti@sil.at>
tmav123 0:f54e9507171b 4 * All rights reserved.
tmav123 0:f54e9507171b 5 *
tmav123 0:f54e9507171b 6 * Redistribution and use in source and binary forms, with or without
tmav123 0:f54e9507171b 7 * modification, are permitted provided that the following conditions
tmav123 0:f54e9507171b 8 * are met:
tmav123 0:f54e9507171b 9 * 1. Redistributions of source code must retain the above copyright
tmav123 0:f54e9507171b 10 * notice, this list of conditions and the following disclaimer.
tmav123 0:f54e9507171b 11 * 2. Redistributions in binary form must reproduce the above copyright
tmav123 0:f54e9507171b 12 * notice, this list of conditions and the following disclaimer in the
tmav123 0:f54e9507171b 13 * documentation and/or other materials provided with the distribution.
tmav123 0:f54e9507171b 14 * 3. The name of the author may not be used to endorse or promote products
tmav123 0:f54e9507171b 15 * derived from this software without specific prior written permission.
tmav123 0:f54e9507171b 16 *
tmav123 0:f54e9507171b 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
tmav123 0:f54e9507171b 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
tmav123 0:f54e9507171b 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
tmav123 0:f54e9507171b 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
tmav123 0:f54e9507171b 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
tmav123 0:f54e9507171b 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
tmav123 0:f54e9507171b 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
tmav123 0:f54e9507171b 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
tmav123 0:f54e9507171b 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
tmav123 0:f54e9507171b 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tmav123 0:f54e9507171b 27 *
tmav123 0:f54e9507171b 28 * File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
tmav123 0:f54e9507171b 29 */
tmav123 0:f54e9507171b 30
tmav123 0:f54e9507171b 31 #ifndef _MB_PROTO_H
tmav123 0:f54e9507171b 32 #define _MB_PROTO_H
tmav123 0:f54e9507171b 33
tmav123 0:f54e9507171b 34 #ifdef __cplusplus
tmav123 0:f54e9507171b 35 PR_BEGIN_EXTERN_C
tmav123 0:f54e9507171b 36 #endif
tmav123 0:f54e9507171b 37 /* ----------------------- Defines ------------------------------------------*/
tmav123 0:f54e9507171b 38 #define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
tmav123 0:f54e9507171b 39 #define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
tmav123 0:f54e9507171b 40 #define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
tmav123 0:f54e9507171b 41 #define MB_FUNC_NONE ( 0 )
tmav123 0:f54e9507171b 42 #define MB_FUNC_READ_COILS ( 1 )
tmav123 0:f54e9507171b 43 #define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
tmav123 0:f54e9507171b 44 #define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
tmav123 0:f54e9507171b 45 #define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
tmav123 0:f54e9507171b 46 #define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
tmav123 0:f54e9507171b 47 #define MB_FUNC_READ_INPUT_REGISTER ( 4 )
tmav123 0:f54e9507171b 48 #define MB_FUNC_WRITE_REGISTER ( 6 )
tmav123 0:f54e9507171b 49 #define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
tmav123 0:f54e9507171b 50 #define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
tmav123 0:f54e9507171b 51 #define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
tmav123 0:f54e9507171b 52 #define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
tmav123 0:f54e9507171b 53 #define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
tmav123 0:f54e9507171b 54 #define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
tmav123 0:f54e9507171b 55 #define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
tmav123 0:f54e9507171b 56 #define MB_FUNC_ERROR ( 128 )
tmav123 0:f54e9507171b 57 /* ----------------------- Type definitions ---------------------------------*/
tmav123 0:f54e9507171b 58 typedef enum
tmav123 0:f54e9507171b 59 {
tmav123 0:f54e9507171b 60 MB_EX_NONE = 0x00,
tmav123 0:f54e9507171b 61 MB_EX_ILLEGAL_FUNCTION = 0x01,
tmav123 0:f54e9507171b 62 MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
tmav123 0:f54e9507171b 63 MB_EX_ILLEGAL_DATA_VALUE = 0x03,
tmav123 0:f54e9507171b 64 MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
tmav123 0:f54e9507171b 65 MB_EX_ACKNOWLEDGE = 0x05,
tmav123 0:f54e9507171b 66 MB_EX_SLAVE_BUSY = 0x06,
tmav123 0:f54e9507171b 67 MB_EX_MEMORY_PARITY_ERROR = 0x08,
tmav123 0:f54e9507171b 68 MB_EX_GATEWAY_PATH_FAILED = 0x0A,
tmav123 0:f54e9507171b 69 MB_EX_GATEWAY_TGT_FAILED = 0x0B
tmav123 0:f54e9507171b 70 } eMBException;
tmav123 0:f54e9507171b 71
tmav123 0:f54e9507171b 72 typedef eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
tmav123 0:f54e9507171b 73
tmav123 0:f54e9507171b 74 typedef struct
tmav123 0:f54e9507171b 75 {
tmav123 0:f54e9507171b 76 UCHAR ucFunctionCode;
tmav123 0:f54e9507171b 77 pxMBFunctionHandler pxHandler;
tmav123 0:f54e9507171b 78 } xMBFunctionHandler;
tmav123 0:f54e9507171b 79
tmav123 0:f54e9507171b 80 #ifdef __cplusplus
tmav123 0:f54e9507171b 81 PR_END_EXTERN_C
tmav123 0:f54e9507171b 82 #endif
tmav123 0:f54e9507171b 83 #endif