标签:
无标签
Detailed Description详细描述
This module defines the interface for the application. It contains the basic functions and types required to use the Modbus protocol stack. A typical application will want to call eMBInit() first. If the device is ready to answer network requests it must then call eMBEnable() to activate the protocol stack. In the main loop the function eMBPoll() must be called periodically. The time interval between pooling depends on the configured Modbus timeout. If an RTOS is available a separate task should be created and the task should always call the function eMBPoll().
这个模块为应用定义了接口。它包括了使用Modbus协议栈所必须的基本功能函数和类型。一个典型的应用程序将会首先调用eMBInit()函数。如果该设备需要回应网络请求,则其必须调用eMBEnable()函数来激活协议栈。在主循环中,函数eMBPoll()将会被周期性调用。两次调用的时间间隔决定于Modbus的超时时间设置。如果使用了RTOS,用户则必须创建一个独立的任务,并且该任务必须一直调用函数eMBPoll()。
|
|
|
Defines定义 |
|
#define |
MB_TCP_PORT_USE_DEFAULT 0 |
|
Enumerations枚举类型 |
|
enum |
eMBMode { MB_RTU, MB_ASCII, MB_TCP }
Modbus协议的模式:RTU ,ASCII 和TCP |
|
enum |
eMBRegisterMode { MB_REG_READ, MB_REG_WRITE }
Modbus寄存器的模式:READ和WRITE |
|
enum |
eMBErrorCode { MB_ENOERR, MB_ENOREG, MB_EINVAL, MB_EPORTERR, MB_ENORES, MB_EIO, MB_EILLSTATE, MB_ETIMEDOUT }
错误码:没有错误,没有寄存器,无效, , ,IO错误,无效 ,超时 |
|
enum |
eMBParity { MB_PAR_NONE, MB_PAR_ODD, MB_PAR_EVEN }
Modbus数据帧的校验类型:无校验,偶校验,奇校验 |
|
Functions函数 |
|
eMBErrorCode |
eMBInit (eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity)
协议初始化函数
输入参数:
eMBMode eMode, Modubus协议模式
UCHAR ucSlaveAddress, 子模块地址
UCHAR ucPort, 端口
ULONG ulBaudRate, 波特率
eMBParity eParity 串行数据的奇偶校验 |
|
eMBErrorCode |
eMBTCPInit (USHORT usTCPPort)
如果使用了TCP协议,则用该函数进行初始化 |
|
eMBErrorCode |
eMBClose (void)
关闭Modbus协议栈 |
|
eMBErrorCode |
eMBEnable (void)
使能Modbus协议栈 |
|
eMBErrorCode |
eMBDisable (void)
禁止Modbus协议栈 |
|
eMBErrorCode |
eMBPoll (void)
周期性调用的协议处理函数 |
|
eMBErrorCode |
eMBSetSlaveID (UCHAR ucSlaveID, BOOL xIsRunning, UCHAR const *pucAdditional, USHORT usAdditionalLen)
设置子模块ID
输入参数:
UCHAR ucSlaveID, 子模块ID
BOOL xIsRunning,
UCHAR const *pucAdditional,
USHORT usAdditionalLen |
|
eMBErrorCode |
eMBRegisterCB (UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler)
Modbus协议的寄存器回调函数
输入参数:
UCHAR ucFunctionCode, 功能码
pxMBFunctionHandler pxHandler功能码对应的处理函数 |
Define Documentation文档
|
#define MB_TCP_PORT_USE_DEFAULT 0 |
|
Enumeration Type Documentation枚举类型定义
|
|
Modbus serial transmission modes (RTU/ASCII).
Modubs串行传输模式
Modbus serial supports two transmission modes. Either ASCII or RTU. RTU is faster but has more hardware requirements and requires a network with a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
Modbus串行传输支持两种模式,ASCII或者是RTU。RTU模式较快但是具有较高的硬件要求并且要求网络延迟要低。ASCII模式较慢,但是在低速连接中更加可靠(如moderms)。
Enumeration values:
|
MB_RTU |
RTU transmission mode. RTU传输模式 |
|
MB_ASCII |
ASCII transmission mode. ASCII传输模式 |
|
MB_TCP |
TCP mode. TCP模式 |
|
|
|
Parity used for characters in serial mode.
串行模式中字符的极性
The parity which should be applied to the characters sent over the serial link. Please note that this values are actually passed to the porting layer and therefore not all parity modes might be available.
串行字符传输时应用的校验格式。需要注意,这个值其实是传给移植层,并且不是所有的奇偶模式都能有效。
Enumeration values:
|
MB_PAR_NONE |
No parity. 无奇偶校验 |
|
MB_PAR_ODD |
Odd parity. 偶校验 |
|
MB_PAR_EVEN |
Even parity. 奇校验 |
|
|
|
If register should be written or read.
寄存器是读还是写
This value is passed to the callback functions which support either reading or writing register values. Writing means that the application registers should be updated and reading means that the modbus protocol stack needs to know the current register values.
值将传给支持读或者写寄存器的回调函数。写意味着应用寄存器更新,读表示Modbus协议栈需要知道当前寄存器的数值。
See also:
eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and eMBRegInputCB( ).
Enumeration values:
|
MB_REG_READ |
Read register values and pass to protocol stack. 读寄存器数值并且传给协议栈 |
|
MB_REG_WRITE |
Update register values. 更新寄存器数值 |
Examples:
AT91SAM7X_ROWLEY/demo.c, AVR/demo.c, LINUX/demo.c, MCF5235/demo.c, MCF5235TCP/demo.c, MSP430/demo.c, STR71X/simple2.c, STR71XTCP/demo.c, WIN32/demo.cpp, and WIN32TCP/demo.cpp. |
Function Documentation
|
|
Release resources used by the protocol stack.
释放协议栈使用的资源。
This function disables the Modbus protocol stack and release all hardware resources. It must only be called when the protocol stack is disabled.
该函数禁止 |