#ifndef __MODBUSTCP_H #define __MODBUSTCP_H // I removed these includes because I've tinkered with the project structure- // they may need to be re-included........ //#include "TCPIPConfig.h" //#include "tcpip/tcpip.h" // Defines which port the server will listen on #define MODBUS_PORT 502 //Define for buffer size - these sizes are specific for my application #define HOLDING_REG_SIZE 15 #define INPUT_REG_SIZE 3 //#define MODBUS_RX_BUFFER_SIZE 50 #define MODBUS_RX_BUFFER_SIZE 256 // increased, as we need to receive multiple file record requests in one message //#define MODBUS_TX_BUFFER_SIZE 50 #define MODBUS_TX_BUFFER_SIZE 256 // increased, as we need to output file records #define COIL_SIZE_BUFFER_BYTES 1 #define COIL_SIZE_BUFFER_BITS 3 #define COIL_BIT_MASK 0x07 #define DISCRETE_INPUT_SIZE 5 //Modbus Functions #define ReadCoil 1 #define ReadDiscreteInputs 2 #define ReadHoldingRegister 3 #define ReadInputRegister 4 #define WriteSingleCoil 5 #define WriteSingleRegister 6 #define WriteMultipleCoils 15 #define WriteMultipleRegister 16 #define ReadFileRecord 20 //Modbus Errors #define Illegal_Function_Code 0x01u #define Illegal_Data_Address 0x02u #define Illegal_Data_Value 0x03u //Position of the data in the frame #define MODBUS_UnitID 6 #define MODBUS_FunctionCode 7 #define MODBUS_DataStart 13 #define MODBUS_ExceptionCode 8 //number of words available for READ HOLDING REGISTER #define MAX_REG_SIZE 50u //is it same as HOLDING REG SIZE typedef struct { uint8 Val; uint8 Addr; } WORD_VAL1, WORD_BITS1; //Modbus command structure typedef struct { uint16 TransactionID; //Transaction ID uint16 ProtocolID; //Protocol ID uint16 Length; //Length uint8 UnitID; //Unit ID uint8 FunctionCode; //Function code uint16 StartAddress; //Starting register address uint16 NumberOfRegister; //Number of registers } _MODBUS_COMMAND; //MODBUS_COMMAND _MODBUS_COMMAND MODBUS_COMMAND; //Function Prototypes.....omitted for this post... void MODBUSTCPServer(void); // etc // etc #endif