From a8ae287334366fa2987b0e81e5725f869ba1be53 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 27 Nov 2019 15:35:14 +0100 Subject: [PATCH] Update con gestione opzionale num max ping retry se rete non stabile --- IOB-UT/IOB-UT.csproj | 4 +- IOB-WIN/DATA/CONF/INTERCL_02.ini | 3 +- IOB-WIN/IobGeneric.cs | 75 +++++++++++++++++++++----------- IOB-WIN/IobKawasaki.cs | 4 +- IOB-WIN/IobMTC.cs | 4 +- IOB-WIN/IobOmron.cs | 6 +-- IOB-WIN/IobSiemens.cs | 6 +-- IOB-WIN/IobWPS.cs | 2 +- Jenkinsfile | 2 +- 9 files changed, 66 insertions(+), 40 deletions(-) diff --git a/IOB-UT/IOB-UT.csproj b/IOB-UT/IOB-UT.csproj index 1679b1a5..21469a13 100644 --- a/IOB-UT/IOB-UT.csproj +++ b/IOB-UT/IOB-UT.csproj @@ -96,7 +96,9 @@ - + + Component + diff --git a/IOB-WIN/DATA/CONF/INTERCL_02.ini b/IOB-WIN/DATA/CONF/INTERCL_02.ini index 9485aab6..25ef319b 100644 --- a/IOB-WIN/DATA/CONF/INTERCL_02.ini +++ b/IOB-WIN/DATA/CONF/INTERCL_02.ini @@ -56,7 +56,8 @@ PZCOUNT_MODE=STD.DM20.2 DISABLE_PZCOUNT=TRUE ENABLE_DYN_DATA=TRUE FORCE_DYN_DATA=TRUE - +NEW_DYN_DATA=TRUE +MAX_PING_RETRY=5 ; conf parametri memoria READ/WRITE PARAM_CONF=INTERCL_02.json diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index cadb0590..854726f3 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -13,7 +13,6 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Text; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -702,7 +701,23 @@ namespace IOB_WIN protected virtual void setParamPlc() { loadMemConf(); - } + fixDefaultPar(); + } + /// + /// Imposta eventuali altri valori default + /// + private void fixDefaultPar() + { + // parametro max tentativi PING... + string s_maxPingRetry = getOptPar("MAX_PING_RETRY"); + if (!string.IsNullOrEmpty(s_maxPingRetry)) + { + int numRetry = 5; + int.TryParse(s_maxPingRetry, out numRetry); + maxPingRetry = numRetry; + } + } + /// /// Effettua logging INFO corretto impostanto anche la variabile IOB prima di scrivere... /// @@ -1591,6 +1606,10 @@ namespace IOB_WIN _connOk = value; } } + /// + /// Max tentativi ping permessi (default: 5) + /// + protected int maxPingRetry { get; set; } = 5; /// /// indica se ping disabilitato da optPar @@ -1605,10 +1624,10 @@ namespace IOB_WIN } } /// - /// test ping all'indirizzo impostato nei parametri + /// test ping all'indirizzo PLC/CNC impostato nei parametri /// /// - protected IPStatus testPing + protected IPStatus testPingMachine { get { @@ -1622,12 +1641,14 @@ namespace IOB_WIN { IPAddress address; PingReply reply; - Ping pingSender = new Ping(); - address = IPAddress.Loopback; - IPAddress.TryParse(cIobConf.cncIpAddr, out address); - int pingMsTimeout = cIobConf.pingMsTimeout; - reply = pingSender.Send(address, pingMsTimeout); - answ = reply.Status; + using (Ping pingSender = new Ping()) + { + address = IPAddress.Loopback; + IPAddress.TryParse(cIobConf.cncIpAddr, out address); + int pingMsTimeout = cIobConf.pingMsTimeout; + reply = pingSender.Send(address, pingMsTimeout); + answ = reply.Status; + } } return answ; } @@ -2495,24 +2516,26 @@ namespace IOB_WIN IPStatus answ = IPStatus.Unknown; ; IPAddress address; PingReply reply; - Ping pingSender = new Ping(); - address = IPAddress.Loopback; - int maxRetry = 5; - int numRetry = 1; ; - string ipAdrr = cIobConf.serverData.MPIP.Replace("http://", "").Replace("https://", ""); - IPAddress.TryParse(ipAdrr, out address); - reply = pingSender.Send(address, pingServerMsTimeout); - // se ho timeout riprovo... - while (reply.Status != IPStatus.Success && numRetry < maxRetry) + using (Ping pingSender = new Ping()) { - lgInfo($"Ping KO | reply: {reply.Status} --> retry"); - reply = pingSender.Send(address, pingServerMsTimeout * numRetry / 2); - numRetry++; - if (reply.Status == IPStatus.Success) + address = IPAddress.Loopback; + int maxRetry = maxPingRetry + 1; + int numRetry = 1; ; + string ipAdrr = cIobConf.serverData.MPIP.Replace("http://", "").Replace("https://", ""); + IPAddress.TryParse(ipAdrr, out address); + reply = pingSender.Send(address, pingServerMsTimeout); + // se ho timeout riprovo... + while (reply.Status != IPStatus.Success && numRetry < maxRetry) { - lgInfo("PING OK!"); - break; - } + lgInfo($"Ping KO | reply: {reply.Status} --> retry"); + reply = pingSender.Send(address, pingServerMsTimeout * numRetry / 2); + numRetry++; + if (reply.Status == IPStatus.Success) + { + lgInfo("PING OK!"); + break; + } + } } answ = reply.Status; return answ; diff --git a/IOB-WIN/IobKawasaki.cs b/IOB-WIN/IobKawasaki.cs index 7454921a..0d5e3805 100644 --- a/IOB-WIN/IobKawasaki.cs +++ b/IOB-WIN/IobKawasaki.cs @@ -309,7 +309,7 @@ namespace IOB_WIN { lgInfo("Refreshing connection..."); // ora tento avvio PLC... SE PING OK... - if (testPing == IPStatus.Success) + if (testPingMachine == IPStatus.Success) { try { @@ -416,7 +416,7 @@ namespace IOB_WIN // in primis salvo data ping... lastPING = DateTime.Now; // se passa il ping faccio il resto... - if (testPing == IPStatus.Success) + if (testPingMachine == IPStatus.Success) { string szStatusConnection = ""; try diff --git a/IOB-WIN/IobMTC.cs b/IOB-WIN/IobMTC.cs index 8951be81..ed878c38 100644 --- a/IOB-WIN/IobMTC.cs +++ b/IOB-WIN/IobMTC.cs @@ -508,7 +508,7 @@ namespace IOB_WIN // in primis salvo data ping... lastPING = DateTime.Now; // se passa il ping faccio il resto... - if (testPing == IPStatus.Success) + if (testPingMachine == IPStatus.Success) { string szStatusConnection = ""; try @@ -733,7 +733,7 @@ namespace IOB_WIN ----------------------------------------------------- */ // Controllo booleano PING e POWERON... - bool checkPing = (testPing == IPStatus.Success); + bool checkPing = (testPingMachine == IPStatus.Success); string currPowerOn = ""; try { diff --git a/IOB-WIN/IobOmron.cs b/IOB-WIN/IobOmron.cs index 0c5d5c47..c48cc83e 100644 --- a/IOB-WIN/IobOmron.cs +++ b/IOB-WIN/IobOmron.cs @@ -258,7 +258,7 @@ namespace IOB_WIN // in primis salvo data ping... lastPING = DateTime.Now; // se passa il ping faccio il resto... - if (testPing == IPStatus.Success) + if (testPingMachine == IPStatus.Success) { string szStatusConnection = ""; try @@ -575,7 +575,7 @@ namespace IOB_WIN * B6: carico AUTOBOTTE ----------------------------------------------------- */ // bit 0 (poweron) imposto a 1 SE pingo... - B_input = testPing == IPStatus.Success ? 1 : 0; + B_input = testPingMachine == IPStatus.Success ? 1 : 0; bool caricoSilos = ((memReadCIO_IN[55] & (1 << 2)) != 0); bool caricoAutobotte = ((memReadCIO_IN[50] & (1 << 2)) != 0); @@ -611,7 +611,7 @@ namespace IOB_WIN { currODL = utils.callUrl(urlGetCurrODL); // solo SE HO un ODL... - if (currODL == "" || currODL == "0") + if (string.IsNullOrEmpty(currODL) || currODL == "0") { if (periodicLog) { diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs index 8fd5fbd1..2da971eb 100644 --- a/IOB-WIN/IobSiemens.cs +++ b/IOB-WIN/IobSiemens.cs @@ -734,7 +734,7 @@ namespace IOB_WIN { bool answ = false; - IPStatus pingStatus = testPing; + IPStatus pingStatus = testPingMachine; // se passa il ping faccio il resto... if (pingStatus != IPStatus.Success) { @@ -810,7 +810,7 @@ namespace IOB_WIN lgError(exc, "Errore in parse parametri da IOBConf"); } // ora tento avvio PLC... SE PING OK... - IPStatus esitoPing = testPing; + IPStatus esitoPing = testPingMachine; if (esitoPing == IPStatus.Success) { needRefresh = false; @@ -946,7 +946,7 @@ namespace IOB_WIN // in primis salvo data ping... lastPING = DateTime.Now; // se passa il ping faccio il resto... - if (testPing == IPStatus.Success) + if (testPingMachine == IPStatus.Success) { string szStatusConnection = ""; try diff --git a/IOB-WIN/IobWPS.cs b/IOB-WIN/IobWPS.cs index 33fd6ca3..79bf7085 100644 --- a/IOB-WIN/IobWPS.cs +++ b/IOB-WIN/IobWPS.cs @@ -138,7 +138,7 @@ namespace IOB_WIN public override void tryConnect() { // controllo ping --> segno connected... - connectionOk = (testPing == IPStatus.Success); + connectionOk = (testPingMachine == IPStatus.Success); if (connectionOk) { try diff --git a/Jenkinsfile b/Jenkinsfile index 8e0a5c0f..c3763dfe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=545']) { + withEnv(['NEXT_BUILD_NUMBER=547']) { // env.versionNumber = VersionNumber(versionNumberString : '2.5.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.5.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'