reset outval x modbus

This commit is contained in:
Samuele Locatelli
2021-11-03 15:21:23 +01:00
parent f6b6c7985a
commit b1a0aa5406
4 changed files with 18 additions and 89 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ namespace IOB_UT_NEXT
#region Public Properties
/// <summary>
/// Elenco dei contatori blink (x gestione caso frponte salita/discesa segnale hce blinka)
/// Elenco dei contatori blink (x gestione caso fronte salita/discesa segnale che blinka)
/// </summary>
public int[] alarmsBlinkCounter { get; set; }
+6 -4
View File
@@ -541,6 +541,11 @@ namespace IOB_WIN_NEXT
int maxRetry = maxPingRetry + 1;
int numRetry = 1;
string ipAddr = cIobConf.serverData.MPIP.Replace($"{cIobConf.serverData.TRANSP}://", "");
// fix se fosse ip + porta...
if (ipAddr.IndexOf(":") >= 0)
{
ipAddr = ipAddr.Substring(0, ipAddr.IndexOf(":"));
}
IPAddress.TryParse(ipAddr, out address);
// se null --> provo DNS...
if (address == null)
@@ -4127,10 +4132,7 @@ namespace IOB_WIN_NEXT
if (enableByApp || enableByIob)
{
if (periodicLog)
{
lgInfo("Inizio processDynData");
}
lgInfo("Inizio processDynData");
if (connectionOk)
{
currDynData = getDynData();
+11 -7
View File
@@ -222,6 +222,7 @@ namespace IOB_WIN_NEXT
foreach (var item in memItemList)
{
double valore = 0;
double valoreScal = 0;
bool dataOk = false;
// in primis DEVO determinare di quale TIPO di valore ho bisogno... dalla PRIMA cifra di memAddr...
modBusAddrType memAddrType = getAddrType(item.Value.memAddr);
@@ -257,12 +258,13 @@ namespace IOB_WIN_NEXT
if (dataOk)
{
// moltiplico x fattore conversione...
valore = valore * item.Value.factor;
saveValue(ref outVal, valore, item.Key);
valoreScal = valore * item.Value.factor;
saveValue(ref outVal, valoreScal, item.Key);
lgInfo($"getDynData: valore ricevuto | {item.Key} | val: {valore} | valoreScal: {valoreScal}");
}
else
{
lgError($"getDynData: valore scartato x limiti min/max | {item.Key} | val: {valore} | min-max: {item.Value.minVal}-{item.Value.maxVal} | deltaVal: {deltaVal}");
lgError($"getDynData: valore scartato x limiti min/max | {item.Key} | val: {valore} | valoreScal: {valoreScal} | min-max: {item.Value.minVal}-{item.Value.maxVal} | deltaVal: {deltaVal}");
readErrorList.Add(item.Key, item.Value);
lgInfo($"--> rimesso in coda lettura | parametro: {item.Key} | index: {item.Value.index} | size: {item.Value.size}");
}
@@ -779,15 +781,16 @@ namespace IOB_WIN_NEXT
// se qualcosa è andato storto riprovo a caricare SOLO gli errori... 1 sola volta
if (readErrorList.Count > 0)
{
lgInfo($"Effettuo rilettura per {readErrorList.Count} variabili");
readErrorListRepeat = getDataDictionary(readErrorList, ref outVal);
}
// se avessi acnora errori --> disconnetto
// se avessi ancora errori --> disconnetto
if (readErrorListRepeat.Count > 0)
{
lgInfo("Trovati valori non validi al secondo tentativo --> resetto adapter con tryDisconnect!");
//// rendo non valida lettura dati
//lastReadPLC = DateTime.Now.AddMinutes(-4);
lgInfo("Trovati valori non validi al secondo tentativo --> invalido valori letti e resetto adapter con tryDisconnect!");
tryDisconnect();
// invalido output
outVal = new Dictionary<string, string>();
tryConnect();
}
else
@@ -804,6 +807,7 @@ namespace IOB_WIN_NEXT
{
lgError(exc, "Errore in getDynData x ModBus TCP PLC --> ciclo disconnect/reconnect");
tryDisconnect();
outVal = new Dictionary<string, string>();
tryConnect();
}
}
-77
View File
@@ -185,83 +185,6 @@ namespace IOB_WIN_NEXT
#endregion Protected Methods
#if false
/// <summary>
/// Processo i task richiesti e li elimino dalla coda 1:1
/// </summary>
/// <param name="task2exe"></param>
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
{
lgInfo($"Chiamata executeTasks specifica ModBus TCP HAM: {task2exe.Count} task ricevuti");
// Verificare il protocollo: dovrebeb togliere SOLO i task eseguiti...
Dictionary<string, string> taskDone = new Dictionary<string, string>();
bool taskOk = false;
string taskVal = "";
// inizio con 1 byte di default
byte[] MemBlock = new byte[1];
string memAddrWrite = "";
if (task2exe != null)
{
// cerco task specifici
foreach (var item in task2exe)
{
taskOk = false;
taskVal = "";
// 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.setProg:
case taskType.sendWatchDogMes2Plc:
case taskType.startSetup:
case taskType.stopSetup:
case taskType.setPzComm:
case taskType.setArt:
case taskType.setComm:
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
break;
case taskType.setParameter:
// richiedo da URL i parametri WRITE da popolare
lgInfo("Chiamata processMemWriteRequests");
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;
default:
taskVal = "SKIPPED | NO EXEC";
break;
}
// aggiungo task!
taskDone.Add(item.Key, taskVal);
taskOk = true;
}
}
return taskDone;
}
#endif
#region Public Methods
/// <summary>