From 1ca4c4d5195d55439a2cd2a458c5ae9d29aa941f Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 13 Nov 2019 12:46:12 +0100 Subject: [PATCH] Inizio modifica siemens base x gestione invio parametri --- IOB-WIN/IobSiemensAt2001.cs | 280 ++++++++++++++---------------------- 1 file changed, 110 insertions(+), 170 deletions(-) diff --git a/IOB-WIN/IobSiemensAt2001.cs b/IOB-WIN/IobSiemensAt2001.cs index 042a1f08..38242be5 100644 --- a/IOB-WIN/IobSiemensAt2001.cs +++ b/IOB-WIN/IobSiemensAt2001.cs @@ -1,6 +1,4 @@ -using IOB_UT; -using MapoSDK; -using Newtonsoft.Json; +using MapoSDK; using System; using System.Collections.Generic; @@ -60,62 +58,118 @@ namespace IOB_WIN bool taskOk = false; string taskVal = ""; // inizio VUOTO - byte[] MemBlock = new byte[parametri.memSizeWrite]; - - // cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4 - foreach (var item in task2exe) + byte[] MemBlock = new byte[1]; + string memAddrWrite = ""; + if (task2exe != null) { - taskOk = false; - taskVal = ""; - // converto richiesta in enum... - taskType tName = taskType.nihil; - Enum.TryParse(item.Key, out tName); - // controllo sulla KEY - switch (tName) + // cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4 + foreach (var item in task2exe) { - case taskType.nihil: - case taskType.fixStopSetup: - case taskType.forceResetPzCount: - case taskType.forceSetPzCount: - case taskType.startSetup: - case taskType.stopSetup: - taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; - break; - case taskType.setArt: - case taskType.setComm: - case taskType.setProg: - // imposto i valori... - if (currProdData.ContainsKey(item.Key)) - { - currProdData[item.Key] = item.Value; - } - else - { - currProdData.Add(item.Key, item.Value); - } - taskVal = item.Value; - break; - case taskType.setParameter: - // deserializzo il valore del parametro in primis - var paramData = JsonConvert.DeserializeObject(item.Value); - // !!!FIXME!!! fare!!! - break; - case taskType.sendWatchDogMes2Plc: - //// compogo in byte... primo bit è setup/run, ultimo è watchdog - //int valore = inSetup ? 1 : 0; - int valore = counterMes2Plc; - MemBlock[68] = (byte)valore; - taskVal = $"VALUE DB1001.68 --> {counterMes2Plc}"; - break; - default: - taskVal = "SKIPPED | NO EXEC"; - break; - } + taskOk = false; + taskVal = ""; + memAddrWrite = ""; + // converto richiesta in enum... + taskType tName = taskType.nihil; + Enum.TryParse(item.Key, out tName); + // controllo sulla KEY + switch (tName) + { + case taskType.nihil: + case taskType.fixStopSetup: + case taskType.forceResetPzCount: + case taskType.forceSetPzCount: + case taskType.startSetup: + case taskType.stopSetup: + taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; + break; + case taskType.setArt: + case taskType.setComm: + case taskType.setProg: +#if false + // imposto i valori... + if (currProdData.ContainsKey(item.Key)) + { + currProdData[item.Key] = item.Value; + } + else + { + currProdData.Add(item.Key, item.Value); + } + taskVal = item.Value; +#endif + saveProdData(item); + int byteSize = 0; + // recupero dati da memMap... altrimenti NULLA + if (memMap.mMapWrite.ContainsKey(item.Key)) + { + dataConf currMem = memMap.mMapWrite[item.Key]; + byteSize = currMem.size; + memAddrWrite = currMem.memAddr; + MemBlock = new byte[byteSize]; + if (currMem.tipoMem == plcDataType.String) + { + saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize); + } + else if (currMem.tipoMem == plcDataType.DInt) + { + int valDInt = 0; + int.TryParse(item.Value, out valDInt); + MemBlock = S7.Net.Types.DInt.ToByteArray(valDInt); + } + else if (currMem.tipoMem == plcDataType.Int) + { + short valDInt = 0; + short.TryParse(item.Value, out valDInt); + MemBlock = S7.Net.Types.Int.ToByteArray(valDInt); + } + } + taskVal = item.Value; + break; + case taskType.setParameter: + // richiedo da URL i parametri WRITE da popolare + taskVal = processMemWriteRequests(); + // se restituiscce "" faccio altra prova... + if (string.IsNullOrEmpty(taskVal)) + { + // i parametri me li aspetto come stringa composta paramName|paramvalue + if (item.Value.Contains("|")) + { + string[] paramsJob = item.Value.Split('|'); + taskVal = $"REQUEST SET PARAMETERS: {paramsJob[0]} --> {paramsJob[1]}"; + } + else + { + taskVal = $"WRONG REQUEST FOR SET PARAMETERS: {item.Value} doesnt contain pipe for splitting key/value"; + } + } + break; + case taskType.sendWatchDogMes2Plc: + //// compogo in byte... primo bit è setup/run, ultimo è watchdog + //int valore = inSetup ? 1 : 0; + int valore = counterMes2Plc; + MemBlock[68] = (byte)valore; + taskVal = $"VALUE DB1001.68 --> {counterMes2Plc}"; + break; + default: + taskVal = "SKIPPED | NO EXEC"; + break; + } - // aggiungo task! - taskDone.Add(item.Key, taskVal); + // aggiungo task! + taskDone.Add(item.Key, taskVal); + if (string.IsNullOrEmpty(memAddrWrite)) + { + // scrivo comunque! + taskOk = S7WriteBB(ref MemBlock, memAddrWrite); + } + if (!taskOk) + { + lgError($"Errore in S7WriteBB durante executeTasks: {item.Key} | {item.Value}"); + } + } } +#if false // controllo SE HO da scrivere articolo/commessa/programma saveStringOnMemBlock(ref MemBlock, "setArt", 0, 20, true); saveStringOnMemBlock(ref MemBlock, "setComm", 22, 20, true); @@ -151,126 +205,12 @@ namespace IOB_WIN // fare un controllo x forzare update... // scrivo comunque! - taskOk = S7WriteBB(ref MemBlock); + taskOk = S7WriteBB(ref MemBlock); +#endif return taskDone; } - /// - /// Recupero dati dinamici in formato dictionary - /// - /// - public override Dictionary getDynData() - { - Dictionary outVal = new Dictionary(); - // controllo se eseguire versione base del getDynData -#if false - if (getOptPar("NEW_DYN_DATA") != "") - { -#endif - outVal = base.getDynData(); -#if false - } - else - { - // processing SOL OSE ho in memoria abb dati... - if (RawInput.Length < parametri.memSizeRead) - { - lgError($"Impossibile processare getDynData x Siemens AT2001, vettore memoria troppo piccolo: {RawInput.Length} byte / {parametri.memSizeRead} byte presenti/richiesti)"); - } - else - { - try - { - // campi REAL - double T_Attuale_Cil = S7.Net.Types.Double.FromByteArray(RawInput.Skip(16).Take(4).ToArray()); - int Bruc_0_100 = S7.Net.Types.Int.FromByteArray(RawInput.Skip(28).Take(2).ToArray()); - int Dep_Cil_mmH2O = S7.Net.Types.Int.FromByteArray(RawInput.Skip(30).Take(2).ToArray()); - int Asp_0_100 = S7.Net.Types.Int.FromByteArray(RawInput.Skip(32).Take(2).ToArray()); - int Ampere_Asp = S7.Net.Types.Int.FromByteArray(RawInput.Skip(34).Take(2).ToArray()); - int Temp_Filtro = S7.Net.Types.Int.FromByteArray(RawInput.Skip(36).Take(2).ToArray()); - int Ampere_Cil = S7.Net.Types.Int.FromByteArray(RawInput.Skip(38).Take(2).ToArray()); - int Flowrate = S7.Net.Types.Int.FromByteArray(RawInput.Skip(40).Take(2).ToArray()); - int Ampere_Dosat = S7.Net.Types.Int.FromByteArray(RawInput.Skip(42).Take(2).ToArray()); - int Tot_Parz_Dosatore = S7.Net.Types.DInt.FromByteArray(RawInput.Skip(48).Take(4).ToArray()); - int Tot_Dosatore = S7.Net.Types.DInt.FromByteArray(RawInput.Skip(52).Take(4).ToArray()); - - // verifico SE devo riportare dati VC - if (utils.CRB("enableTSVC")) - { - bool[] scaduti = new bool[11]; - // salvo in stack le VC rilevate - scaduti[0] = stackVal_TSVC("T_Attuale_Cil", T_Attuale_Cil); - scaduti[1] = stackVal_TSVC("Bruc_0_100", Bruc_0_100); - scaduti[2] = stackVal_TSVC("Dep_Cil_mmH2O", Dep_Cil_mmH2O); - scaduti[3] = stackVal_TSVC("Asp_0_100", Asp_0_100); - scaduti[4] = stackVal_TSVC("Ampere_Asp", Ampere_Asp); - scaduti[5] = stackVal_TSVC("Temp_Filtro", Temp_Filtro); - scaduti[6] = stackVal_TSVC("Ampere_Cil", Ampere_Cil); - scaduti[7] = stackVal_TSVC("Flowrate", Flowrate); - scaduti[8] = stackVal_TSVC("Ampere_Dosat", Ampere_Dosat); - scaduti[9] = stackVal_TSVC("Tot_Parz_Dosatore", Tot_Parz_Dosatore); - scaduti[10] = stackVal_TSVC("Tot_Dosatore", Tot_Dosatore); - - // verifico SE devo riportare dati VC - if (baseUtils.CountTrue(scaduti) > 0) - { - T_Attuale_Cil = getVal_TSVC_int("T_Attuale_Cil", scaduti[0]); - Bruc_0_100 = getVal_TSVC_int("Bruc_0_100", scaduti[1]); - Dep_Cil_mmH2O = getVal_TSVC_int("Dep_Cil_mmH2O", scaduti[2]); - Asp_0_100 = getVal_TSVC_int("Asp_0_100", scaduti[3]); - Ampere_Asp = getVal_TSVC_int("Ampere_Asp", scaduti[4]); - Temp_Filtro = getVal_TSVC_int("Temp_Filtro", scaduti[5]); - Ampere_Cil = getVal_TSVC_int("Ampere_Cil", scaduti[6]); - Flowrate = getVal_TSVC_int("Flowrate", scaduti[7]); - Ampere_Dosat = getVal_TSVC_int("Ampere_Dosat", scaduti[8]); - Tot_Parz_Dosatore = getVal_TSVC_int("Tot_Parz_Dosatore", scaduti[9]); - Tot_Dosatore = getVal_TSVC_int("Tot_Dosatore", scaduti[10]); - outVal.Add("T_Attuale_Cil", $"{T_Attuale_Cil:N1}"); - outVal.Add("Bruc_0_100", $"{Bruc_0_100}"); - outVal.Add("Dep_Cil_mmH2O", $"{Dep_Cil_mmH2O}"); - outVal.Add("Asp_0_100", $"{Asp_0_100}"); - outVal.Add("Ampere_Asp", $"{Ampere_Asp}"); - outVal.Add("Temp_Filtro", $"{Temp_Filtro}"); - outVal.Add("Ampere_Cil", $"{Ampere_Cil}"); - outVal.Add("Flowrate", $"{Flowrate}"); - outVal.Add("Ampere_Dosat", $"{Ampere_Dosat}"); - outVal.Add("Tot_Parz_Dosatore", $"{Tot_Parz_Dosatore}"); - outVal.Add("Tot_Dosatore", $"{Tot_Dosatore}"); - - // salvo! - LastTSVC["T_Attuale_Cil"] = T_Attuale_Cil; - LastTSVC["Bruc_0_100"] = Bruc_0_100; - LastTSVC["Dep_Cil_mmH2O"] = Dep_Cil_mmH2O; - LastTSVC["Asp_0_100"] = Asp_0_100; - LastTSVC["Ampere_Asp"] = Ampere_Asp; - LastTSVC["Temp_Filtro"] = Temp_Filtro; - LastTSVC["Ampere_Cil"] = Ampere_Cil; - LastTSVC["Flowrate"] = Flowrate; - LastTSVC["Ampere_Dosat"] = Ampere_Dosat; - LastTSVC["Tot_Parz_Dosatore"] = Tot_Parz_Dosatore; - LastTSVC["Tot_Dosatore"] = Tot_Dosatore; - } - else - { - outVal.Add("DYNDATA", $"T_Attuale_Cil {LastTSVC["T_Attuale_Cil"]:N1} | Tot_Dosatore {LastTSVC["Tot_Dosatore"]} | Bruc_0_100 {LastTSVC["Bruc_0_100"]} | Flowrate {LastTSVC["Flowrate"]}"); - } - } - else - { - outVal.Add("DYNDATA", $"T_Attuale_Cil {LastTSVC["T_Attuale_Cil"]:N1} | Tot_Dosatore {LastTSVC["Tot_Dosatore"]} | Bruc_0_100 {LastTSVC["Bruc_0_100"]} | Flowrate {LastTSVC["Flowrate"]}"); - } - } - catch (Exception exc) - { - lgError(exc, "Errore in getDynData x Siemens AT2001"); - } - } - } -#endif - return outVal; - } - /// /// Effettua decodifica aree memoria alla bitmap usata x MAPO ///