Modbus的寄存器
详细描述
The protocol stack does not internally allocate any memory for the registers. This makes the protocol stack very small and also usable on low end targets. In addition the values don't have to be in the memory and could for example be stored in a flash.
Whenever the protocol stack requires a value it calls one of the callback function with the register address and the number of registers to read as an argument. The application should then read the actual register values (for example the ADC voltage) and should store the result in the supplied buffer.
If the protocol stack wants to update a register value because a write register function was received a buffer with the new register values is passed to the callback function. The function should then use these values to update the application register values.
协议栈不在内部为寄存器分配空间。这就使得协议栈非常小并且适用于低端目标应用。并且Modbus寄存器的值不一定存储在内存中,而是可以存储在如flash之类的存储器中。当协议栈需要获取数值是,它通过调用回调函数来实现,该回调函数以寄存器地址和数量作为参数。应用程序将读实际的寄存器数值(如ADC电压),并且存储在特定的缓冲区中。
如果协议栈收到了一个写寄存器命令,将会执行寄存器更新操作,一个包含新寄存器数值的缓冲区会传给回调函数。这个回调函数将用这些值来更新应用寄存器数值。
| |
Functions功能函数 | |
eMBRegInputCB (UCHAR *pucRegBuffer, USHORT usAddress, USHORT usNRegs) 输入寄存器回调函数 | |
eMBRegHoldingCB (UCHAR *pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode) 保持寄存器回调函数 | |
eMBRegCoilsCB (UCHAR *pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode) 线圈状态寄存器回调函数 | |
eMBRegDiscreteCB (UCHAR *pucRegBuffer, USHORT usAddress, USHORT usNDiscrete) 离散寄存器回调函数 |
|
| Callback function used if a Coil Register value is read or written by the protocol stack. If you are going to use this function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields. 如果协议栈需要对线圈状态寄存器进行读写,则需要调用回调函数。如果用户用到这个功能,用户可能用到xMBUtilSetBits( ) 和 xMBUtilGetBits( ) 来处理位域。 Parameters: 参数
Returns: 返回 The function must return one of the following error codes: 这个函数将返回如下的错误码: · eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal Modbus response is sent. eMBErrorCode::MB_ENOERR如果没有错误发生。在这种情况下,发送一个正常的Modbus应答。 · eMBErrorCode::MB_ENOREG If the application does not map an coils within the requested address range. In this case a ILLEGAL DATA ADDRESS is sent as a response. eMBErrorCode::MB_ENOREG如果请求的地址范围中没有线圈状态寄存器,在这种情况下,发送一个ILLEGAL DATA ADDRESS应答。 · eMBErrorCode::MB_ETIMEDOUT If the requested register block is currently not available and the application dependent response timeout would be violated. In this case a SLAVE DEVICE BUSY exception is sent as a response. eMBErrorCode::MB_ETIMEDOUT如果请求的寄存器区当前无效,并且应用相关的应当超时。这种情况下,发送一个SLAVE DEVICE BUSY应答。 · eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case a SLAVE DEVICE FAILURE exception is sent as a response. eMBErrorCode::MB_EIO 如果一个其他错误发生。在这种情况下,发送一个SLAVE DEVICE FAILURE应答。 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. |
|
| Callback function used if a Input Discrete Register value is read by the protocol stack. If you are going to use his function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields. Parameters:
Returns: The function must return one of the following error codes: 这个函数将返回如下的错误码: · eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal Modbus response is sent. eMBErrorCode::MB_ENOERR如果没有错误发生。在这种情况下,发送一个正常的Modbus应答。 · eMBErrorCode::MB_ENOREG If no such discrete inputs exists. In this case a ILLEGAL DATA ADDRESS exception frame is sent as a response. eMBErrorCode::MB_ENOREG如果请求的地址范围中没有这种离散输入寄存器,在这种情况下,发送一个ILLEGAL DATA ADDRESS应答。 · eMBErrorCode::MB_ETIMEDOUT If the requested register block is currently not available and the application dependent response timeout would be violated. In this case a SLAVE DEVICE BUSY exception is sent as a response. eMBErrorCode::MB_ETIMEDOUT如果请求的寄存器区当前无效,并且应用相关的应当超时。这种情况下,发送一个SLAVE DEVICE BUSY应答。 · eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case a SLAVE DEVICE FAILURE exception is sent as a response. eMBErrorCode::MB_EIO如果一个其他错误发生。在这种情况下,发送一个SLAVE DEVICE FAILURE应答。 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. |
|
| Callback function used if a Holding Register value is read or written by the protocol stack. The starting register address is given by 如果协议栈需要对保持寄存器数值进行读写,将用到这个回调函数。通过 Parameters: 参数
Returns: The function must return one of the following error codes: 这个函数将返回如下的错误码: · eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal Modbus response is sent. eMBErrorCode::MB_ENOERR如果没有错误发生。在这种情况下,发送一个正常的Modbus应答。 · eMBErrorCode::MB_ENOREG If the application can not supply values for registers within this range. In this case a ILLEGAL DATA ADDRESS exception frame is sent as a response. eMBErrorCode::MB_ENOREG如果请求的地址范围中没有寄存器,在这种情况下,发送一个ILLEGAL DATA ADDRESS应答。 · eMBErrorCode::MB_ETIMEDOUT If the requested register block is currently not available and the application dependent response timeout would be violated. In this case a SLAVE DEVICE BUSY exception is sent as a response. eMBErrorCode::MB_ETIMEDOUT如果请求的寄存器区当前无效,并且应用相关的应当超时。这种情况下,发送一个SLAVE DEVICE BUSY应答。 · eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case a SLAVE DEVICE FAILURE exception is sent as a response. eMBErrorCode::MB_EIO如果一个其他错误发生。在这种情况下,发送一个SLAVE DEVICE FAILURE应答。 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. |
|
| Callback function used if the value of a Input Register is required by the protocol stack. The starting register address is given by 如果协议栈需要对输入寄存器进行操作,需要用到这个回调函数。起始寄存器的地址由usAddress给出,最后一个寄存器的地址是 Parameters: 参数
Returns: 返回 The function must return one of the following error codes: 这个函数将返回如下的错误码: · eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal Modbus response is sent. eMBErrorCode::MB_ENOERR如果没有错误发生。在这种情况下,发送一个正常的Modbus应答。 · eMBErrorCode::MB_ENOREG If the application can not supply values for registers within this range. In this case a ILLEGAL DATA ADDRESS exception frame is sent as a response. eMBErrorCode::MB_ENOREG如果请求的地址范围中没有寄存器,在这种情况下,发送一个ILLEGAL DATA ADDRESS应答。 · eMBErrorCode::MB_ETIMEDOUT If the requested register block is currently not available and the application dependent response timeout would be violated. In this case a SLAVE DEVICE BUSY exception is sent as a response. eMBErrorCode::MB_ETIMEDOUT如果请求的寄存器区当前无效,并且应用相关的应当超时。这种情况下,发送一个SLAVE DEVICE BUSY应答。 · eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case a SLAVE DEVICE FAILURE exception is sent as a response. eMBErrorCode::MB_EIO如果一个其他错误发生。在这种情况下,发送一个SLAVE DEVICE FAILURE应答。 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. |
文章评论(0条评论)
登录后参与讨论