Update x gestione lettura string

This commit is contained in:
Samuele E. Locatelli
2022-07-29 11:08:38 +02:00
parent 9f8944876d
commit eae1d51337
5 changed files with 41 additions and 17 deletions
+1
View File
@@ -125,6 +125,7 @@
<Compile Include="Eurom63.cs" />
<Compile Include="IobWinStatus.cs" />
<Compile Include="TCMan.cs" />
<Compile Include="TimeUtils.cs" />
<Compile Include="ToMapo.cs" />
<Compile Include="baseUtils.cs" />
<Compile Include="BinaryFormatter.cs" />
+5
View File
@@ -812,6 +812,11 @@ namespace IOB_UT_NEXT
/// </summary>
public int Period { get; set; } = 60;
/// <summary>
/// UM parametro, impiegato anche x conversione (es epoch --> datetime)
/// </summary>
public string UM { get; set; } = "";
#endregion Public Properties
}
}
+2 -2
View File
@@ -132,7 +132,7 @@
"tipoMem": "INT",
"index": 1102,
"size": 2,
"unit": "#",
"unit": "EPOCH",
"func": "POINT",
"period": 90,
"factor": 1
@@ -144,7 +144,7 @@
"tipoMem": "INT",
"index": 1104,
"size": 2,
"unit": "#",
"unit": "EPOCH",
"func": "POINT",
"period": 90,
"factor": 1
+2 -1
View File
@@ -3155,7 +3155,7 @@ namespace IOB_WIN_NEXT
}
else
{
lgError($"Errore in invio richiesta registrazione allarme: URL: {lastUrl}{Environment.NewLine}Payload:{Environment.NewLine}{rawData}");
lgError($"Errore in invio richiesta registrazione allarme | resp: {resp} | URL: {lastUrl}{Environment.NewLine}Payload:{Environment.NewLine}{rawData}");
}
}
return fatto;
@@ -4902,6 +4902,7 @@ namespace IOB_WIN_NEXT
{
Funzione = funz,
Period = periodo,
UM = item.Value.unit,
DTStart = DateTime.Now.AddHours(-1),
dataArray = new List<double>()
};
+31 -14
View File
@@ -830,14 +830,10 @@ namespace IOB_WIN_NEXT
fatto = writeInputReg(currMem.index, CurrVal);
break;
//case plcDataType.String:
// // se ho writePre --> "allungo" di 2 la dimensione della stringa x MemBlock...
// if (writePre)
// {
// MemBlock = new byte[byteSize + 2];
// }
// saveStringOnMemBlock(ref MemBlock, 0, currMem.size, currMem.value);
// break;
case plcDataType.String:
CurrVal = ModbusClient.ConvertStringToRegisters(currMem.value);
fatto = writeInputReg(currMem.index, CurrVal);
break;
default:
break;
@@ -1304,6 +1300,7 @@ namespace IOB_WIN_NEXT
// procedo x ogni valore configurato...
foreach (var item in memItemList)
{
listInt = new int[item.Value.size];
// attesa 50 ms prima di procedere x evitare burst dati
if (!useLUT)
{
@@ -1368,7 +1365,18 @@ namespace IOB_WIN_NEXT
{
try
{
listInt = HoldingRegisterLUT[lutAddress];
if (listInt.Length == 2)
{
listInt = HoldingRegisterLUT[lutAddress];
}
else
{
// faccio ciclo x copiare 2 alla volta...
for (int i = 0; i < listInt.Length; i += 2)
{
Array.Copy(HoldingRegisterLUT[lutAddress + i], 0, listInt, i, 2);
}
}
}
catch (Exception exc)
{
@@ -1385,7 +1393,6 @@ namespace IOB_WIN_NEXT
{
// valore string...
valString = ModbusClient.ConvertRegistersToString(listInt, 0, item.Value.size);
}
else
{
@@ -1407,10 +1414,20 @@ namespace IOB_WIN_NEXT
dataOk = (valore > (item.Value.minVal + deltaVal) && valore < (item.Value.maxVal - deltaVal));
if (dataOk || disDynDataRangeCheck)
{
// moltiplico x fattore conversione...
valoreScal = valore * item.Value.factor;
saveValue(ref outVal, valoreScal, item.Key);
lgDebug($"getDataDictionary: valore ricevuto | {item.Key} | val: {valore} | valoreScal: {valoreScal}");
// verifica valori EPOCH x convertirli in datetime...
if (item.Value.unit == "EPOCH")
{
valString = TimeUtils.epochConvert(valore).ToString("yyyy-MM-dd HH:mm:ss");
saveValueString(ref outVal, valString, item.Key);
lgDebug($"getDataDictionary: valore EPOCH ricevuto | {item.Key} | val: {valore} | valString: {valString}");
}
else
{
// moltiplico x fattore conversione...
valoreScal = valore * item.Value.factor;
saveValue(ref outVal, valoreScal, item.Key);
lgDebug($"getDataDictionary: valore ricevuto | {item.Key} | val: {valore} | valoreScal: {valoreScal}");
}
}
else
{