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

📄 modbus.h

📁 modbus的c语言版本应用于dos下
💻 H
字号:
/******************************************************************************
*
* (c) 2004 by BECK IPC GmbH
*
*******************************************************************************
*
* Disclaimer: This program is an example and should be used as such.
*             If you wish to use this program or parts of it in your application,
*             you must validate the code yourself. BECK IPC GmbH can not be held
*             responsible for the correct functioning or coding of this example.
*
* Module:     Modbus.h
* Function:   Basic modbus definitions, datatypes, constants
*
*******************************************************************************
*
* $Header: modbus.h, 2, 05.09.2005 10:25:39, Andre Pribil$
*
******************************************************************************/
#ifndef __MODBUS_H__
#define __MODBUS_H__

//------------------------------------------------------------------------------
//Constants
//------------------------------------------------------------------------------
#define MB_TCP_PORT         502    //the default tcp modbus port
#define MB_TCP_MAX_BUF      260    //max size of tcp modbus frame
                                   //7 byte MBAB header + 253 bytes of PDU
#define MB_SER_MAX_BUF      256    // 1 byte slave address + 253 byte of PDU + 2 CRC                             
#define MB_SER_BCAST          0    // broadcast
#define MB_SER_SLAVE_ADDR_MIN 1    //smallest individual slave address
#define MB_SER_SLAVE_ADDR_MAX 247  //largest individual slave address

#define MBAB_SIZE             7     // Header size


#define MB_NO_ERROR           0
#define MB_ERROR             -1
#define MB_TCP_ERROR         -2

//Modbus exception codes, used at exception responses
#define MB_ILLEGAL           0x01   // Illegal function code number
#define MB_ILL_DATA_ADDR     0x02   // Received data address out of range by server
#define MB_ILL_DATA_VAL      0x03   // Not an allowed value for server
#define MB_SERVER_FAILURE    0x04   // Unrecoverable error, occured, when server performs req. action
#define MB_ACK               0x05   // Response to prevent a timeout during long duration of perfom action
#define MB_SERVER_BUSY       0x06   // Server is encaged in processing a long duration command
#define MB_MEMORY_PARITY     0x08   //
#define MB_GW_PATH_UNAVAIL   0x0A   //
#define MB_GW_TARGET_RESP    0x0B   //
#define MB_EXTEND_EXCEPTION  0xFF   // Indicates that the exeception response contains extended exception information
                                    // A subseqeunt two bytes length field inidcates the size of bytes of the
                                    // specific exception information.

//Assigned public function codes
//Bit access
#define MB_RD_COIL_STATE        0x01
#define MB_RD_DISCRETE_INP      0x02
#define MB_FORCE_SINGLE_COIL    0x05
#define MB_FORCE_MULTIPLE_COIL  0x0F
//16-bit word access
#define MB_RD_HOLDING_REG       0x03
#define MB_RD_INPUT_REG         0x04
#define MB_WR_SINGLE_REG        0x06
#define MB_WR_MULTIPLE_REG      0x10
#define MB_MSK_WR_HOLDING_REG   0x16
#define MB_RD_WR_HOLDING_REG    0x17

//serial line only
#define MB_SER_DIAG             0x08
#define MB_SER_GET_COMM_EVT     0x0B
#define MB_SER_GET_COMM_EVT_LOG 0x0C
#define MB_SER_GET_SLAVE_ID     0x11

//File record access
#define MB_RD_FILE_RECORD       0x14   //not supported
#define MB_WR_FILE_RECORD       0x15   //not supported
#define MB_FILE_RECORD_SUBCODE  0x06   //not supported
//Encapsulated device
#define MB_RD_DEV_IDENT         0x2B
//------------------------------------------------------------------------------
#endif /*__MODBUS_H__*/

⌨️ 快捷键说明

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