From 15d4cc2af5cbf66732c67907fd73240f5204566b Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 21 Oct 2020 18:19:04 +0200 Subject: [PATCH 1/4] calmierata riduzione status attivo --- IOB-WIN/IobFileEurom63.cs | 47 ++++++++++++++++++++++++++++++--------- Jenkinsfile | 2 +- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/IOB-WIN/IobFileEurom63.cs b/IOB-WIN/IobFileEurom63.cs index a714feb8..3477511c 100644 --- a/IOB-WIN/IobFileEurom63.cs +++ b/IOB-WIN/IobFileEurom63.cs @@ -17,6 +17,8 @@ namespace IOB_WIN { #region Protected Fields + protected static DateTime lastStatusDecr = DateTime.Now; + /// /// step di comunicazione attivo /// @@ -87,18 +89,24 @@ namespace IOB_WIN private void checkSessionActive(Eurom63.Session currSession, Eurom63.ComLevel nextLevel) { // SOLO SE ha senso che controllo (sono in sampling...) - if (actLevel > Eurom63.ComLevel.ChannelOk) + if (actLevel > Eurom63.ComLevel.HasInfo) { DateTime adesso = DateTime.Now; // devono essere ATTIVE le sessioni di campionamento... e NON scadute if (!currSession.Active || currSession.SessionValidUntil < adesso) { - // elimino TUTTE le risposte... - cleanupResp(currSession.SessionName); - // imposto livellotornando indietro di 1 alla volta... senza andare in negativoS - actLevel = actLevel - 1; - actLevel = actLevel > 0 ? actLevel : 0; - lgInfo($"Sessione inattiva, {actLevel + 1} --> {actLevel}"); + // controllo ultimo downgrade status + if (lastStatusDecr.AddSeconds(3) < adesso) + { + // elimino TUTTE le risposte... + cleanupResp(currSession.SessionName); + // registro downgrade status... + lastStatusDecr = adesso; + // imposto livellotornando indietro di 1 alla volta... senza andare in negativoS + actLevel = actLevel - 1; + actLevel = actLevel > 0 ? actLevel : 0; + lgInfo($"Sessione inattiva, {actLevel + 1} --> {actLevel}"); + } } } } @@ -747,6 +755,19 @@ namespace IOB_WIN lgError($"Lettura file stato in errore: trovate {numRow} linee"); } } + // se valido RILEGGO ultimo curr status + if (Last_CurrStatus.ValidUntil > adesso) + { + currStatus = Last_CurrStatus.Value; + } + } + else + { + // se valido RILEGGO ultimo curr status + if (Last_CurrStatus.ValidUntil > adesso) + { + currStatus = Last_CurrStatus.Value; + } } } else @@ -756,10 +777,14 @@ namespace IOB_WIN { currStatus = Last_CurrStatus.Value; } - else - { - actLevel = Eurom63.ComLevel.ChannelOk; - } + } + } + else + { + // se valido RILEGGO ultimo curr status + if (Last_CurrStatus.ValidUntil > adesso) + { + currStatus = Last_CurrStatus.Value; } } diff --git a/Jenkinsfile b/Jenkinsfile index 45594ac5..daf71d39 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { steps { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=737']) { + withEnv(['NEXT_BUILD_NUMBER=738']) { // env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN' From 32f855307db0e6f16d2a4ab7e06d77c65196f264 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 21 Oct 2020 18:52:23 +0200 Subject: [PATCH 2/4] maybe fix x status bloccato solo con contapezzi --- IOB-WIN/IobFileEurom63.cs | 147 +++++++++++++++++++++----------------- Jenkinsfile | 2 +- 2 files changed, 81 insertions(+), 68 deletions(-) diff --git a/IOB-WIN/IobFileEurom63.cs b/IOB-WIN/IobFileEurom63.cs index 3477511c..8368b514 100644 --- a/IOB-WIN/IobFileEurom63.cs +++ b/IOB-WIN/IobFileEurom63.cs @@ -531,85 +531,96 @@ namespace IOB_WIN { if (utils.CRB("enableContapezzi")) { - // controllo se sono in sampling della produzione - if (actLevel >= Eurom63.ComLevel.ProdRequested) + try { - /************************************************************ - * - * EXAMPLE - * DATE, TIME, ActCntCyc, ActTimCyc, ActTimFill, @OutXhour, SetDescJob - * 20201007, 21:29:52, 5302, 8.61, 0.50, 10058, Nr. 1000987654.01 - * - * devo prendere il 3° valore - * - * - ************************************************************/ - - // leggo il file della produzione HARD CODED... - var sessProd = confE63.ActiveSessions[5]; - string currPzCount = ""; - if (sessProd != null) + // controllo se sono in sampling della produzione + if (actLevel >= Eurom63.ComLevel.ProdRequested) { - if (sessProd.Active) - { - // nome file... - string fileName = $"{BaseDir}\\{sessProd.SessionName}.DAT"; - if (File.Exists(fileName)) - { - string rawData = ""; - using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - using (var textReader = new StreamReader(fileStream)) - { - rawData = textReader.ReadToEnd(); - } - // ora splitto in linee - string[] rawLines = Regex.Split(rawData, "\r\n|\r|\n"); - int numRow = rawLines.Length; + /************************************************************ + * + * EXAMPLE + * DATE, TIME, ActCntCyc, ActTimCyc, ActTimFill, @OutXhour, SetDescJob + * 20201007, 21:29:52, 5302, 8.61, 0.50, 10058, Nr. 1000987654.01 + * + * devo prendere il 3° valore + * + * + ************************************************************/ - // devo avere almeno 2 righe... - if (numRow >= 2) + // leggo il file della produzione HARD CODED... + var sessProd = confE63.ActiveSessions[5]; + string currPzCount = ""; + if (sessProd != null) + { + if (sessProd.Active) + { + // nome file... + string fileName = $"{BaseDir}\\{sessProd.SessionName}.DAT"; + if (File.Exists(fileName)) { - string[] statusData = rawLines[1].Split(','); - currPzCount = statusData[2].Trim(); - // salvo se valido - if (!string.IsNullOrEmpty(currPzCount)) + string rawData = ""; + using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var textReader = new StreamReader(fileStream)) { - int newVal = -1; - Int32.TryParse(currPzCount, out newVal); - // verifico SE il contapezzi vada moltiplicato x il fattore pzPallet... - if (confE63.PzPallet > 1) + rawData = textReader.ReadToEnd(); + } + // ora splitto in linee + string[] rawLines = Regex.Split(rawData, "\r\n|\r|\n"); + int numRow = rawLines.Length; + + // devo avere almeno 2 righe... + if (numRow >= 2) + { + string[] statusData = rawLines[1].Split(','); + currPzCount = statusData[2].Trim(); + // salvo se valido + if (!string.IsNullOrEmpty(currPzCount)) { - newVal = newVal * confE63.PzPallet; + int newVal = -1; + Int32.TryParse(currPzCount, out newVal); + // verifico SE il contapezzi vada moltiplicato x il fattore pzPallet... + if (confE63.PzPallet > 1) + { + newVal = newVal * confE63.PzPallet; + } + // aggiorno contapezzi + contapezziPLC = newVal > -1 ? newVal : contapezziPLC; + } + // ora verifico SE siano validi anche le dataora dei valori letti (< 20 sec ritardo da ora...) + string data = statusData[0].Trim(); + string ora = statusData[1].Trim(); + DateTime adesso = DateTime.Now; + DateTime lastPub = adesso.AddMinutes(-1); + CultureInfo provider = CultureInfo.InvariantCulture; + try + { + lastPub = DateTime.ParseExact($"{data} {ora}", "yyyyMMdd HH:mm:ss", provider); + } + catch + { } + if (Math.Abs(lastPub.Subtract(adesso).TotalSeconds) > maxDelaySec) + { + sessProd.SessionValidUntil = adesso; + // elimino file RSP... + cleanupResp(sessProd.SessionName); } - // aggiorno contapezzi - contapezziPLC = newVal > -1 ? newVal : contapezziPLC; - } - // ora verifico SE siano validi anche le dataora dei valori letti (< 20 sec ritardo da ora...) - string data = statusData[0].Trim(); - string ora = statusData[1].Trim(); - DateTime adesso = DateTime.Now; - DateTime lastPub = adesso.AddMinutes(-1); - CultureInfo provider = CultureInfo.InvariantCulture; - try - { - lastPub = DateTime.ParseExact($"{data} {ora}", "yyyyMMdd HH:mm:ss", provider); - } - catch - { } - if (Math.Abs(lastPub.Subtract(adesso).TotalSeconds) > maxDelaySec) - { - sessProd.SessionValidUntil = adesso; - // elimino file RSP... - cleanupResp(sessProd.SessionName); } } } + else + { + actLevel = Eurom63.ComLevel.StatusRequested; + } + } + else + { + actLevel = Eurom63.ComLevel.StatusRequested; } } - else - { - actLevel = Eurom63.ComLevel.StatusRequested; - } + } + catch (Exception exc) + { + lgError($"Eccezione in processContapezzi:{Environment.NewLine}{exc}"); } } } @@ -768,6 +779,8 @@ namespace IOB_WIN { currStatus = Last_CurrStatus.Value; } + // abbasso status... + actLevel--; } } else diff --git a/Jenkinsfile b/Jenkinsfile index daf71d39..be521ccd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { steps { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=738']) { + withEnv(['NEXT_BUILD_NUMBER=739']) { // env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN' From c6090f1ff587122338318d91067c1e54aeef0188 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 21 Oct 2020 18:52:43 +0200 Subject: [PATCH 3/4] =?UTF-8?q?fix=20status=20NON=20ACT=20=202=C2=B0=20cha?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IOB-WIN/IobFileEurom63.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/IOB-WIN/IobFileEurom63.cs b/IOB-WIN/IobFileEurom63.cs index 8368b514..a05351cc 100644 --- a/IOB-WIN/IobFileEurom63.cs +++ b/IOB-WIN/IobFileEurom63.cs @@ -811,7 +811,6 @@ namespace IOB_WIN switch (currStatus[1]) { case 'A': - case '0': B_input += (1 << 1); break; From 25b2cbd64504709a201981758bf8b539b4282c06 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Thu, 29 Oct 2020 15:19:21 +0100 Subject: [PATCH 4/4] Update simec con distinzione allarme e emergenza --- IOB-WIN/IobSiemensSimec.cs | 181 ++++++++++++++++++++----------------- Jenkinsfile | 2 +- 2 files changed, 101 insertions(+), 82 deletions(-) diff --git a/IOB-WIN/IobSiemensSimec.cs b/IOB-WIN/IobSiemensSimec.cs index c91de155..7bb4f332 100644 --- a/IOB-WIN/IobSiemensSimec.cs +++ b/IOB-WIN/IobSiemensSimec.cs @@ -9,21 +9,21 @@ namespace IOB_WIN /// public class IobSiemensSimec : IobSiemens { - /* -------------------------------------------------------------------------------- + /* -------------------------------------------------------------------------------- * Controlli SIEMENS SIMEC * - basasto su SIEMENS * - S7 vers 1500 - * + * * STRUTTURA MEMORIA DB29: (lettura) 10byte, * G:\Drive condivisi\30_Clienti\Valvital\Comunicazione PLC\26 - SIMEC Taglio\ - * + * * Si intende lettura con DB29.DBxx, scrittura DB30.DBxx - * - * DB30 blocco dati scritto dal MES - * CodArt Array[0..19] of Char DBB0..19 - * CodComm Array[0..9] of Char DBB20..29 - * CodProgr Array[0..9] of Char DBB30..39 - * + * + * DB30 blocco dati scritto dal MES + * CodArt Array[0..19] of Char DBB0..19 + * CodComm Array[0..9] of Char DBB20..29 + * CodProgr Array[0..9] of Char DBB30..39 + * * DB29 blocco dati letto dal MES Byte Bit * CicloOn Bool 0 0 * MacchOn Bool 0 1 @@ -41,12 +41,14 @@ namespace IOB_WIN * b15 Bool 1 5 * b16 Bool 1 6 * b17 Bool 1 7 - * ContapezziAssoluto DInt 2 - * Comtapezzi parziale DInt 6 + * ContapezziAssoluto DInt 2 + * Comtapezzi parziale DInt 6 * -------------------------------------------------------------------------------- */ + #region Public Constructors + /// - /// Classe base con i metodi x Siemens + /// Classe base con i metodi x Siemens /// /// /// @@ -55,7 +57,85 @@ namespace IOB_WIN lgInfo("NEW IOB SIEMENS versione SIMEC"); } - #region Metodi specifici (da verificare/completare in implementazione) + #endregion Public Constructors + + #region Protected Methods + + /// + /// Effettua decodifica aree memoria alla bitmap usata x MAPO + /// + protected override void decodeToBaseBitmap() + { + // init a zero... + B_input = 0; + + /* ----------------------------------------------------- + * bitmap MAPO STANDARD + * B0: POWER_ON + * B1: RUN + * B2: pzCount + * B3: allarme + * B4: manuale + * B5: emergenza (1=attiva/premuta, 0=armed) + * + * - BIT di stato + * DB29 blocco dati letto dal MES Byte Bit + * CicloOn Bool 0 0 + * MacchOn Bool 0 1 + * ManualeOn Bool 0 2 + * AllarmiOn Bool 0 3 + * EmergenzaOn Bool 0 4 + * EmergenzaPremuta Bool 0 5 + * ContapezziAssoluto DInt 2 + * Comtapezzi parziale DInt 6 + * + ----------------------------------------------------- */ + + byte mainData = RawInput[0]; + + int byteSignals = 0; + // bit 0 (poweron) imposto a 1 SE connected... + if (currPLC.IsConnected) + { + byteSignals += (1 << 0); + } + + // lavora --> bit0 e bit1: cicloOn AND macchOn + if ((mainData & (1 << 0)) != 0 && (mainData & (1 << 1)) != 0) + { + byteSignals += (1 << 1); + } + + // controllo il bit ALARM + if ((mainData & (1 << 3)) != 0) + { + byteSignals += (1 << 3); + } + // controllo il bit emergenza dello status + if ((mainData & (1 << 5)) != 0) + { + byteSignals += (1 << 5); + } + + // check MANUALE ... + if ((mainData & (1 << 2)) != 0) + { + byteSignals += (1 << 4); + } + + // salvo! + B_input = byteSignals; + + // log opzionale! + if (verboseLog) + { + lgInfo($"Trasformazione dati: RawInput:{RawInput[0]} --> B_input: {B_input}"); + } + } + + #endregion Protected Methods + + #region Public Methods /// /// Processo i task richiesti e li elimino dalla coda 1:1 @@ -92,6 +172,7 @@ namespace IOB_WIN case taskType.setPzComm: taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; break; + case taskType.setArt: case taskType.setComm: saveProdData(item); @@ -122,18 +203,21 @@ namespace IOB_WIN } taskVal = item.Value; break; + case taskType.startSetup: //// processo scrittura BIT su DB150.DBX4.0 //MemBlock = new byte[1]; //MemBlock[0] = (byte)1; //memAddrWrite = "DB150.DBB4"; break; + case taskType.stopSetup: //// processo scrittura BIT su DB150.DBX4.0 //MemBlock = new byte[1]; //MemBlock[0] = (byte)0; //memAddrWrite = "DB150.DBB4"; break; + case taskType.setParameter: // richiedo da URL i parametri WRITE da popolare lgInfo("Chiamata processMemWriteRequests"); @@ -153,6 +237,7 @@ namespace IOB_WIN } } break; + default: taskVal = "SKIPPED | NO EXEC"; break; @@ -173,72 +258,6 @@ namespace IOB_WIN return taskDone; } - /// - /// Effettua decodifica aree memoria alla bitmap usata x MAPO - /// - protected override void decodeToBaseBitmap() - { - // init a zero... - B_input = 0; - - /* ----------------------------------------------------- - * bitmap MAPO STANDARD - * B0: POWER_ON - * B1: RUN - * B2: pzCount - * B3: allarme - * B4: manuale - * - * - BIT di stato - * DB29 blocco dati letto dal MES Byte Bit - * CicloOn Bool 0 0 - * MacchOn Bool 0 1 - * ManualeOn Bool 0 2 - * AllarmiOn Bool 0 3 - * EmergenzaOn Bool 0 4 - * EmergenzaPremuta Bool 0 5 - * ContapezziAssoluto DInt 2 - * Comtapezzi parziale DInt 6 - * - ----------------------------------------------------- */ - - byte mainData = RawInput[0]; - - int byteSignals = 0; - // bit 0 (poweron) imposto a 1 SE connected... - if (currPLC.IsConnected) - { - byteSignals += (1 << 0); - } - - // lavora --> bit0 e bit1: cicloOn AND macchOn - if ((mainData & (1 << 0)) != 0 && (mainData & (1 << 1)) != 0) - { - byteSignals += (1 << 1); - } - - // controllo il bit ALARM OR emergenza dello status - if ((mainData & (1 << 3)) != 0 || (mainData & (1 << 5)) != 0) - { - byteSignals += (1 << 3); - } - - // check MANUALE ... - if ((mainData & (1 << 2)) != 0) - { - byteSignals += (1 << 4); - } - - // salvo! - B_input = byteSignals; - - // log opzionale! - if (verboseLog) - { - lgInfo($"Trasformazione dati: RawInput:{RawInput[0]} --> B_input: {B_input}"); - } - } - - #endregion + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index be521ccd..b80ab4ae 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { steps { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=739']) { + withEnv(['NEXT_BUILD_NUMBER=740']) { // env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '3.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'