Merge branch 'release/AddPArametricBitConditionsParams'

This commit is contained in:
Samuele Locatelli
2022-11-10 17:17:15 +01:00
10 changed files with 303 additions and 111 deletions
+89
View File
@@ -0,0 +1,89 @@
namespace IOB_UT_NEXT
{
public class BitConditionCheck
{
#region Public Constructors
/// <summary>
/// Inizializza un oggetto da usare per testing bit condition
/// </summary>
/// <param name="keyName">Nome della chiave registrata</param>
/// <param name="rawConf">Configuraizone nel formato BaseAddr.BitNum=ValOk</param>
public BitConditionCheck(string keyName, string rawConf)
{
Logging.Instance.Info($"Init BitConditionCheck | {keyName} | {rawConf}");
KeyName = keyName;
RawVal = rawConf;
string sVal = "";
int valDecoded = 0;
// check preliminare
if (rawConf.Contains(".") && rawConf.Contains("="))
{
// splitto per "="...
var splitCond = rawConf.Split('=');
sVal = splitCond[1];
int.TryParse(sVal, out valDecoded);
ValOk = valDecoded;
// il restante splitto per "."
var splitMem = splitCond[0].Split('.');
// BaseAddr
sVal = splitMem[0];
int.TryParse(sVal, out valDecoded);
BaseAddr = valDecoded;
// BitNum
sVal = splitMem[1];
int.TryParse(sVal, out valDecoded);
BitNum = valDecoded;
}
}
/// <summary>
/// Inizializza un oggetto fake/empty
/// </summary>
public BitConditionCheck()
{
Logging.Instance.Info("Init empty BitConditionCheck");
}
/// <summary>
/// Inizializza un oggetto solo per key
/// </summary>
/// <param name="keyName">Nome della chiave registrata</param>
public BitConditionCheck(string keyName)
{
Logging.Instance.Info($"Init BitConditionCheck | {keyName}");
KeyName = keyName;
}
#endregion Public Constructors
#region Public Properties
/// <summary>
/// Indirizzo base x memoria da testare come bit condition
/// </summary>
public int BaseAddr { get; set; } = 0;
/// <summary>
/// Numero bit da impiegare
/// </summary>
public int BitNum { get; set; } = 0;
/// <summary>
/// Valore chiave
/// </summary>
public string KeyName { get; set; } = "";
/// <summary>
/// Valore raw decodificato
/// </summary>
public string RawVal { get; set; } = "";
/// <summary>
/// Valore target che porta a condizione OK = true
/// </summary>
public int ValOk { get; set; } = 0;
#endregion Public Properties
}
}
+2
View File
@@ -141,10 +141,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BitConditionCheck.cs" />
<Compile Include="CustomObj.cs" />
<Compile Include="DataExport.cs" />
<Compile Include="Eurom63.cs" />
<Compile Include="IobWinStatus.cs" />
<Compile Include="plcMemMapExt.cs" />
<Compile Include="TCMan.cs" />
<Compile Include="TimeUtils.cs" />
<Compile Include="ToMapo.cs" />
+14
View File
@@ -0,0 +1,14 @@
using MapoSDK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IOB_UT_NEXT
{
public class plcMemMapExt : plcMemMap
{
public Dictionary<string, string> optMemPar { get; set; } = new Dictionary<string, string>();
}
}
+34 -29
View File
@@ -1,36 +1,36 @@
{
"mMapWrite": {
},
"mMapRead": {
"StatusWord": {
"name": "StatusWord",
"description": "Word di Status",
"memAddr": "40002",
"tipoMem": "Int",
"index": 2,
"size": 1,
"func": "POINT",
"period": 90,
"factor": 1,
"minVal": 0,
"maxVal": 65536,
"unit": "BMap"
},
"StatusDetWord": {
"name": "StatusDetWord",
"description": "Word di Status",
"memAddr": "40005",
"tipoMem": "Int",
"index": 5,
"size": 1,
"func": "POINT",
"period": 90,
"factor": 1,
"minVal": 0,
"maxVal": 65536,
"unit": "BMap"
},
//"StatusWord": {
// "name": "StatusWord",
// "description": "Word di Status",
// "memAddr": "40002",
// "tipoMem": "Int",
// "index": 2,
// "size": 1,
// "func": "POINT",
// "period": 90,
// "factor": 1,
// "minVal": 0,
// "maxVal": 65536,
// "unit": "BMap"
//},
//"StatusDetWord": {
// "name": "StatusDetWord",
// "description": "Word di Status",
// "memAddr": "40005",
// "tipoMem": "Int",
// "index": 5,
// "size": 1,
// "func": "POINT",
// "period": 90,
// "factor": 1,
// "minVal": 0,
// "maxVal": 65536,
// "unit": "BMap"
//},
"FreqInverter": {
"name": "FreqInverter",
"description": "Frequenza Inverter",
@@ -101,5 +101,10 @@
"maxVal": 999999999,
"unit": "A"
}
},
"optMemPar": {
"AutoBitCond": "40002.14=1",
"EStopBitCond": "40002.9=0",
"WorkBitCond": "40002.0=1"
}
}
+47 -2
View File
@@ -174,7 +174,7 @@ namespace IOB_WIN_NEXT
/// <summary>
/// Struttura memoria PLC x lettura/scrittura da JSON file
/// </summary>
public plcMemMap memMap;
public plcMemMapExt memMap;
/// <summary>
/// Minimo numero di px da inviare in blocco
@@ -5191,8 +5191,9 @@ namespace IOB_WIN_NEXT
lgInfoStartup($"File json PARAMETRI composto da {jsonData.Length} caratteri");
try
{
memMap = JsonConvert.DeserializeObject<plcMemMap>(jsonData);
memMap = JsonConvert.DeserializeObject<plcMemMapExt>(jsonData);
setupMemMap();
setupOptMemPar();
}
catch (Exception exc)
{
@@ -5246,6 +5247,47 @@ namespace IOB_WIN_NEXT
lgInfoStartup("DONE loadMemConf");
}
/// <summary>
/// Dizionario condizioni di check (opzionali) da usare x valori controllo bitmap (es ModBUs TCP Imax)
/// </summary>
protected Dictionary<string, BitConditionCheck> OptCheckConditions { get; set; } = new Dictionary<string, BitConditionCheck>();
protected virtual void setupOptMemPar()
{
// verifica se siano necessari configuraizoni speciali dalla optMemPar (es per ricerca condizioni status bolleane come ModbusTCP...)
if (memMap.optMemPar != null && memMap.optMemPar.Count > 0)
{
// cerco condizioni speciali x Auto, Estop, Work.. devono essere *BitCond
var listPar2add = memMap.optMemPar.Where(x => x.Key.EndsWith("BitCond")).ToList();
if (listPar2add != null && listPar2add.Count > 0)
{
foreach (var item in listPar2add)
{
addCheckCondition(item.Key, item.Value);
}
}
}
}
/// <summary>
/// Aggiunge in setup memoria la checkCondition ricevuta già "decodificata"
/// </summary>
/// <param name="ompKey">Chiave da aggiungere</param>
/// <param name="ompVal">Valore da decodificare e poi aggiungere</param>
private void addCheckCondition(string ompKey, string ompVal)
{
var newCond = new BitConditionCheck(ompVal);
// cerco x aggiornare o aggiungere...
if (OptCheckConditions.ContainsKey(ompKey))
{
OptCheckConditions[ompKey] = newCond;
}
else
{
OptCheckConditions.Add(ompKey, newCond);
}
}
/// <summary>
/// Metodo da overridare x scrivere DAVVERO i parametri sul PLC
/// </summary>
@@ -6689,6 +6731,9 @@ namespace IOB_WIN_NEXT
}
#endregion Private Methods
}
/// <summary>
+1 -1
View File
@@ -27,7 +27,7 @@ namespace IOB_WIN_NEXT
{
lgInfo("NEW IOB ModBus TCP");
DateTime adesso = DateTime.Now;
memMap = new plcMemMap();
memMap = new plcMemMapExt();
if (IOBConf != null)
{
// gestione invio ritardato contapezzi
+89 -59
View File
@@ -43,51 +43,8 @@ namespace IOB_WIN_NEXT
#endregion Public Constructors
#region Protected Methods
#region Protected Properties
/// <summary>
/// Restituisce status di emergenza
/// </summary>
protected bool EStop
{
get
{
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40002;
// deve avere allarmi (è un allarme EStop)
if (hasAlarms())
{
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[statusReg];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
// hard coded il 9° bit a zero
answ = ((currStatus & (1 << 9)) == 0);
}
return answ;
}
}
/// <summary>
/// Restituisce status di LAVORA, hard coded
/// </summary>
protected bool Work
{
get
{
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40002;
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[statusReg];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
// hard coded il 5° bit
answ = ((currStatus & (1 << 0)) > 0);
return answ;
}
}
/// <summary>
/// Restituisce status di AUTOmatico, hard coded
/// </summary>
@@ -95,6 +52,8 @@ namespace IOB_WIN_NEXT
{
get
{
return testCondition("WorkBitCond");
#if false
bool answ = false;
int currStatus = 0;
// hard coded
@@ -105,9 +64,49 @@ namespace IOB_WIN_NEXT
// hard coded il 5° bit
answ = ((currStatus & (1 << 14)) > 0);
return answ;
#endif
}
}
/// <summary>
/// Restituisce status di ESTOP triggered (triggered = premuta, altrimenti armed)
/// </summary>
protected bool EStopTriggered
{
get
{
return testCondition("EStopBitCond");
}
}
/// <summary>
/// Restituisce status di LAVORA, hard coded
/// </summary>
protected bool Work
{
get
{
return testCondition("WorkBitCond");
#if false
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40002;
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[statusReg];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
// hard coded il 5° bit
answ = ((currStatus & (1 << 0)) > 0);
return answ;
#endif
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
/// </summary>
@@ -137,26 +136,32 @@ namespace IOB_WIN_NEXT
{
byteSignals += (1 << 0);
}
// processo dagli stati + gravi...
if (!EStop)
if (HoldingRegisterLUT != null && HoldingRegisterLUT.Count > 0)
{
byteSignals += (1 << 7);
}
// se emergenza NON premuta (triggered) indico OK (armata...)
if (!EStopTriggered)
{
byteSignals += (1 << 7);
}
// processo dagli stati + gravi...
if (hasAlarms())
{
byteSignals += (1 << 3);
// processo dagli stati + gravi...
if (hasAlarms())
{
byteSignals += (1 << 3);
}
if (Work)
{
byteSignals += (1 << 1);
}
if (!Auto)
{
byteSignals += (1 << 4);
}
}
if (Work)
else
{
byteSignals += (1 << 1);
lgInfo("HoldingRegisterLUT vuoto!");
}
if (!Auto)
{
byteSignals += (1 << 4);
}
// salvo!
B_input = byteSignals;
@@ -190,6 +195,31 @@ namespace IOB_WIN_NEXT
lgTrace("-------------------- Completato test lettura {baseAddr} --------------------");
}
/// <summary>
/// Testa la condition modbus da LUT + configurazione
/// </summary>
/// <param name="cKey"></param>
/// <returns></returns>
private bool testCondition(string cKey)
{
bool answ = false;
if (OptCheckConditions.ContainsKey(cKey))
{
int currStatus = 0;
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[OptCheckConditions[cKey].BaseAddr];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
// hard coded il 9° bit a zero
answ = ((currStatus & (1 << OptCheckConditions[cKey].BitNum)) == OptCheckConditions[cKey].ValOk);
lgTrace($"testCondition for {cKey} | BaseAddr: {OptCheckConditions[cKey].BaseAddr} | BitNum: {OptCheckConditions[cKey].BitNum} | ValOk: {OptCheckConditions[cKey].ValOk}");
}
else
{
lgTrace($"testCondition error: {cKey} not found");
}
return answ;
}
private void testRead()
{
foreach (var item in memSetR)
+24 -18
View File
@@ -55,7 +55,7 @@ namespace IOB_WIN_NEXT
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40003;
int statusReg = 40002;
// deve avere allarmi (è un allarme EStop)
if (hasAlarms())
{
@@ -79,7 +79,7 @@ namespace IOB_WIN_NEXT
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40003;
int statusReg = 40002;
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[statusReg];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
@@ -98,7 +98,7 @@ namespace IOB_WIN_NEXT
bool answ = false;
int currStatus = 0;
// hard coded
int statusReg = 40003;
int statusReg = 40002;
int[] listInt = new int[2];
listInt = HoldingRegisterLUT[statusReg];
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
@@ -137,26 +137,32 @@ namespace IOB_WIN_NEXT
{
byteSignals += (1 << 0);
}
// processo dagli stati + gravi...
if (!EStop)
if (HoldingRegisterLUT != null && HoldingRegisterLUT.Count > 0)
{
byteSignals += (1 << 7);
}
// processo dagli stati + gravi...
if (!EStop)
{
byteSignals += (1 << 7);
}
// processo dagli stati + gravi...
if (hasAlarms())
{
byteSignals += (1 << 3);
// processo dagli stati + gravi...
if (hasAlarms())
{
byteSignals += (1 << 3);
}
if (Work)
{
byteSignals += (1 << 1);
}
if (!Auto)
{
byteSignals += (1 << 4);
}
}
if (Work)
else
{
byteSignals += (1 << 1);
lgInfo("HoldingRegisterLUT vuoto!");
}
if (!Auto)
{
byteSignals += (1 << 4);
}
// salvo!
B_input = byteSignals;
+2 -1
View File
@@ -1176,7 +1176,7 @@ namespace IOB_WIN_NEXT
opcUaParams = JsonConvert.DeserializeObject<OpcUaParamConf>(jsonData);
lgDebug($"Decodifica aree OpcUaParamConf: trovati {opcUaParams.paramsEndThresh.Count} valori paramsEndThresh");
// sistemo se ci sono dati memMap...
memMap = new plcMemMap();
memMap = new plcMemMapExt();
if (opcUaParams.mMapWrite != null)
{
memMap.mMapWrite = opcUaParams.mMapWrite;
@@ -1186,6 +1186,7 @@ namespace IOB_WIN_NEXT
memMap.mMapRead = opcUaParams.mMapRead;
}
setupMemMap();
setupOptMemPar();
}
catch (Exception exc)
{
+1 -1
View File
@@ -79,7 +79,7 @@ namespace IOB_WIN_NEXT
/// <param name="adpConf"></param>
public IobSiemens(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
memMap = new plcMemMap();
memMap = new plcMemMapExt();
writePre = true;
if (IOBConf.optPar.ContainsKey("WRITE_PRE"))
{