Update con gestione opzionale num max ping retry se rete non stabile

This commit is contained in:
Samuele E. Locatelli
2019-11-27 15:35:14 +01:00
parent 128ac5c644
commit a8ae287334
9 changed files with 66 additions and 40 deletions
+3 -1
View File
@@ -96,7 +96,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="baseUtils.cs" />
<Compile Include="baseUtils.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="BinaryFormatter.cs" />
<Compile Include="fileMover.cs" />
<Compile Include="IniFile.cs" />
+2 -1
View File
@@ -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
+49 -26
View File
@@ -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();
}
/// <summary>
/// Imposta eventuali altri valori default
/// </summary>
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;
}
}
/// <summary>
/// Effettua logging INFO corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
@@ -1591,6 +1606,10 @@ namespace IOB_WIN
_connOk = value;
}
}
/// <summary>
/// Max tentativi ping permessi (default: 5)
/// </summary>
protected int maxPingRetry { get; set; } = 5;
/// <summary>
/// indica se ping disabilitato da optPar
@@ -1605,10 +1624,10 @@ namespace IOB_WIN
}
}
/// <summary>
/// test ping all'indirizzo impostato nei parametri
/// test ping all'indirizzo PLC/CNC impostato nei parametri
/// </summary>
/// <returns></returns>
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;
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
{
+3 -3
View File
@@ -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)
{
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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
Vendored
+1 -1
View File
@@ -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'