From 8501fb41f743afe45fee84b8606da977b27ca0e0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 29 Jul 2020 10:08:44 +0200 Subject: [PATCH] S7Net: Fix strobe race condition --- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 39fa7b1..d482692 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -1255,9 +1255,22 @@ namespace CMS_CORE_Library.S7Net if (libraryError.IsError()) return libraryError; - // If PLC it's performing another request then return + // se รจ true + int n = 200; + do + { + // Check Strobe + libraryError = MEM_RWBoolean(R, fixEndian, 0, strobeCell.MemType, strobeCell.Address, strobeByte, alarmBitId, ref readValue); + Thread.Sleep(20); + n--; + } while (n > 0 && readValue); + + // If PLC is true --> reset if (readValue) - return NO_ERROR; + { + bool forceVal =false; + libraryError = MEM_RWBoolean(W, fixEndian, 0, strobeCell.MemType, strobeCell.Address, strobeByte, alarmBitId, ref forceVal); + } // Check ACK libraryError = MEM_RWBoolean(R, fixEndian, 0, ackCell.MemType, ackCell.Address, ackByte, alarmBitId, ref readValue); @@ -1341,7 +1354,7 @@ namespace CMS_CORE_Library.S7Net private CmsError ResetStrobe(int bitId, int strobeByte, int ackByte, MEMORY_TYPE memType, bool fixEndian) { - int n = 600; + int n = 200; bool readValue = false; bool writeValue = false; bool ok = false; @@ -1376,6 +1389,7 @@ namespace CMS_CORE_Library.S7Net if (!ok) { + writeValue = false; // Reset strobe libraryError = MEM_RWBoolean(W, fixEndian, 0, memType, TABLE, strobeByte, bitId, ref writeValue); if (libraryError.IsError()) @@ -4677,7 +4691,6 @@ namespace CMS_CORE_Library.S7Net #endregion Subordinate Private Functions - }