4
0
mirror of https://github.com/armink/FreeModbus_Slave-Master-RTT-STM32.git synced 2025-02-20 23:36:59 +08:00

1、【增加】FreeModbus主机轮训事件方法,错误处理事件具体内容后期补充;

2、【更新】FreeModbus主机文件框架,使其更加合理;
3、【更新】IAR及Keil工程代码架构

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2013-08-20 13:07:51 +08:00
parent dfe745c166
commit c1520d3634
12 changed files with 1411 additions and 1116 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1886,64 +1886,82 @@
</file>
</group>
<group>
<name>FreeModbusSlaver</name>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\mb.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbcrc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfunccoils.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncdiag.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncdisc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncholding.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncinput.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncother.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbrtu.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbrtu_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbutils.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\port.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portevent.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portevent_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portserial.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portserial_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\porttimer.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\porttimer_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\user_app_s.c</name>
</file>
<name>FreeModbusMaster</name>
<group>
<name>Modbus</name>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\mb_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbrtu_m.c</name>
</file>
</group>
<group>
<name>Port</name>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portevent_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portserial_m.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\porttimer_m.c</name>
</file>
</group>
</group>
<group>
<name>FreeModbusSlave</name>
<group>
<name>Modbus</name>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\mb.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbcrc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfunccoils.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncdiag.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncdisc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncholding.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncinput.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbfuncother.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\rtu\mbrtu.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\modbus\functions\mbutils.c</name>
</file>
</group>
<group>
<name>Port</name>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\port.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portevent.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\portserial.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\porttimer.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\FreeModbus\port\user_app_s.c</name>
</file>
</group>
</group>
<group>
<name>RT-Thread Kernel</name>

View File

@ -17,7 +17,7 @@
<Build><ColumnWidth0>20</ColumnWidth0><ColumnWidth1>1215</ColumnWidth1><ColumnWidth2>324</ColumnWidth2><ColumnWidth3>81</ColumnWidth3></Build><TerminalIO/><Debug-Log><ColumnWidth0>19</ColumnWidth0><ColumnWidth1>1622</ColumnWidth1></Debug-Log></Static>
<Windows>
<Wnd2>
<Wnd0>
<Tabs>
<Tab>
<Identity>TabID-30370-1297</Identity>
@ -29,7 +29,7 @@
</Tab>
</Tabs>
<SelectedTab>0</SelectedTab></Wnd2><Wnd3><Tabs><Tab><Identity>TabID-24390-6730</Identity><TabName>Build</TabName><Factory>Build</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd3></Windows>
<SelectedTab>0</SelectedTab></Wnd0><Wnd1><Tabs><Tab><Identity>TabID-24390-6730</Identity><TabName>Build</TabName><Factory>Build</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd1></Windows>
<Editor>
@ -42,7 +42,7 @@
<Top><Row0><Sizes><Toolbar-00e15d58><key>iaridepm.enu1</key></Toolbar-00e15d58></Sizes></Row0></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>772</Bottom><Right>451</Right><x>-2</x><y>-2</y><xscreen>456</xscreen><yscreen>101</yscreen><sizeHorzCX>271429</sizeHorzCX><sizeHorzCY>104339</sizeHorzCY><sizeVertCX>269643</sizeVertCX><sizeVertCY>799587</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>151</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>153</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>158058</sizeHorzCY><sizeVertCX>271429</sizeVertCX><sizeVertCY>104339</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
<Top><Row0><Sizes><Toolbar-00e55d58><key>iaridepm.enu1</key></Toolbar-00e55d58></Sizes></Row0></Top><Left><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>725</Bottom><Right>451</Right><x>-2</x><y>-2</y><xscreen>456</xscreen><yscreen>101</yscreen><sizeHorzCX>271429</sizeHorzCX><sizeHorzCY>104339</sizeHorzCY><sizeVertCX>269643</sizeVertCX><sizeVertCY>751033</sizeVertCY></Rect></Wnd0></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>206612</sizeHorzCY><sizeVertCX>271429</sizeVertCX><sizeVertCY>104339</sizeVertCY></Rect></Wnd1></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>
</Desktop>
</Workspace>

View File

@ -80,16 +80,6 @@ static pvMBFrameStop pvMBFrameStopCur;
static peMBFrameReceive peMBFrameReceiveCur;
static pvMBFrameClose pvMBFrameCloseCur;
/* Functions pointer which are initialized in eMBInit( ). Depending on the
* mode (RTU or ASCII) the are set to the correct implementations.
* Using for Modbus Master,Add by Armink 20130813
*/
static peMBFrameSend peMBMasterFrameSendCur;
static pvMBFrameStart pvMBMasterFrameStartCur;
static pvMBFrameStop pvMBMasterFrameStopCur;
static peMBFrameReceive peMBMasterFrameReceiveCur;
static pvMBFrameClose pvMBMasterFrameCloseCur;
/* Callback functions required by the porting layer. They are called when
* an external event has happend which includes a timeout or the reception
* or transmission of a character.
@ -102,18 +92,6 @@ BOOL( *pxMBPortCBTimerExpired ) ( void );
BOOL( *pxMBFrameCBReceiveFSMCur ) ( void );
BOOL( *pxMBFrameCBTransmitFSMCur ) ( void );
/* Callback functions required by the porting layer. They are called when
* an external event has happend which includes a timeout or the reception
* or transmission of a character.
* Using for Modbus Master,Add by Armink 20130813
*/
BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
BOOL( *pxMBMasterFrameCBReceiveFSMCur ) ( void );
BOOL( *pxMBMasterFrameCBTransmitFSMCur ) ( void );
/* An array of Modbus functions handlers which associates Modbus function
* codes with implementing functions.
*/
@ -248,64 +226,6 @@ eMBTCPInit( USHORT ucTCPPort )
}
#endif
#if MB_MASTER_RTU_ENABLED > 0
eMBErrorCode
eMBMasterInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
{
eMBErrorCode eStatus = MB_ENOERR;
switch (eMode)
{
#if MB_MASTER_RTU_ENABLED > 0
case MB_RTU:
pvMBMasterFrameStartCur = eMBMasterRTUStart;
pvMBMasterFrameStopCur = eMBMasterRTUStop;
peMBMasterFrameSendCur = eMBMasterRTUSend;
peMBMasterFrameReceiveCur = eMBMasterRTUReceive;
pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerT35Expired;
eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
break;
#endif
#if MB_MASTER_ASCII_ENABLED > 0
case MB_ASCII:
pvMBMasterFrameStartCur = eMBMasterASCIIStart;
pvMBMasterFrameStopCur = eMBMasterASCIIStop;
peMBMasterFrameSendCur = eMBMasterASCIISend;
peMBMasterFrameReceiveCur = eMBMasterASCIIReceive;
pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
break;
#endif
default:
eStatus = MB_EINVAL;
break;
}
if (eStatus == MB_ENOERR)
{
if (!xMBMasterPortEventInit())
{
/* port dependent event module initalization failed. */
eStatus = MB_EPORTERR;
}
else
{
eMBCurrentMode = eMode;
eMBState = STATE_DISABLED;
}
}
return eStatus;
}
#endif
eMBErrorCode
eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
{
@ -372,26 +292,6 @@ eMBClose( void )
return eStatus;
}
#if MB_MASTER_RTU_ENABLED > 0
eMBErrorCode
eMBMasterClose( void )
{
eMBErrorCode eStatus = MB_ENOERR;
if( eMBState == STATE_DISABLED )
{
if( pvMBMasterFrameCloseCur != NULL )
{
pvMBMasterFrameCloseCur( );
}
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
#endif
eMBErrorCode
eMBEnable( void )
@ -411,26 +311,6 @@ eMBEnable( void )
return eStatus;
}
#if MB_MASTER_RTU_ENABLED > 0
eMBErrorCode
eMBMasterEnable( void )
{
eMBErrorCode eStatus = MB_ENOERR;
if( eMBState == STATE_DISABLED )
{
/* Activate the protocol stack. */
pvMBMasterFrameStartCur( );
eMBState = STATE_ENABLED;
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
#endif
eMBErrorCode
eMBDisable( void )
{
@ -453,30 +333,6 @@ eMBDisable( void )
return eStatus;
}
#if MB_MASTER_RTU_ENABLED > 0
eMBErrorCode
eMBMasterDisable( void )
{
eMBErrorCode eStatus;
if( eMBState == STATE_ENABLED )
{
pvMBMasterFrameStopCur( );
eMBState = STATE_DISABLED;
eStatus = MB_ENOERR;
}
else if( eMBState == STATE_DISABLED )
{
eStatus = MB_ENOERR;
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
#endif
eMBErrorCode eMBPoll( void )
{
static UCHAR *ucMBFrame;

330
FreeModbus/modbus/mb_m.c Normal file
View File

@ -0,0 +1,330 @@
/*
* FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
* Copyright (C) 2013 Armink <armink.ztl@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* File: $Id: mbrtu_m.c,v 1.60 2013/08/20 11:18:10 Armink Add Master Functions , $
*/
/* ----------------------- System includes ----------------------------------*/
#include "stdlib.h"
#include "string.h"
/* ----------------------- Platform includes --------------------------------*/
#include "port.h"
/* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h"
#include "mbconfig.h"
#include "mbframe.h"
#include "mbproto.h"
#include "mbfunc.h"
#include "mbport.h"
#if MB_MASTER_RTU_ENABLED == 1
#include "mbrtu.h"
#endif
#if MB_MASTER_ASCII_ENABLED == 1
#include "mbascii.h"
#endif
#if MB_MASTER_TCP_ENABLED == 1
#include "mbtcp.h"
#endif
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
#ifndef MB_PORT_HAS_CLOSE
#define MB_PORT_HAS_CLOSE 0
#endif
/* ----------------------- Static variables ---------------------------------*/
static UCHAR ucMBAddress;
static eMBMode eMBCurrentMode;
static enum
{
STATE_ENABLED,
STATE_DISABLED,
STATE_NOT_INITIALIZED
} eMBState = STATE_NOT_INITIALIZED;
/* Functions pointer which are initialized in eMBInit( ). Depending on the
* mode (RTU or ASCII) the are set to the correct implementations.
* Using for Modbus Master,Add by Armink 20130813
*/
static peMBFrameSend peMBMasterFrameSendCur;
static pvMBFrameStart pvMBMasterFrameStartCur;
static pvMBFrameStop pvMBMasterFrameStopCur;
static peMBFrameReceive peMBMasterFrameReceiveCur;
static pvMBFrameClose pvMBMasterFrameCloseCur;
/* Callback functions required by the porting layer. They are called when
* an external event has happend which includes a timeout or the reception
* or transmission of a character.
* Using for Modbus Master,Add by Armink 20130813
*/
BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
BOOL( *pxMBMasterFrameCBReceiveFSMCur ) ( void );
BOOL( *pxMBMasterFrameCBTransmitFSMCur ) ( void );
/* An array of Modbus functions handlers which associates Modbus function
* codes with implementing functions.
*/
static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
{MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
#endif
#if MB_FUNC_READ_INPUT_ENABLED > 0
{MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
#endif
#if MB_FUNC_READ_HOLDING_ENABLED > 0
{MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
#endif
#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
{MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
#endif
#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
{MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
#endif
#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
{MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
#endif
#if MB_FUNC_READ_COILS_ENABLED > 0
{MB_FUNC_READ_COILS, eMBFuncReadCoils},
#endif
#if MB_FUNC_WRITE_COIL_ENABLED > 0
{MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
#endif
#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
{MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
#endif
#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
{MB_FUNC_READ_DISCRETE_INPUTS, eMBFuncReadDiscreteInputs},
#endif
};
/* ----------------------- Start implementation -----------------------------*/
eMBErrorCode
eMBMasterInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
{
eMBErrorCode eStatus = MB_ENOERR;
switch (eMode)
{
#if MB_MASTER_RTU_ENABLED > 0
case MB_RTU:
pvMBMasterFrameStartCur = eMBMasterRTUStart;
pvMBMasterFrameStopCur = eMBMasterRTUStop;
peMBMasterFrameSendCur = eMBMasterRTUSend;
peMBMasterFrameReceiveCur = eMBMasterRTUReceive;
pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerT35Expired;
eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
break;
#endif
#if MB_MASTER_ASCII_ENABLED > 0
case MB_ASCII:
pvMBMasterFrameStartCur = eMBMasterASCIIStart;
pvMBMasterFrameStopCur = eMBMasterASCIIStop;
peMBMasterFrameSendCur = eMBMasterASCIISend;
peMBMasterFrameReceiveCur = eMBMasterASCIIReceive;
pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
break;
#endif
default:
eStatus = MB_EINVAL;
break;
}
if (eStatus == MB_ENOERR)
{
if (!xMBMasterPortEventInit())
{
/* port dependent event module initalization failed. */
eStatus = MB_EPORTERR;
}
else
{
eMBCurrentMode = eMode;
eMBState = STATE_DISABLED;
}
}
return eStatus;
}
eMBErrorCode
eMBMasterClose( void )
{
eMBErrorCode eStatus = MB_ENOERR;
if( eMBState == STATE_DISABLED )
{
if( pvMBMasterFrameCloseCur != NULL )
{
pvMBMasterFrameCloseCur( );
}
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
eMBErrorCode
eMBMasterEnable( void )
{
eMBErrorCode eStatus = MB_ENOERR;
if( eMBState == STATE_DISABLED )
{
/* Activate the protocol stack. */
pvMBMasterFrameStartCur( );
eMBState = STATE_ENABLED;
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
eMBErrorCode
eMBMasterDisable( void )
{
eMBErrorCode eStatus;
if( eMBState == STATE_ENABLED )
{
pvMBMasterFrameStopCur( );
eMBState = STATE_DISABLED;
eStatus = MB_ENOERR;
}
else if( eMBState == STATE_DISABLED )
{
eStatus = MB_ENOERR;
}
else
{
eStatus = MB_EILLSTATE;
}
return eStatus;
}
eMBErrorCode eMBMasterPoll( void )
{
static UCHAR *ucMBFrame;
static UCHAR ucRcvAddress;
static UCHAR ucFunctionCode;
static USHORT usLength;
static eMBException eException;
int i;
eMBErrorCode eStatus = MB_ENOERR;
eMBMasterEventType eEvent;
/* Check if the protocol stack is ready. */
if( eMBState != STATE_ENABLED )
{
return MB_EILLSTATE;
}
/* Check if there is a event available. If not return control to caller.
* Otherwise we will handle the event. */
if( xMBMasterPortEventGet( &eEvent ) == TRUE )
{
switch ( eEvent )
{
case EV_MASTER_READY:
break;
case EV_MASTER_FRAME_RECEIVED:
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
if( eStatus == MB_ENOERR )
{
/* Check if the frame is for us. If not ignore the frame. */
if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
{
( void )xMBMasterPortEventPost( EV_MASTER_EXECUTE );
}
}
else ( void )xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
break;
case EV_MASTER_EXECUTE:
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
eException = MB_EX_ILLEGAL_FUNCTION;
for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
{
/* No more function handlers registered. Abort. */
if( xFuncHandlers[i].ucFunctionCode == 0 )
{
break;
}
else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
{
eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
break;
}
}
/* If the request was not sent to the broadcast address we
* return a reply. */
if( ucRcvAddress != MB_ADDRESS_BROADCAST )
{
if( eException != MB_EX_NONE )
{
/* An exception occured. Build an error frame. */
usLength = 0;
ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
ucMBFrame[usLength++] = eException;
}
eStatus = peMBMasterFrameSendCur( ucMBAddress, ucMBFrame, usLength );
}
break;
case EV_MASTER_FRAME_SENT:
break;
case EV_MASTER_ERROR_PROCESS:
break;
}
}
return MB_ENOERR;
}
#endif

View File

@ -150,7 +150,6 @@ eMBRTUStop( void )
eMBErrorCode
eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
{
BOOL xFrameReceived = FALSE;
eMBErrorCode eStatus = MB_ENOERR;
ENTER_CRITICAL_SECTION( );
@ -172,7 +171,6 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
/* Return the start of the Modbus PDU to the caller. */
*pucFrame = ( UCHAR * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
xFrameReceived = TRUE;
}
else
{

View File

@ -151,7 +151,6 @@ eMBMasterRTUStop( void )
eMBErrorCode
eMBMasterRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
{
BOOL xFrameReceived = FALSE;
eMBErrorCode eStatus = MB_ENOERR;
ENTER_CRITICAL_SECTION( );
@ -173,7 +172,6 @@ eMBMasterRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLengt
/* Return the start of the Modbus PDU to the caller. */
*pucFrame = ( UCHAR * ) & ucMasterRTUBuf[MB_SER_PDU_PDU_OFF];
xFrameReceived = TRUE;
}
else
{

View File

@ -23,7 +23,7 @@
#include "mb.h"
#include "mbport.h"
#if MB_MASTER_RTU_ENABLED > 0
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED
/* ----------------------- Variables ----------------------------------------*/
static eMBMasterEventType eMasterQueuedEvent;
static BOOL xMasterEventInQueue;

View File

@ -25,7 +25,7 @@
#include "mb.h"
#include "mbport.h"
#if MB_MASTER_RTU_ENABLED > 0
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED
/* ----------------------- static functions ---------------------------------*/
static void prvvUARTTxReadyISR(void);
static void prvvUARTRxISR(void);

View File

@ -26,7 +26,7 @@
#include "mb.h"
#include "mbport.h"
#if MB_MASTER_RTU_ENABLED > 0
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED
/* ----------------------- Variables ----------------------------------------*/
static USHORT usT35TimeOut50us;

File diff suppressed because one or more lines are too long

View File

@ -668,7 +668,7 @@
</Files>
</Group>
<Group>
<GroupName>FreeModbus</GroupName>
<GroupName>FreeModbusSlave</GroupName>
<Files>
<File>
<FileName>mb.c</FileName>
@ -720,11 +720,6 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
<File>
<FileName>port.c</FileName>
<FileType>1</FileType>
@ -745,6 +740,26 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\porttimer.c</FilePath>
</File>
<File>
<FileName>user_app_s.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\user_app_s.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>FreeModbusMaster</GroupName>
<Files>
<File>
<FileName>mb_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\mb_m.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
<File>
<FileName>portevent_m.c</FileName>
<FileType>1</FileType>
@ -760,11 +775,6 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\porttimer_m.c</FilePath>
</File>
<File>
<FileName>user_app_s.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\user_app_s.c</FilePath>
</File>
</Files>
</Group>
</Groups>
@ -1431,7 +1441,7 @@
</Files>
</Group>
<Group>
<GroupName>FreeModbus</GroupName>
<GroupName>FreeModbusSlave</GroupName>
<Files>
<File>
<FileName>mb.c</FileName>
@ -1483,11 +1493,6 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
<File>
<FileName>port.c</FileName>
<FileType>1</FileType>
@ -1508,6 +1513,26 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\porttimer.c</FilePath>
</File>
<File>
<FileName>user_app_s.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\user_app_s.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>FreeModbusMaster</GroupName>
<Files>
<File>
<FileName>mb_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\mb_m.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
<File>
<FileName>portevent_m.c</FileName>
<FileType>1</FileType>
@ -1523,11 +1548,6 @@
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\porttimer_m.c</FilePath>
</File>
<File>
<FileName>user_app_s.c</FileName>
<FileType>1</FileType>
<FilePath>..\FreeModbus\port\user_app_s.c</FilePath>
</File>
</Files>
</Group>
</Groups>