212 lines
7.8 KiB
C#
212 lines
7.8 KiB
C#
using MapoSDK;
|
|
using Opc.Ua;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IOB_WIN_NEXT
|
|
{
|
|
public class IobOpcUaMBHCimolai : IobOpcUaMBH
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Estende l'init della classe base, impiegando il pacchetto Nuget OPC-UA foundation con la
|
|
/// gestione specifica per MBH (es Cimolai, Baglietto) https://github.com/OPCFoundation/UA-.NETStandard
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="IOBConf"></param>
|
|
public IobOpcUaMBHCimolai(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
lgInfo("Init OpcUa MBH versione Cimolai (Baglietto)");
|
|
|
|
// inizializzo classe base...
|
|
if (!string.IsNullOrEmpty(getOptPar("CHANGE_ODL_MODE")))
|
|
{
|
|
CHANGE_ODL_MODE = getOptPar("CHANGE_ODL_MODE");
|
|
}
|
|
sendKeyRichiesta = true;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Processo i task richiesti e li elimino dalla coda 1:1
|
|
/// </summary>
|
|
/// <param name="task2exe"></param>
|
|
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
|
|
{
|
|
// uso metodo base x salvare esito scrittura
|
|
var writeResult = base.executeTasks(task2exe);
|
|
|
|
// aggiungo comportamento custom: se ho impostato nome ricetta (programma) --> imposto
|
|
// richiesta caricamento se ho richiesto reset o fine lavoro --> imposto azzeramento
|
|
// esco restituendo risutlato scrittura iniziali
|
|
if (task2exe != null)
|
|
{
|
|
// controllo se memMap != null...
|
|
if (memMap != null)
|
|
{
|
|
bool taskOk = false;
|
|
string taskVal = "";
|
|
// cerco task specifici x OMP
|
|
foreach (var item in task2exe)
|
|
{
|
|
taskOk = false;
|
|
taskVal = "";
|
|
// converto richiesta in enum...
|
|
taskType tName = taskType.nihil;
|
|
Enum.TryParse(item.Key, out tName);
|
|
// controllo sulla KEY...
|
|
switch (tName)
|
|
{
|
|
case taskType.setProg:
|
|
// recupero dati da memMap...
|
|
if (memMap != null && memMap.mMapWrite != null)
|
|
{
|
|
if (memMap.mMapWrite.ContainsKey(item.Key))
|
|
{
|
|
dataConf currMem = memMap.mMapWrite[item.Key];
|
|
string addr = currMem.memAddr;
|
|
taskVal = $"SET task: {item.Key} --> {item.Value} | mem: {currMem.memAddr} - {currMem.size} byte";
|
|
// salvo il nuovo valore nella memoria... così prox invio lo trasmetterà
|
|
memMap.mMapWrite[item.Key].value = item.Value;
|
|
}
|
|
else
|
|
{
|
|
taskVal = $"NO DATA MEM, SET task: {item.Key} --> {item.Value}";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
taskVal = $"NO MemMap found, SET task: {item.Key} --> {item.Value}";
|
|
}
|
|
// salvo in currProd..
|
|
saveProdData(new KeyValuePair<string, string>(item.Key, item.Value));
|
|
|
|
break;
|
|
|
|
case taskType.startSetup:
|
|
setFineLotto();
|
|
break;
|
|
|
|
case taskType.stopSetup:
|
|
setInizioProd();
|
|
break;
|
|
|
|
default:
|
|
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
|
|
lgInfo($"Chiamata senza processing: taskOk: {taskOk} | taskVal: {taskVal}");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError($"Attenzione! memMap è nullo, non posso eseguire task2exe!");
|
|
}
|
|
}
|
|
|
|
return writeResult;
|
|
}
|
|
|
|
public override bool resetcontapezziPLC()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
List<WriteValue> nodes2Write = new List<WriteValue>();
|
|
foreach (var item in opcUaParams.actResetCounter)
|
|
{
|
|
WriteValue commWriteVal = new WriteValue();
|
|
commWriteVal.NodeId = new NodeId(item.Key);
|
|
commWriteVal.AttributeId = Attributes.Value;
|
|
commWriteVal.Value = new DataValue();
|
|
commWriteVal.Value.Value = item.Value;
|
|
|
|
nodes2Write.Add(commWriteVal);
|
|
}
|
|
// vera scrittura
|
|
UA_ref.WriteNodes(nodes2Write);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Azioni specifiche x indicare fine lotto di produzione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool setFineLotto()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
List<WriteValue> nodes2Write = new List<WriteValue>();
|
|
foreach (var item in opcUaParams.actStopProd)
|
|
{
|
|
WriteValue commWriteVal = new WriteValue();
|
|
commWriteVal.NodeId = new NodeId(item.Key);
|
|
commWriteVal.AttributeId = Attributes.Value;
|
|
commWriteVal.Value = new DataValue();
|
|
commWriteVal.Value.Value = item.Value;
|
|
|
|
nodes2Write.Add(commWriteVal);
|
|
}
|
|
// vera scrittura
|
|
UA_ref.WriteNodes(nodes2Write);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Azioni specifiche x iniziare produzione (impostazione ricetta)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool setInizioProd()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
List<WriteValue> nodes2Write = new List<WriteValue>();
|
|
foreach (var item in opcUaParams.actSetRecipe)
|
|
{
|
|
WriteValue commWriteVal = new WriteValue();
|
|
commWriteVal.NodeId = new NodeId(item.Key);
|
|
commWriteVal.AttributeId = Attributes.Value;
|
|
commWriteVal.Value = new DataValue();
|
|
commWriteVal.Value.Value = item.Value;
|
|
|
|
nodes2Write.Add(commWriteVal);
|
|
}
|
|
// vera scrittura
|
|
UA_ref.WriteNodes(nodes2Write);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
|
|
/// <summary>
|
|
/// Effettua vero processing contapezzi
|
|
/// </summary>
|
|
public override void processContapezzi()
|
|
{
|
|
// non fa nulal (non ha contapezzi)
|
|
}
|
|
}
|
|
} |