Merge pull request #29 from ericQiang/master

fix the mistake of calling modbus API before T35 timer complate initi…
This commit is contained in:
朱天龙 (Armink) 2018-08-22 11:47:46 +08:00 committed by GitHub
commit 38e8bd2453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 15 deletions

View File

@ -172,6 +172,18 @@ eMBErrorCode eMBMasterEnable( void );
*/
eMBErrorCode eMBMasterDisable( void );
/*! \ingroup modbus
* \brief Check the Modbus Master protocol stack has established or not.
*
* This function must be called and check the return value before calling
* any other functions.
*
* \return If the protocol stack has been established or not
* TRUE. the protocol stack has established
* FALSE. the protocol stack hasn't established
*/
BOOL eMBMasterIsEstablished( void );
/*! \ingroup modbus
* \brief The main pooling loop of the Modbus Master protocol stack.
*

View File

@ -71,7 +71,8 @@ static enum
{
STATE_ENABLED,
STATE_DISABLED,
STATE_NOT_INITIALIZED
STATE_NOT_INITIALIZED,
STATE_ESTABLISHED,
} eMBState = STATE_NOT_INITIALIZED;
/* Functions pointer which are initialized in eMBInit( ). Depending on the
@ -233,7 +234,7 @@ eMBMasterDisable( void )
{
eMBErrorCode eStatus;
if( eMBState == STATE_ENABLED )
if(( eMBState == STATE_ENABLED ) || ( eMBState == STATE_ESTABLISHED))
{
pvMBMasterFrameStopCur( );
eMBState = STATE_DISABLED;
@ -250,6 +251,20 @@ eMBMasterDisable( void )
return eStatus;
}
BOOL
eMBMasterIsEstablished( void )
{
if(eMBState == STATE_ESTABLISHED)
{
return TRUE;
}
else
{
return FALSE;
}
}
eMBErrorCode
eMBMasterPoll( void )
{
@ -265,7 +280,7 @@ eMBMasterPoll( void )
eMBMasterErrorEventType errorType;
/* Check if the protocol stack is ready. */
if( eMBState != STATE_ENABLED )
if(( eMBState != STATE_ENABLED ) && ( eMBState != STATE_ESTABLISHED))
{
return MB_EILLSTATE;
}
@ -277,21 +292,22 @@ eMBMasterPoll( void )
switch ( eEvent )
{
case EV_MASTER_READY:
eMBState = STATE_ESTABLISHED;
break;
case EV_MASTER_FRAME_RECEIVED:
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
/* Check if the frame is for us. If not ,send an error process event. */
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
{
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
}
else
{
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
}
break;
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
/* Check if the frame is for us. If not ,send an error process event. */
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
{
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
}
else
{
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
}
break;
case EV_MASTER_EXECUTE:
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];