1、【修改】FreeModbus主机及从机关于线圈及离散输入变量缓冲区的定义,解决了之前在线圈及离散输入不为8的倍数时,缓冲区大小不正确的Bug

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2013-10-17 08:52:39 +08:00
parent 24432b4fee
commit c778f40a6d
2 changed files with 36 additions and 14 deletions

View File

@ -112,8 +112,8 @@ PR_BEGIN_EXTERN_C
/*! \brief If master send a broadcast frame,the master will wait time of convert to delay, /*! \brief If master send a broadcast frame,the master will wait time of convert to delay,
* then master can send other frame */ * then master can send other frame */
#define MB_MASTER_DELAY_MS_CONVERT (200 ) #define MB_MASTER_DELAY_MS_CONVERT (200 )
/*! \brief If master send a frame which is not broadcast,the master will wait sometime for slaver. /*! \brief If master send a frame which is not broadcast,the master will wait sometime for slave.
* And if slaver is not respond in this time,the master will process this timeout error. * And if slave is not respond in this time,the master will process this timeout error.
* Then master can send other frame */ * Then master can send other frame */
#define MB_MASTER_TIMEOUT_MS_RESPOND (2000) #define MB_MASTER_TIMEOUT_MS_RESPOND (2000)
/*! \brief The total slaves in Modbus Master system.Default 16. /*! \brief The total slaves in Modbus Master system.Default 16.

View File

@ -1,25 +1,47 @@
#include "user_mb_app.h" #include "user_mb_app.h"
/* ----------------------- Variables ---------------------------------*/ /*------------------------Slave mode use these variables----------------------*/
//Slave mode use these variables //Slave mode:DiscreteInputs variables
USHORT usSDiscInStart = S_DISCRETE_INPUT_START; USHORT usSDiscInStart = S_DISCRETE_INPUT_START;
UCHAR ucSDiscInBuf[S_DISCRETE_INPUT_NDISCRETES/8]; #if S_DISCRETE_INPUT_NDISCRETES%8
USHORT usSCoilStart = S_COIL_START; UCHAR ucSDiscInBuf[S_DISCRETE_INPUT_NDISCRETES/8+1];
UCHAR ucSCoilBuf[S_COIL_NCOILS/8] ; #else
USHORT usSRegInStart = S_REG_INPUT_START; UCHAR ucSDiscInBuf[S_DISCRETE_INPUT_NDISCRETES/8] ;
USHORT usSRegInBuf[S_REG_INPUT_NREGS] ; #endif
USHORT usSRegHoldStart = S_REG_HOLDING_START; //Slave mode:Coils variables
USHORT usSRegHoldBuf[S_REG_HOLDING_NREGS] ; USHORT usSCoilStart = S_COIL_START;
//Master mode use these variables #if S_COIL_NCOILS%8
UCHAR ucSCoilBuf[S_COIL_NCOILS/8+1] ;
#else
UCHAR ucSCoilBuf[S_COIL_NCOILS/8] ;
#endif
//Slave mode:InputRegister variables
USHORT usSRegInStart = S_REG_INPUT_START;
USHORT usSRegInBuf[S_REG_INPUT_NREGS] ;
//Slave mode:HoldingRegister variables
USHORT usSRegHoldStart = S_REG_HOLDING_START;
USHORT usSRegHoldBuf[S_REG_HOLDING_NREGS] ;
/*-----------------------Master mode use these variables----------------------*/
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0 #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
//Master mode:DiscreteInputs variables
USHORT usMDiscInStart = M_DISCRETE_INPUT_START; USHORT usMDiscInStart = M_DISCRETE_INPUT_START;
#if M_DISCRETE_INPUT_NDISCRETES%8
UCHAR ucMDiscInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_DISCRETE_INPUT_NDISCRETES/8+1];
#else
UCHAR ucMDiscInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_DISCRETE_INPUT_NDISCRETES/8]; UCHAR ucMDiscInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_DISCRETE_INPUT_NDISCRETES/8];
#endif
//Master mode:Coils variables
USHORT usMCoilStart = M_COIL_START; USHORT usMCoilStart = M_COIL_START;
#if M_COIL_NCOILS%8
UCHAR ucMCoilBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_COIL_NCOILS/8+1];
#else
UCHAR ucMCoilBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_COIL_NCOILS/8]; UCHAR ucMCoilBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_COIL_NCOILS/8];
#endif
//Master mode:InputRegister variables
USHORT usMRegInStart = M_REG_INPUT_START; USHORT usMRegInStart = M_REG_INPUT_START;
USHORT usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS]; USHORT usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS];
//Master mode:HoldingRegister variables
USHORT usMRegHoldStart = M_REG_HOLDING_START; USHORT usMRegHoldStart = M_REG_HOLDING_START;
USHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS]; USHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
#endif #endif
//******************************<2A><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>********************************** //******************************<2A><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>**********************************
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )