Modified version of ModbusTCP

Dependencies:   EthernetNetIf mbed

Files at this revision

API Documentation at this revision

Comitter:
paleskyjp
Date:
Thu Mar 15 15:28:14 2012 +0000
Parent:
2:53de07fd9705
Commit message:
eMBRegCoilsCB was corrected.
(Implementation of writing single coil was wrong.)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Mar 13 13:16:24 2012 +0000
+++ b/main.cpp	Thu Mar 15 15:28:14 2012 +0000
@@ -127,13 +127,13 @@
 #if MB_TCP_ENABLED == 1
     Net::poll();
 #endif
-/*
+
     if(tm.read()>.5)
     {
       led1=!led1; //Show that we are alive
       tm.start();
     }
-*/
+
     eStatus = eMBPoll(  );
             
     /* Here we simply count the number of poll cycles. */
@@ -249,11 +249,9 @@
 
             case MB_REG_WRITE:
                 // Write coils
-                if(iIntBitNum==0){
-                    usRegCoilBuf[iIntBufNum]=0;
-                }
-                ucTemp=(pucRegBuffer[iExtBufNum]>>iExtBitNum) & 1;
-                usRegCoilBuf[iIntBufNum]|=ucTemp<<iIntBitNum;
+				ucTemp=usRegCoilBuf[iIntBufNum]&(~(1<<iIntBitNum));
+				ucTemp|=((pucRegBuffer[iExtBufNum]>>iExtBitNum) & 1)<<iIntBitNum;
+				usRegCoilBuf[iIntBufNum]=ucTemp;
                 break;
             }
             iIntRegIndex++;