Skip to content

Commit

Permalink
fix the mistake of calling modbus API before T35 timer complate initi…
Browse files Browse the repository at this point in the history
…alization
  • Loading branch information
ericQiang committed Aug 21, 2018
1 parent fcc2228 commit 9a3a505
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions FreeModbus/modbus/include/mb_m.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
22 changes: 19 additions & 3 deletions FreeModbus/modbus/mb_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +234,7 @@ eMBMasterDisable( void )
{
eMBErrorCode eStatus;

if( eMBState == STATE_ENABLED )
if(( eMBState == STATE_ENABLED ) || ( eMBState == STATE_ESTABLISHED))
{
pvMBMasterFrameStopCur( );
eMBState = STATE_DISABLED;
Expand All @@ -250,6 +251,20 @@ eMBMasterDisable( void )
return eStatus;
}

BOOL
eMBMasterIsEstablished( void )
{
if(eMBState == STATE_ESTABLISHED)
{
return TRUE;
}
else
{
return FALSE;
}
}


eMBErrorCode
eMBMasterPoll( void )
{
Expand All @@ -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;
}
Expand All @@ -277,6 +292,7 @@ eMBMasterPoll( void )
switch ( eEvent )
{
case EV_MASTER_READY:
eMBState = STATE_ESTABLISHED;
break;

case EV_MASTER_FRAME_RECEIVED:
Expand Down

0 comments on commit 9a3a505

Please sign in to comment.