308 lines
7.9 KiB
C#
308 lines
7.9 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using System.Threading.Tasks;
|
|
//using MTC;
|
|
using MTC;
|
|
using MTConnect;
|
|
|
|
namespace SCMA.AdapterCom
|
|
{
|
|
public class GatewayMTC : Gateway
|
|
{
|
|
/// <summary>
|
|
/// adapter globale MTC
|
|
/// </summary>
|
|
/// <summary>
|
|
public Adapter mAdapter = new Adapter();
|
|
|
|
#region gestione globale oggetto
|
|
|
|
/// <summary>
|
|
/// wrapper init
|
|
/// </summary>
|
|
public GatewayMTC()
|
|
{
|
|
protocollo = gwProtocol.MTC;
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo Begin
|
|
/// </summary>
|
|
public override void beginDataCollect()
|
|
{
|
|
mAdapter.Begin();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo SendChanged
|
|
/// </summary>
|
|
public override void sendChanged()
|
|
{
|
|
mAdapter.SendChanged();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo imposta tutto a UNAVAILABLE
|
|
/// </summary>
|
|
public override void setAllUnavailable()
|
|
{
|
|
mAdapter.Unavailable();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo START
|
|
/// </summary>
|
|
public override void start()
|
|
{
|
|
mAdapter.Port = port;
|
|
mAdapter.Start();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo STOP
|
|
/// </summary>
|
|
public override void stop()
|
|
{
|
|
mAdapter.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region gestione nodi (dataItems, conditions)
|
|
|
|
public override void addItemNodeByType(string key, itemType tipo)
|
|
{
|
|
if (!itemNodes.ContainsKey(key))
|
|
{
|
|
// in base al TIPO genero l'oggetto corretto...
|
|
DataItem currObj;
|
|
switch (tipo)
|
|
{
|
|
case itemType.Condition:
|
|
currObj = new Condition(key);
|
|
break;
|
|
case itemType.Event:
|
|
currObj = new Event(key);
|
|
break;
|
|
case itemType.Message:
|
|
currObj = new Message(key);
|
|
break;
|
|
case itemType.Sample:
|
|
currObj = new Sample(key);
|
|
break;
|
|
default:
|
|
currObj = new DataItem(key);
|
|
break;
|
|
}
|
|
mAdapter.AddDataItem(currObj);
|
|
base.addItemNode(key, currObj);
|
|
}
|
|
}
|
|
/// Effettua chiamata VERA su adapter MTConnect...
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
public override void addItemNode(string key, object value)
|
|
{
|
|
if (!itemNodes.ContainsKey(key))
|
|
{
|
|
base.addItemNode(key, value);
|
|
// aggiungo ad adapter
|
|
mAdapter.AddDataItem((DataItem)value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Effettua chiamata VERA su adapter MTConnect...
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
public override void addItemNode(object value)
|
|
{
|
|
DataItem currObj = (DataItem)value;
|
|
string key = value.ToString().Replace("|", "");
|
|
try
|
|
{
|
|
key = key.Replace(currObj.Value.ToString(), "");
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
if (!itemNodes.ContainsKey(key))
|
|
{
|
|
base.addItemNode(key, value);
|
|
// aggiungo ad adapter
|
|
mAdapter.AddDataItem((DataItem)value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo rimozione di TUTTI gli ITEMS
|
|
/// </summary>
|
|
public override void removeAllItemNodes()
|
|
{
|
|
foreach (var item in itemNodes)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((DataItem)item.Value);
|
|
}
|
|
base.removeAllItemNodes();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo rimozione ITEMS
|
|
/// </summary>
|
|
/// <param name="anItem"></param>
|
|
public override void removeItemNode(string key)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((DataItem)itemNodes[key]);
|
|
// rimuovo da vett interno
|
|
base.removeItemNode(key);
|
|
}
|
|
public override void updateItemNodeValue(string key, object value)
|
|
{
|
|
((DataItem)getItemNode(key)).Value = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// wrapper aggiunta condizione
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
public override void addConditionNode(string key, object value)
|
|
{
|
|
conditionNodes.Add(key, value);
|
|
// aggiungo ad adapter
|
|
mAdapter.AddDataItem((Condition)value);
|
|
}
|
|
public override void removeAllConditionNodes()
|
|
{
|
|
foreach (var item in conditionNodes)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((Condition)item.Value);
|
|
}
|
|
base.removeAllConditionNodes();
|
|
}
|
|
public override void removeConditionNode(string key)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((Condition)conditionNodes[key]);
|
|
// rimuovo da vett interno
|
|
base.removeConditionNode(key);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region gestione allarmi
|
|
|
|
/// <summary>
|
|
/// Speciofica implementazione x formattazione ALLARMI
|
|
/// </summary>
|
|
/// <param name="currAllarm"></param>
|
|
public override void addAlarm(allarme currAllarm)
|
|
{
|
|
// in base al tipo di allarme decodifico condizione...
|
|
Condition.Level livello = Condition.Level.NORMAL;
|
|
switch (currAllarm.livello)
|
|
{
|
|
case "WARNING":
|
|
livello = Condition.Level.WARNING;
|
|
break;
|
|
case "FAULT":
|
|
default:
|
|
livello = Condition.Level.FAULT;
|
|
break;
|
|
}
|
|
if (conditionNodes.ContainsKey(currAllarm.gruppo))
|
|
{
|
|
Condition mAlarm = (Condition)conditionNodes[currAllarm.gruppo];
|
|
mAlarm.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
}
|
|
#if false
|
|
// in base al gruppo decido dove assegnare come CONDITION...
|
|
switch (currAllarm.gruppo)
|
|
{
|
|
case "PLC":
|
|
mAlarmPLC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
case "CNC":
|
|
default:
|
|
mAlarmCNC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Speciofica implementazione x formattazione ALLARMI
|
|
/// </summary>
|
|
/// <param name="currAllarm"></param>
|
|
/// <param name="alarmNode">Generico nodo di tipo condition</param>
|
|
public override void addAlarm(object alarmNode, allarme currAllarm)
|
|
{
|
|
// in base al tipo di allarme decodifico condizione...
|
|
Condition.Level livello = Condition.Level.NORMAL;
|
|
switch (currAllarm.livello)
|
|
{
|
|
case "WARNING":
|
|
livello = Condition.Level.WARNING;
|
|
break;
|
|
case "FAULT":
|
|
default:
|
|
livello = Condition.Level.FAULT;
|
|
break;
|
|
}
|
|
Condition mAlarm = (Condition)alarmNode;
|
|
mAlarm.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
|
|
#if false
|
|
// in base al gruppo decido dove assegnare come CONDITION...
|
|
switch (currAllarm.gruppo)
|
|
{
|
|
case "PLC":
|
|
mAlarmPLC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
case "CNC":
|
|
default:
|
|
mAlarmCNC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Wrapper setup obj allarmi
|
|
/// </summary>
|
|
public override void addAlarmNodes()
|
|
{
|
|
// registro
|
|
Condition newCondNode;
|
|
newCondNode = new Condition("CNC");
|
|
addConditionNode("CNC", newCondNode);
|
|
newCondNode = new Condition("PLC");
|
|
addConditionNode("PLC", newCondNode);
|
|
}
|
|
/// <summary>
|
|
/// Wrapper inizializzazione allarmi
|
|
/// </summary>
|
|
public override void initAlarms()
|
|
{
|
|
// trasformo i nodi in elenchi conditions e li aggiungo...
|
|
foreach (var item in conditionNodes)
|
|
{
|
|
((Condition)item.Value).Normal();
|
|
}
|
|
#if false
|
|
//mAlarmSystem.Normal();
|
|
mAlarmCNC.Normal();
|
|
mAlarmPLC.Normal();
|
|
//mAlarmGeneral.Normal();
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// inizializazione allarme a normal
|
|
/// </summary>
|
|
/// <param name="alarmNode"></param>
|
|
public override void initAlarm(object alarmNode)
|
|
{
|
|
Condition mAlarm = (Condition)alarmNode;
|
|
mAlarm.Normal();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|