Gestione allarmi:
- spostato da ModBus/Siemens a IobGeneric metodo hasAlarms - implementaizoni in override di base
This commit is contained in:
+193
-1
@@ -1958,6 +1958,185 @@ namespace IOB_WIN_NEXT
|
||||
return outVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementazione di riferimento della verifica stato allarmi
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual int getAlarmStatus(BaseAlarmConf item)
|
||||
{
|
||||
int answ = 0;
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Implementazione di riferimento della verifica stato allarmi formato UInt
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual uint getAlarmStatusUInt(BaseAlarmConf item)
|
||||
{
|
||||
uint answ = 0;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica presenza eventuali allarmi
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual bool hasAlarms()
|
||||
{
|
||||
bool answ = false;
|
||||
int numErrors = 0;
|
||||
int currStatus = 0;
|
||||
int[] listInt = new int[2];
|
||||
if (alarmMaps != null)
|
||||
{
|
||||
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
|
||||
foreach (var item in alarmMaps)
|
||||
{
|
||||
// banchi in array Int16 --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
#if false
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
{
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
#endif
|
||||
currStatus = getAlarmStatus(item);
|
||||
|
||||
// aggiornamento blink counters dato nuovo valore
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
|
||||
// calcolo indice errori
|
||||
if ((uint)(item.alarmsMask[i] & currStatus) > 0)
|
||||
{
|
||||
numErrors++;
|
||||
}
|
||||
// verifico SE sia variato... confronto allarmi filtrato stile blink per
|
||||
// bit status:
|
||||
// - allarmi che iniziano per # IGNORATI
|
||||
// - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il
|
||||
// fronte di discesa
|
||||
if (item.isChanged(i, (uint)currStatus))
|
||||
{
|
||||
// registro gli allarmi attivi e trasmetto...
|
||||
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages))
|
||||
{
|
||||
// se inviato --> salvo stato da current...
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
answ = numErrors > 0;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processing degli allarmi (se presenti e gestiti)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual Dictionary<string, string> getAlarmData()
|
||||
{
|
||||
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
||||
// ora aggiungo (se ci fossero) gli allarmi...
|
||||
if (alarmMaps != null && alarmMaps.Count > 0)
|
||||
{
|
||||
if (hasAlarms())
|
||||
{
|
||||
string bankVal = "";
|
||||
foreach (var item in alarmMaps)
|
||||
{
|
||||
bankVal = "";
|
||||
var currState = currAlarmsState(item);
|
||||
// calcolo vettore stringa degli allarmi...
|
||||
bankVal = getAlarmState(item, currState);
|
||||
bankVal = string.IsNullOrEmpty(bankVal) ? "OK" : bankVal;
|
||||
saveAlarmString(ref outVal, bankVal, item.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (periodicLog || outVal.Count > 0)
|
||||
{
|
||||
lgDebug($"Esito getAlarmData: {outVal.Count} allarmi attivi/validi in outVal");
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce stato allarmi in formato byte[]
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected byte[] currAlarmsState(BaseAlarmConf item)
|
||||
{
|
||||
byte[] answ = new byte[item.size];
|
||||
int currStatus = 0;
|
||||
int[] listInt = new int[2];
|
||||
// banchi in array Int16 --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
#if false
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
{
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
#endif
|
||||
currStatus = getAlarmStatus(item);
|
||||
|
||||
// aggiornamento blink counters dato nuovo valore
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
|
||||
// calcolo indice errori
|
||||
if ((uint)(item.alarmsMask[i] & currStatus) > 0)
|
||||
{
|
||||
var currByte = BitConverter.GetBytes(currStatus);
|
||||
// salvo nell'array di byte
|
||||
Buffer.BlockCopy(currByte, 0, answ, i * 2, 2);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cerca se esiste il parametro opzionale e lo restituisce
|
||||
/// </summary>
|
||||
@@ -2568,6 +2747,19 @@ namespace IOB_WIN_NEXT
|
||||
if (connectionOk)
|
||||
{
|
||||
currDynData = getDynData();
|
||||
var currAlarmData = getAlarmData();
|
||||
// se ho allarmi
|
||||
if (currAlarmData != null && currAlarmData.Count > 0)
|
||||
{
|
||||
foreach (var item in currAlarmData)
|
||||
{
|
||||
if (!currDynData.ContainsKey(item.Key))
|
||||
{
|
||||
// aggiungo!
|
||||
currDynData.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
string sVal = "";
|
||||
@@ -4637,6 +4829,7 @@ namespace IOB_WIN_NEXT
|
||||
lgInfoStartup($"Apertura file {jsonFileName}");
|
||||
StreamReader reader = new StreamReader(jsonFileName);
|
||||
string jsonData = reader.ReadToEnd();
|
||||
reader.Dispose();
|
||||
if (!string.IsNullOrEmpty(jsonData))
|
||||
{
|
||||
lgInfoStartup($"File json ALLARMI composto da {jsonData.Length} caratteri");
|
||||
@@ -4654,7 +4847,6 @@ namespace IOB_WIN_NEXT
|
||||
{
|
||||
lgError("Errore in loadMemConf: file json vuoto!");
|
||||
}
|
||||
reader.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -243,6 +243,8 @@ namespace IOB_WIN_NEXT
|
||||
outVal = new Dictionary<string, string>();
|
||||
tryConnect();
|
||||
}
|
||||
// refuso, gestito da getAlarmData di IobGeneric
|
||||
#if false
|
||||
// ora aggiungo (se ci fossero) gli allarmi...
|
||||
if (alarmMaps != null && alarmMaps.Count > 0)
|
||||
{
|
||||
@@ -259,7 +261,8 @@ namespace IOB_WIN_NEXT
|
||||
saveAlarmString(ref outVal, bankVal, item.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -599,74 +602,103 @@ namespace IOB_WIN_NEXT
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected bool hasAlarms
|
||||
protected override int getAlarmStatus(BaseAlarmConf item)
|
||||
{
|
||||
get
|
||||
int answ = 0;
|
||||
int[] listInt = new int[2];
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
{
|
||||
bool answ = false;
|
||||
int numErrors = 0;
|
||||
int currStatus = 0;
|
||||
int[] listInt = new int[2];
|
||||
if (alarmMaps != null)
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
{
|
||||
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
|
||||
foreach (var item in alarmMaps)
|
||||
try
|
||||
{
|
||||
// banchi in array Int16 --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
answ = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
// refuso: usato metodo base IobGeneric
|
||||
protected override bool hasAlarms()
|
||||
{
|
||||
bool answ = false;
|
||||
int numErrors = 0;
|
||||
int currStatus = 0;
|
||||
int[] listInt = new int[2];
|
||||
if (alarmMaps != null)
|
||||
{
|
||||
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
|
||||
foreach (var item in alarmMaps)
|
||||
{
|
||||
// banchi in array Int16 --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
{
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
{
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
|
||||
// aggiornamento blink counters dato nuovo valore
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
// aggiornamento blink counters dato nuovo valore
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
|
||||
// calcolo indice errori
|
||||
if ((uint)(item.alarmsMask[i] & currStatus) > 0)
|
||||
// calcolo indice errori
|
||||
if ((uint)(item.alarmsMask[i] & currStatus) > 0)
|
||||
{
|
||||
numErrors++;
|
||||
}
|
||||
// verifico SE sia variato... confronto allarmi filtrato stile blink per
|
||||
// bit status:
|
||||
// - allarmi che iniziano per # IGNORATI
|
||||
// - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il
|
||||
// fronte di discesa
|
||||
if (item.isChanged(i, (uint)currStatus))
|
||||
{
|
||||
// registro gli allarmi attivi e trasmetto...
|
||||
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages))
|
||||
{
|
||||
numErrors++;
|
||||
}
|
||||
// verifico SE sia variato... confronto allarmi filtrato stile blink per
|
||||
// bit status:
|
||||
// - allarmi che iniziano per # IGNORATI
|
||||
// - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il
|
||||
// fronte di discesa
|
||||
if (item.isChanged(i, (uint)currStatus))
|
||||
{
|
||||
// registro gli allarmi attivi e trasmetto...
|
||||
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages))
|
||||
{
|
||||
// se inviato --> salvo stato da current...
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
}
|
||||
// se inviato --> salvo stato da current...
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
answ = numErrors > 0;
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
answ = numErrors > 0;
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario delle ultime operazioni di scrittura per OGNI memoria (in modo che fa log
|
||||
@@ -678,6 +710,7 @@ namespace IOB_WIN_NEXT
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Restituisce stato allarmi in formato byte[]
|
||||
/// </summary>
|
||||
@@ -726,7 +759,8 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
|
||||
// processo dagli stati + gravi...
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
|
||||
// processo dagli stati + gravi...
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
|
||||
// processo dagli stati + gravi...
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace IOB_WIN_NEXT
|
||||
// hard coded
|
||||
int statusReg = 41094;
|
||||
// deve avere allarmi (è un allarme EStop)
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
int[] listInt = new int[2];
|
||||
listInt = HoldingRegisterLUT[statusReg];
|
||||
@@ -150,7 +150,7 @@ namespace IOB_WIN_NEXT
|
||||
{
|
||||
byteSignals += (1 << 7);
|
||||
}
|
||||
else if (hasAlarms)
|
||||
else if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
+30
-32
@@ -1146,52 +1146,50 @@ namespace IOB_WIN_NEXT
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifica presenza allarmi (tra quelli configurati)
|
||||
/// </summary>
|
||||
protected bool hasAlarms
|
||||
protected override bool hasAlarms()
|
||||
{
|
||||
get
|
||||
bool answ = false;
|
||||
int numErrors = 0;
|
||||
uint currStatus = 0;
|
||||
if (alarmMaps != null)
|
||||
{
|
||||
bool answ = false;
|
||||
int numErrors = 0;
|
||||
uint currStatus = 0;
|
||||
if (alarmMaps != null)
|
||||
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
|
||||
foreach (var item in alarmMaps)
|
||||
{
|
||||
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
|
||||
foreach (var item in alarmMaps)
|
||||
// banchi in WORD (2 byte) --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
// banchi in WORD (2 byte) --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
currStatus = S7.Net.Types.Counter.FromByteArray(RawInput.Skip(item.index + 2 * i).Take(2).ToArray());
|
||||
// verifica e decremento blink...
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
currStatus = S7.Net.Types.Counter.FromByteArray(RawInput.Skip(item.index + 2 * i).Take(2).ToArray());
|
||||
// verifica e decremento blink...
|
||||
item.checkBlinkCounter(i, (uint)currStatus);
|
||||
|
||||
// verifico SE sia variato... confronto allarmi filtrato stile blink per
|
||||
// bit status:
|
||||
// - allarmi che iniziano per # IGNORATI
|
||||
// - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il
|
||||
// fronte di discesa
|
||||
if (item.isChanged(i, currStatus))
|
||||
// verifico SE sia variato... confronto allarmi filtrato stile blink per
|
||||
// bit status:
|
||||
// - allarmi che iniziano per # IGNORATI
|
||||
// - altri allarmi con un countdown da MAX_COUNTER_BLINK a 0 per il
|
||||
// fronte di discesa
|
||||
if (item.isChanged(i, currStatus))
|
||||
{
|
||||
if (currStatus > 0)
|
||||
{
|
||||
if (currStatus > 0)
|
||||
{
|
||||
numErrors++;
|
||||
}
|
||||
// registro gli allarmi attivi e trasmetto...
|
||||
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages))
|
||||
{
|
||||
// se inviato --> salvo stato da current...
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
}
|
||||
numErrors++;
|
||||
}
|
||||
// registro gli allarmi attivi e trasmetto...
|
||||
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], (uint)(item.alarmsMask[i] & currStatus), item.messages))
|
||||
{
|
||||
// se inviato --> salvo stato da current...
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
answ = numErrors > 0;
|
||||
return answ;
|
||||
}
|
||||
answ = numErrors > 0;
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
|
||||
// processo dagli stati + gravi...
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
|
||||
// processo dagli stati + gravi...
|
||||
if (hasAlarms)
|
||||
if (hasAlarms())
|
||||
{
|
||||
byteSignals += (1 << 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user