From 2a6fb4292c163ce3fea39614034d454f5c5bb67f Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 8 Nov 2019 19:07:03 +0100 Subject: [PATCH] Vari fix x errori + continuo fix x provare metodi backgroundWorkers --- IOB-WIN/.editorconfig | 12 +++++++ IOB-WIN/IobSiemens.cs | 72 +++++++++++++++++++++++---------------- IOB-WIN/IobSiemensFape.cs | 4 +-- 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/IOB-WIN/.editorconfig b/IOB-WIN/.editorconfig index 28e04861..0a801cd7 100644 --- a/IOB-WIN/.editorconfig +++ b/IOB-WIN/.editorconfig @@ -14,3 +14,15 @@ dotnet_diagnostic.CA1806.severity = none # CA1305: Specificare IFormatProvider dotnet_diagnostic.CA1305.severity = none + +# CA1031: Do not catch general exception types +dotnet_diagnostic.CA1031.severity = none + +# CA1707: Gli identificatori non devono contenere caratteri di sottolineatura +dotnet_diagnostic.CA1707.severity = none + +# CA1307: Specificare StringComparison +dotnet_diagnostic.CA1307.severity = none + +# CA1063: Implement IDisposable Correctly +dotnet_diagnostic.CA1063.severity = none diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs index 745fc05f..bad1c7e3 100644 --- a/IOB-WIN/IobSiemens.cs +++ b/IOB-WIN/IobSiemens.cs @@ -10,7 +10,7 @@ using System.Net.NetworkInformation; namespace IOB_WIN { - public class IobSiemens : IobGeneric + public class IobSiemens : IobGeneric, IDisposable { /* -------------------------------------------------------------------------------- * Controlli SIEMENS tramite libreria S7.net @@ -348,35 +348,42 @@ namespace IOB_WIN public IobSiemens(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { memMap = new plcMemMap(); - // gestione invio ritardato contapezzi - pzCountDelay = utils.CRI("pzCountDelay"); - lastPzCountSend = DateTime.Now; - lastWarnODL = DateTime.Now; - // inizializzo parametri... - parametri = new connParamS7() + if (IOBConf != null) { - ipAdrr = "127.0.0.1", - tipoCpu = CpuType.S7200, - slot = 0, - rack = 0, - pingMsTimeout = IOBConf.pingMsTimeout, - memAddrRead = "DB1.DBB0", - memAddrWrite = "DB2.DBB0", - memSizeRead = 0, - memSizeWrite = 0 - }; - setParamPlc(); + // gestione invio ritardato contapezzi + pzCountDelay = utils.CRI("pzCountDelay"); + lastPzCountSend = DateTime.Now; + lastWarnODL = DateTime.Now; + // inizializzo parametri... + parametri = new connParamS7() + { + ipAdrr = "127.0.0.1", + tipoCpu = CpuType.S7200, + slot = 0, + rack = 0, + pingMsTimeout = IOBConf.pingMsTimeout, + memAddrRead = "DB1.DBB0", + memAddrWrite = "DB2.DBB0", + memSizeRead = 0, + memSizeWrite = 0 + }; + setParamPlc(); - // salvo info su conf IOB... - string iobConfSer = ""; - try - { - iobConfSer = JsonConvert.SerializeObject(IOBConf); + // salvo info su conf IOB... + string iobConfSer = ""; + try + { + iobConfSer = JsonConvert.SerializeObject(IOBConf); + } + catch + { } + // finito! + lgInfo($"Init IOB, con {iobConfSer}"); + } + else + { + lgError("Impossibile avviare, IOBConf nullo/non valido!"); } - catch - { } - // finito! - lgInfo($"Init IOB, con {iobConfSer}"); } /// @@ -505,7 +512,7 @@ namespace IOB_WIN try { // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area) - if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "") + if (cIobConf.optPar.Count > 0 && !string.IsNullOrWhiteSpace(getOptPar("PZCOUNT_MODE"))) { if (getOptPar("PZCOUNT_MODE").StartsWith("STD")) { @@ -672,7 +679,7 @@ namespace IOB_WIN try { // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area) - if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "") + if (cIobConf.optPar.Count > 0 && !string.IsNullOrWhiteSpace(getOptPar("PZCOUNT_MODE"))) { string memAddr = getOptPar("PZCOUNT_MODE"); if (memAddr.StartsWith("STD")) @@ -952,6 +959,13 @@ namespace IOB_WIN } return outVal; } + /// + /// Metodo dispose x il currPLC contenuto + /// + public void Dispose() + { + currPLC.Dispose(); + } #endregion } diff --git a/IOB-WIN/IobSiemensFape.cs b/IOB-WIN/IobSiemensFape.cs index db148c16..48695eb1 100644 --- a/IOB-WIN/IobSiemensFape.cs +++ b/IOB-WIN/IobSiemensFape.cs @@ -181,7 +181,7 @@ namespace IOB_WIN { currODL = utils.callUrl(urlGetCurrODL); // solo SE HO un ODL... - if (currODL == "" || currODL == "0") + if (string.IsNullOrWhiteSpace(currODL) || currODL == "0") { if (periodicLog) { @@ -207,7 +207,7 @@ namespace IOB_WIN lastWarnODL = DateTime.Now; } } - if (currODL != null && currODL != "" && currODL != "0") + if (!string.IsNullOrWhiteSpace(currODL) && currODL != "0") { // ora processo il contapezzi... // controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture