⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myprotocol.h

📁 THIS CODE IS FOR EXAMPLE PURPOSES ONLY, USE AT YOUR OWN RISK, NO WARRANTY IS ASSUMED OR IMPLIED
💻 H
字号:

#include "netBufLib.h"

#define MODBUS_MAX_PBU	253
/* implimentation specific address extention byte */
#define MODBUS_REQUEST  1
#define MODBUS_REPLY   2

#define NUMBER_OF_INPUTS		100	/* 1 Bit read only */
#define NUMBER_OF_COILS			100	/* 1 Bit read/write */
#define NUMBER_OF_INPUT_REGISTERS	100    	/* 16 Bit read only */
#define NUMBER_OF_HOLDING_REGISTERS	100	/* 16 Bit read/write */

/* standard modbus message types */
#define MODBUS_Read_Coils			(0x01) 
#define MODBUS_Read_Discrete_Inputs 		(0x02) 
#define MODBUS_Read_Holding_Registers  		(0x03) 
#define MODBUS_Read_Input_Registers  		(0x04) 
#define MODBUS_Write_Single_Coil 		(0x05) 
#define MODBUS_Write_Single_Register  		(0x06)
#define MODBUS_Write_Multiple_Coils 		(0x0F) 
#define MODBUS_Write_Multiple_registers 	(0x10)
#define MODBUS_Read_File_Record  		(0x14)
#define MODBUS_Mask_Write_Register  		(0x16)
#define MODBUS_Read_Write_Multiple_registers 	(0x17) 
#define MODBUS_Read_Device_Identification 	(0x2B)
#define MODBUS_ERROR   0x80

/*
this structure hold transaction details
this implementation supports a single transaction
per interface, but a robust implementation would support 
many simultaneous transactions per interface and this 
structure would need to be indexed differently
*/

typedef struct modbus_proto_ctrl {      /* MODBUS_PROTO_CTRL */
    void  * pCookie;                     /* identifies net device attachment */
    int   mtuSize;                       /* Max device frame size */
    int   bufferSize;                       /* Max device frame size */
    uchar_t * pBuffer;                       /* pointer to temporary buffer */
    BOOL  busy;                          /* temporary buffer in use */ 
    uchar_t returnAddress[30];                  /* return Address (6 chars for ethernet)   */  
 } MODBUS_PROTO_CTRL;

/* most function types use use only begining of header */

typedef struct modbus_hdr {      /* MODBUS_HEADER */
    uchar_t  type;                /* MODBUS_REQUEST or MODBUS_REPLY, */
                                  /* implimentation specific address extension */
    uchar_t  function;                   /* message type, start of standard modbus PDU */
    ushort_t address;                    /* start address */
    union
	{
    	uchar_t rBytes;                     /* number of bytes returned */
    	ushort_t size;                       /* number of data points */
    	ushort_t data;                       /* single data point */
	} u;
    uchar_t  bytes;                      /* size of data */ 
 } MODBUS_HEADER;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -