mirror of
https://github.com/armink/FreeModbus_Slave-Master-RTT-STM32.git
synced 2025-02-28 03:47:00 +08:00
clear specific events before modbus master operation.
Next modbus ops may failed if we received some data before operation starting. Signed-off-by: Xia Haiqiang <xiahaiqiang@chinayuanwang.com>
This commit is contained in:
parent
29ae0afb3b
commit
437c9ace46
@ -94,6 +94,7 @@ eMBMasterReqReadCoils( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usNCoils ,LONG
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_COILS;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_COILS;
|
||||||
@ -201,6 +202,7 @@ eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LO
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_SINGLE_COIL;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_SINGLE_COIL;
|
||||||
@ -297,6 +299,7 @@ eMBMasterReqWriteMultipleCoils( UCHAR ucSndAddr,
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_COILS;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_COILS;
|
||||||
|
@ -79,6 +79,7 @@ eMBMasterReqReadDiscreteInputs( UCHAR ucSndAddr, USHORT usDiscreteAddr, USHORT u
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_DISCRETE_INPUTS;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_DISCRETE_INPUTS;
|
||||||
|
@ -106,6 +106,7 @@ eMBMasterReqWriteHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usRe
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_REGISTER;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_REGISTER;
|
||||||
@ -177,6 +178,7 @@ eMBMasterReqWriteMultipleHoldingRegister( UCHAR ucSndAddr,
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_REGISTERS;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_REGISTERS;
|
||||||
@ -271,6 +273,7 @@ eMBMasterReqReadHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRe
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_HOLDING_REGISTER;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_HOLDING_REGISTER;
|
||||||
@ -366,6 +369,7 @@ eMBMasterReqReadWriteMultipleHoldingRegister( UCHAR ucSndAddr,
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
|
||||||
|
@ -79,6 +79,7 @@ eMBMasterReqReadInputRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs
|
|||||||
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
eMBMasterEventClear();
|
||||||
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
vMBMasterGetPDUSndBuf(&ucMBFrame);
|
||||||
vMBMasterSetDestAddress(ucSndAddr);
|
vMBMasterSetDestAddress(ucSndAddr);
|
||||||
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_INPUT_REGISTER;
|
ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_INPUT_REGISTER;
|
||||||
|
@ -405,6 +405,7 @@ BOOL xMBMasterRequestIsBroadcast( void );
|
|||||||
eMBMasterErrorEventType eMBMasterGetErrorType( void );
|
eMBMasterErrorEventType eMBMasterGetErrorType( void );
|
||||||
void vMBMasterSetErrorType( eMBMasterErrorEventType errorType );
|
void vMBMasterSetErrorType( eMBMasterErrorEventType errorType );
|
||||||
eMBMasterReqErrCode eMBMasterWaitRequestFinish( void );
|
eMBMasterReqErrCode eMBMasterWaitRequestFinish( void );
|
||||||
|
void eMBMasterEventClear( void );
|
||||||
|
|
||||||
/* ----------------------- Callback -----------------------------------------*/
|
/* ----------------------- Callback -----------------------------------------*/
|
||||||
|
|
||||||
|
@ -236,4 +236,21 @@ eMBMasterReqErrCode eMBMasterWaitRequestFinish( void ) {
|
|||||||
return eErrStatus;
|
return eErrStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used for clear all events at last modbus operation.
|
||||||
|
* @note If you are use OS, you can use OS's event mechanism. Otherwise you have to run
|
||||||
|
* much user custom delay for waiting.
|
||||||
|
*/
|
||||||
|
void eMBMasterEventClear( void )
|
||||||
|
{
|
||||||
|
rt_uint32_t recvedEvent;
|
||||||
|
|
||||||
|
rt_event_recv(&xMasterOsEvent,
|
||||||
|
EV_MASTER_PROCESS_SUCESS | EV_MASTER_ERROR_RESPOND_TIMEOUT
|
||||||
|
| EV_MASTER_ERROR_RECEIVE_DATA
|
||||||
|
| EV_MASTER_ERROR_EXECUTE_FUNCTION,
|
||||||
|
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO,
|
||||||
|
&recvedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user