Merge branch 'release/ModBusFix01'

This commit is contained in:
Samuele Locatelli
2021-09-29 18:36:10 +02:00
2 changed files with 16 additions and 21 deletions
+6 -4
View File
@@ -535,7 +535,7 @@ namespace IOB_WIN_NEXT
{
address = IPAddress.Loopback;
int maxRetry = maxPingRetry + 1;
int numRetry = 1; ;
int numRetry = 1;
string ipAddr = cIobConf.serverData.MPIP.Replace($"{cIobConf.serverData.TRANSP}://", "");
IPAddress.TryParse(ipAddr, out address);
// se null --> provo DNS...
@@ -552,21 +552,23 @@ namespace IOB_WIN_NEXT
// se != null --> uso address...
if (address != null)
{
reply = pingSender.Send(address, 100);
reply = pingSender.Send(address, 300);
}
else
{
reply = pingSender.Send(cIobConf.cncIpAddr, 100);
reply = pingSender.Send(cIobConf.cncIpAddr, 300);
}
}
catch
{
reply = pingSender.Send(IPAddress.Loopback, 100);
reply = pingSender.Send(IPAddress.Loopback, 300);
}
// se ho timeout riprovo...
while (reply.Status != IPStatus.Success && numRetry < maxRetry)
{
lgInfo($"Server Ping KO | reply: {reply.Status} --> retry");
var rand = new Random();
Thread.Sleep(rand.Next(150, 500));
reply = pingSender.Send(address, pingServerMsTimeout * numRetry / 2);
numRetry++;
if (reply.Status == IPStatus.Success)
+10 -17
View File
@@ -241,11 +241,11 @@ namespace IOB_WIN_NEXT
}
else
{
lgError($"getDynData: valore scartato x limiti min/max | val: {valore} | min-max: {item.Value.minVal}-{item.Value.maxVal}");
lgError($"getDynData: valore scartato x limiti min/max | {item.Key} | val: {valore} | min-max: {item.Value.minVal}-{item.Value.maxVal} | deltaVal: {deltaVal}");
if (enableRetry)
{
readErrorList.Add(item.Key, item.Value);
lgInfo($"valore fuori limiti --> rimesso in coda lettura | parametro: {item.Key}");
lgInfo($"--> rimesso in coda lettura | parametro: {item.Key} | index: {item.Value.index} | size: {item.Value.size}");
}
}
}
@@ -704,6 +704,7 @@ namespace IOB_WIN_NEXT
// se avessi acnora errori --> disconnetto
if (readErrorList.Count > 0)
{
lgInfo("Trovati valori non validi al secondo tentativo --> resetto adapter con tryDisconnect!");
tryDisconnect();
}
}
@@ -1269,24 +1270,16 @@ namespace IOB_WIN_NEXT
/// </summary>
public override void tryDisconnect()
{
if (connectionOk)
lgInfo("Richiesta disconnessione adapter ModBusTCP!");
try
{
string szStatusConnection = "";
try
{
currPLC.Disconnect();
connectionOk = false;
lgInfo(szStatusConnection);
lgInfo("Effettuata disconnessione adapter ModBusTCP!");
}
catch (Exception exc)
{
lgFatal(exc, "Errore nella disconnessione dall'adapter ModBusTCP");
}
currPLC.Disconnect();
connectionOk = false;
lgInfo("Effettuata disconnessione adapter ModBusTCP!");
}
else
catch (Exception exc)
{
lgError("IMPOSSIBILE effettuare disconnessione ModBusTCP: Connessione non disponibile...");
lgFatal($"Errore nella disconnessione dall'adapter ModBusTCP{Environment.NewLine}{exc}");
}
}