from Cam Marshall original modbus

Dependencies:   mbed

Fork of Modbus by Cam Marshall

Revision:
4:5000041d2dc2
Parent:
1:7dc3a566a85a
--- a/Modbus/mbrtu.cpp	Mon Mar 13 13:12:06 2017 +0000
+++ b/Modbus/mbrtu.cpp	Tue Mar 14 14:25:27 2017 +0800
@@ -134,6 +134,7 @@
     eRcvState = STATE_RX_INIT;
     vMBPortSerialEnable( TRUE, FALSE );
     vMBPortTimersEnable(  );
+
     EXIT_CRITICAL_SECTION(  );
 }
 
@@ -154,12 +155,12 @@
 
     ENTER_CRITICAL_SECTION(  );
     assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
-        
+
     /* Length and CRC check */
     if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
         && ( usMBCRC16( ( UCHAR * ) ucRTUBuf, usRcvBufferPos ) == 0 ) )
     {
-        /* Save the address field. All frames are passed to the upper layer
+        /* Save the address field. All frames are passed to the upper layed
          * and the decision if a frame is used is done there.
          */
         *pucRcvAddress = ucRTUBuf[MB_SER_PDU_ADDR_OFF];
@@ -176,7 +177,7 @@
         // Added by Cam
         // Now that the poll routine knows about the received frame, 
         // clear the receive buffer position ready for the next frame received
-        usRcvBufferPos = 0;
+        //usRcvBufferPos = 0;
 
     }
     else
@@ -256,9 +257,10 @@
 
         /* In the idle state we wait for a new character. If a character
          * is received the t1.5 and t3.5 timers are started and the
-         * receiver is in the state STATE_RX_RECEIVE.
+         * receiver is in the state STATE_RX_RECEIVCE.
          */
     case STATE_RX_IDLE:
+        usRcvBufferPos = 0; //cam will comment this
         ucRTUBuf[usRcvBufferPos++] = ucByte;
         eRcvState = STATE_RX_RCV;
 
@@ -292,6 +294,7 @@
     BOOL            xNeedPoll = FALSE;
 
     assert( eRcvState == STATE_RX_IDLE );
+
     switch ( eSndState )
     {
         /* We should not get a transmitter event if the transmitter is in
@@ -326,7 +329,7 @@
 BOOL
 xMBRTUTimerT35Expired( void )
 {
-    BOOL    xNeedPoll = FALSE;
+    BOOL            xNeedPoll = FALSE;
 
     switch ( eRcvState )
     {