107 lines
4.0 KiB
C#
107 lines
4.0 KiB
C#
using MapoSDK;
|
|
using Newtonsoft.Json;
|
|
using Opc.Ua;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IOB_WIN_NEXT
|
|
{
|
|
public class IobOpcUaEwonBLM : IobOpcUaEwon
|
|
{
|
|
#region Protected Fields
|
|
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Estende l'init della classe base, impiegando il pacchetto Nuget OPC-UA foundation con la gestione specifica per EWON (es Monti, Tenditalia)
|
|
/// https://github.com/OPCFoundation/UA-.NETStandard
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="IOBConf"></param>
|
|
public IobOpcUaEwonBLM(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
lgInfo("Init Ewon versione BLM (Mecart)");
|
|
|
|
// inizializzo classe base...
|
|
if (!string.IsNullOrEmpty(getOptPar("CHANGE_ODL_MODE")))
|
|
{
|
|
CHANGE_ODL_MODE = getOptPar("CHANGE_ODL_MODE");
|
|
}
|
|
sendKeyRichiesta = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua vera scrittura parametri
|
|
/// </summary>
|
|
/// <param name="updatedPar"></param>
|
|
protected override void plcWriteParams(ref List<objItem> updatedPar)
|
|
{
|
|
base.plcWriteParams(ref updatedPar);
|
|
|
|
// se DEVO gestire setup Mecolpress...
|
|
if (opcUaParams.SetupConf.SetupMode == IOB_UT_NEXT.MachineSetupMode.MECOLPRESS)
|
|
{
|
|
List<WriteValue> nodes2Write = new List<WriteValue>();
|
|
// faccio un check tra i valori in memoria che devono corrispondere e se NON corrispondono --> metto valore in scrittura...
|
|
int numDiff = 0;
|
|
foreach (var item in opcUaParams.SetupConf.checkParList)
|
|
{
|
|
// cerco la memoria corrispondente...
|
|
var memorieMes = dataItemMem.Where(x => x.Key.Contains(item.Key)).ToList();
|
|
var memorieMac = dataItemMem.Where(x => x.Key.Contains(item.Value)).ToList();
|
|
// se ho trovato qualcosa verifico se corrispondono...
|
|
if (memorieMes.Count > 0 && memorieMes.Count > 0)
|
|
{
|
|
// controllo primo record con primo record
|
|
if (memorieMes.FirstOrDefault().Value.value != memorieMac.FirstOrDefault().Value.value)
|
|
{
|
|
numDiff++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// ciclo le condizioni di uscita
|
|
foreach (var item in opcUaParams.SetupConf.writeParAction)
|
|
{
|
|
WriteValue commWriteVal = new WriteValue();
|
|
commWriteVal.NodeId = new NodeId(item.TargetParam);
|
|
commWriteVal.AttributeId = Attributes.Value;
|
|
commWriteVal.Value = new DataValue();
|
|
// se ho differenze --> scrivo richiesta attrezzaggio...
|
|
if (numDiff > 0)
|
|
{
|
|
commWriteVal.Value.Value = item.TargetValNotEqual;
|
|
}
|
|
else
|
|
{
|
|
commWriteVal.Value.Value = item.TargetValEqual;
|
|
}
|
|
|
|
// accodo x scrittura
|
|
nodes2Write.Add(commWriteVal);
|
|
lgInfo($"richiesta scrittura valore | nodeId: {commWriteVal.NodeId } | targetPar: {item.TargetParam} | val {commWriteVal.Value.Value}");
|
|
}
|
|
|
|
// x ora NON eseguo
|
|
if (opcUaParams.SetupConf.EnableAdvSetup)
|
|
{
|
|
// ora scrivo!
|
|
if (nodes2Write.Count > 0)
|
|
{
|
|
UA_ref.WriteNodes(nodes2Write);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
}
|
|
} |