Update serializzazione/deserializzazione codice
This commit is contained in:
@@ -127,8 +127,6 @@
|
||||
"rovrd": "PATH RAPID OVERRIDE"
|
||||
},
|
||||
"subscribedItems": [
|
||||
"ns=4;s=Dati_Mes",
|
||||
"ns=4;s=Calibratrice_L1",
|
||||
"ns=4;s=Calibratrice_L2"
|
||||
"ns=4;s=Dati_Mes"
|
||||
]
|
||||
}
|
||||
@@ -252,7 +252,7 @@ namespace IOB_WIN_NEXT
|
||||
/// <param name="forceSend"></param>
|
||||
private void checkAndSend(Opc.Ua.Client.MonitoredItem MonIt, string NotifyValue, bool forceSend)
|
||||
{
|
||||
#if true
|
||||
#if false
|
||||
// provo a decodificare...
|
||||
var attrlist = Attributes.GetIdentifiers();
|
||||
List<string> listName = new List<string>();
|
||||
@@ -310,6 +310,34 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected bool encodeReadData { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice una versione serializzata delle variabili complesse in formato string
|
||||
/// </summary>
|
||||
/// <param name="dataType"></param>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual string bSerString(string dataType, object rawData)
|
||||
{
|
||||
string answ = "";
|
||||
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Restitusice una versione serializzata delle variabili complesse in formato object (generico)
|
||||
/// </summary>
|
||||
/// <param name="dataType"></param>
|
||||
/// <param name="rawData"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual object bSerObj(string dataType, object rawData)
|
||||
{
|
||||
object answ = null;
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vera connessione ad OpcUa
|
||||
/// </summary>
|
||||
@@ -430,9 +458,18 @@ namespace IOB_WIN_NEXT
|
||||
{
|
||||
dataItemMem.Add(uuid, newItem);
|
||||
lgDebug($"Item subscribed: {uuid}");
|
||||
// restituisce i 115 byte da deserializzare... qui HACK!
|
||||
var rawVal = UA_ref.ReadNodeRaw(item.StartNodeId);
|
||||
string currVal = UA_ref.ReadNode(item.StartNodeId);
|
||||
// verifico se ho i dati complessi by design
|
||||
string currVal = "";
|
||||
if (encodeReadData)
|
||||
{
|
||||
// restituisce i 115 byte da deserializzare... qui HACK!
|
||||
var rawVal = UA_ref.ReadNodeRaw(item.StartNodeId);
|
||||
currVal = bSerString("OPC", rawVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
currVal = UA_ref.ReadNode(item.StartNodeId);
|
||||
}
|
||||
checkAndSend(item, currVal, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,22 +21,24 @@ namespace IOB_WIN_NEXT
|
||||
public MesItemStatus(byte[] rawData)
|
||||
{
|
||||
Stato = BitConverter.ToUInt16(rawData, 0);
|
||||
Velocita= BitConverter.ToUInt16(rawData, 2);
|
||||
Velocita = BitConverter.ToUInt16(rawData, 2);
|
||||
Termico = !rawData.Skip(4).Take(1).Equals(0);
|
||||
MagnetoTermico= !rawData.Skip(5).Take(1).Equals(0);
|
||||
AvariaInverter= !rawData.Skip(6).Take(1).Equals(0);
|
||||
MagnetoTermico = !rawData.Skip(5).Take(1).Equals(0);
|
||||
AvariaInverter = !rawData.Skip(6).Take(1).Equals(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converte un singolo item in un array di byte per scrittura su PLC S7
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte[] convertToByte()
|
||||
public byte[] serialize()
|
||||
{
|
||||
byte[] answ = new byte[7];
|
||||
//Buffer.BlockCopy(UInt16.ToByteArray(Stato), 0, answ, 0, 2);
|
||||
//Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Speed), 0, answ, 4, 4);
|
||||
//Buffer.BlockCopy(S7.Net.Types.Double.ToByteArray(Load), 0, answ, 8, 4);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(Stato), 0, answ, 0, 2);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(Velocita), 0, answ, 2, 2);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(Termico), 0, answ, 4, 1);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(MagnetoTermico), 0, answ, 5, 1);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(AvariaInverter), 0, answ, 6, 1);
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -105,8 +107,28 @@ namespace IOB_WIN_NEXT
|
||||
/// <param name="rawData">Flusso di dati RAW da tradurre...</param>
|
||||
public DatiMesIcoel(byte[] rawData)
|
||||
{
|
||||
Calibratrice_L1 = new MesItemStatus(rawData.Skip(0).Take(7).ToArray());
|
||||
Calibratrice_L2 = new MesItemStatus(rawData.Skip(7).Take(7).ToArray());
|
||||
// solo se i dati sono esattamente 115...
|
||||
|
||||
if (rawData.Length >= 115)
|
||||
{
|
||||
Calibratrice_L1 = new MesItemStatus(rawData.Skip(0).Take(7).ToArray());
|
||||
Calibratrice_L2 = new MesItemStatus(rawData.Skip(7).Take(7).ToArray());
|
||||
Dewatering_L1 = new MesItemStatus(rawData.Skip(14).Take(7).ToArray());
|
||||
Dewatering_L2 = new MesItemStatus(rawData.Skip(21).Take(7).ToArray());
|
||||
Precalibro_L1 = new MesItemStatus(rawData.Skip(28).Take(7).ToArray());
|
||||
Precalibro_L2 = new MesItemStatus(rawData.Skip(35).Take(7).ToArray());
|
||||
Taglierina_L1 = new MesItemStatus(rawData.Skip(42).Take(7).ToArray());
|
||||
Taglierina_L2 = new MesItemStatus(rawData.Skip(49).Take(7).ToArray());
|
||||
NastroTaglierina_L1 = new MesItemStatus(rawData.Skip(56).Take(7).ToArray());
|
||||
NastroTaglierina_L2 = new MesItemStatus(rawData.Skip(63).Take(7).ToArray());
|
||||
Elevatore_L1 = new MesItemStatus(rawData.Skip(70).Take(7).ToArray());
|
||||
Elevatore_L2 = new MesItemStatus(rawData.Skip(77).Take(7).ToArray());
|
||||
ImmergitoreBins_L1 = new MesItemStatus(rawData.Skip(84).Take(7).ToArray());
|
||||
ImmergitoreBins_L2 = new MesItemStatus(rawData.Skip(91).Take(7).ToArray());
|
||||
ImmergitoreCasse_L1 = new MesItemStatus(rawData.Skip(98).Take(7).ToArray());
|
||||
ImmergitoreCasse_L2 = new MesItemStatus(rawData.Skip(105).Take(7).ToArray());
|
||||
Varie = new PlantStatus(rawData.Skip(112).Take(3).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +260,7 @@ namespace IOB_WIN_NEXT
|
||||
|
||||
List<WriteValue> nodes2Write = new List<WriteValue>();
|
||||
nodes2Write.Add(commWriteVal);
|
||||
|
||||
|
||||
UA_ref.WriteNodes(nodes2Write);
|
||||
}
|
||||
catch (Exception exc)
|
||||
|
||||
Reference in New Issue
Block a user