336 lines
9.3 KiB
C#
336 lines
9.3 KiB
C#
using MTC;
|
|
using OPC_UA_REDIS;
|
|
|
|
namespace SCMA.AdapterCom
|
|
{
|
|
public class GatewaySOURS : Gateway
|
|
{
|
|
|
|
/// <summary>
|
|
/// adapter globale MTC
|
|
/// </summary>
|
|
/// <summary>
|
|
public AdapterRed mAdapter = new AdapterRed();
|
|
|
|
#region gestione globale oggetto
|
|
|
|
/// <summary>
|
|
/// Gateway SOUR
|
|
/// </summary>
|
|
public GatewaySOURS()
|
|
{
|
|
protocollo = gwProtocol.SOURS;
|
|
}
|
|
/// <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()
|
|
{
|
|
// passo le tabelle di remap/replace
|
|
mAdapter.ServerPort = 6379; // !!! port hard coded
|
|
mAdapter.ServerAddr = "127.0.0.1"; // !!! IP hard coded
|
|
mAdapter.nameRepRoles = nameRepRoles;
|
|
mAdapter.DataModel = DataModel;
|
|
// aggiunge il set di allarmi (che è NATIVAMENTE già su 3 lingue... )
|
|
mAdapter.elencoAllarmi = elencoAllarmi;
|
|
mAdapter.itemNodes = itemNodes;
|
|
mAdapter.conditionNodes = conditionNodes;
|
|
|
|
// avvio oggetto
|
|
mAdapter.Start();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo STOP
|
|
/// </summary>
|
|
public override void stop()
|
|
{
|
|
mAdapter.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region gestione controllo stato catena applicativi e messaggi da piattaforma
|
|
|
|
/// <summary>
|
|
/// Verifica lo stato di un servizio indicato per via numerica:
|
|
/// 1: verifica che servizio REDIS sia OK
|
|
/// 2: verifica OPC-UA-SERVER sia ALIVE
|
|
/// 3: verifica gateway sia OK (attivo)
|
|
/// 4: verifica gateway abbia accesso internet
|
|
/// </summary>
|
|
/// <param name="numServ"></param>
|
|
/// <returns></returns>
|
|
public override bool checkStatus(int numServ)
|
|
{
|
|
bool answ = false;
|
|
switch (numServ)
|
|
{
|
|
case 1:
|
|
answ = mAdapter.redServAlive;
|
|
break;
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
break;
|
|
case 4:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#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...
|
|
DataItemRed currObj;
|
|
switch (tipo)
|
|
{
|
|
case itemType.Condition:
|
|
currObj = new DataItemRed(key);
|
|
//currObj = new ConditionRed(key);
|
|
break;
|
|
#if false
|
|
case itemType.Event:
|
|
currObj = new Event(key);
|
|
break;
|
|
case itemType.Message:
|
|
currObj = new Message(key);
|
|
break;
|
|
case itemType.Sample:
|
|
currObj = new Sample(key);
|
|
break;
|
|
#endif
|
|
default:
|
|
currObj = new DataItemRed(key);
|
|
break;
|
|
}
|
|
mAdapter.AddDataItem(currObj);
|
|
if (tipo == itemType.Condition)
|
|
{
|
|
addConditionNode(key, currObj);
|
|
addItemNode(key, currObj);
|
|
}
|
|
else
|
|
{
|
|
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((DataItemRed)value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Effettua chiamata VERA su adapter MTConnect...
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
public override void addItemNode(object value)
|
|
{
|
|
DataItemRed currObj = (DataItemRed)value;
|
|
string key = currObj.Name;
|
|
if (!itemNodes.ContainsKey(key))
|
|
{
|
|
base.addItemNode(key, value);
|
|
// aggiungo ad adapter
|
|
mAdapter.AddDataItem((DataItemRed)value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo rimozione di TUTTI gli ITEMS
|
|
/// </summary>
|
|
public override void removeAllItemNodes()
|
|
{
|
|
foreach (var item in itemNodes)
|
|
{
|
|
// rimuovo da SCMA
|
|
mAdapter.RemoveDataItem((DataItemRed)item.Value.cObject);
|
|
}
|
|
base.removeAllItemNodes();
|
|
}
|
|
/// <summary>
|
|
/// Wrapper metodo rimozione ITEMS
|
|
/// </summary>
|
|
/// <param name="anItem"></param>
|
|
public override void removeItemNode(string key)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((DataItemRed)itemNodes[key].cObject);
|
|
// rimuovo da vett interno
|
|
base.removeItemNode(key);
|
|
}
|
|
public override void updateItemNodeValue(string key, object value)
|
|
{
|
|
((DataItemRed)getItemNode(key)).Value = value;
|
|
}
|
|
public override void updateItemNodeCodeValue(string key, string code, object value)
|
|
{
|
|
#if false
|
|
((Message)getItemNode(key)).Code = code;
|
|
((Message)getItemNode(key)).Value = value;
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// wrapper aggiunta condizione
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
public override void addConditionNode(string key, object value)
|
|
{
|
|
if (!conditionNodes.ContainsKey(key))
|
|
{
|
|
base.addConditionNode(key, value);
|
|
// aggiungo ad adapter
|
|
mAdapter.AddDataItem((DataItemRed)value);
|
|
//mAdapter.AddDataItem((ConditionRed)value);
|
|
}
|
|
// aggiungo itemnode (se non c'è)
|
|
addItemNode(key, value);
|
|
}
|
|
public override void removeAllConditionNodes()
|
|
{
|
|
foreach (var item in conditionNodes)
|
|
{
|
|
// rimuovo da MTC
|
|
mAdapter.RemoveDataItem((DataItemRed)item.Value.cObject);
|
|
//mAdapter.RemoveDataItem((ConditionRed)item.Value.cObject);
|
|
}
|
|
base.removeAllConditionNodes();
|
|
}
|
|
public override void removeConditionNode(string key)
|
|
{
|
|
// rimuovo da oggetti specifici
|
|
mAdapter.RemoveDataItem((DataItemRed)conditionNodes[key].cObject);
|
|
//mAdapter.RemoveDataItem((ConditionRed)conditionNodes[key].cObject);
|
|
// 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...
|
|
//ConditionRed.Level livello = ConditionRed.Level.NORMAL;
|
|
//switch (currAllarm.livello)
|
|
//{
|
|
// case "WARNING":
|
|
// livello = ConditionRed.Level.WARNING;
|
|
// break;
|
|
// case "FAULT":
|
|
// default:
|
|
// livello = ConditionRed.Level.FAULT;
|
|
// break;
|
|
//}
|
|
//if (conditionNodes.ContainsKey(currAllarm.gruppo))
|
|
//{
|
|
// ConditionRed mAlarm = (ConditionRed)conditionNodes[currAllarm.gruppo].cObject;
|
|
// mAlarm.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// Specifica implementazione x formattazione ALLARMI
|
|
/// </summary>
|
|
/// <param name="currAllarm"></param>
|
|
/// <param name="alarmNode">Generico nodo di tipo condition</param>
|
|
public override void addAlarm(itemNode alarmNode, allarme currAllarm)
|
|
{
|
|
//// in base al tipo di allarme decodifico condizione...
|
|
//ConditionRed.Level livello = ConditionRed.Level.NORMAL;
|
|
//switch (currAllarm.livello)
|
|
//{
|
|
// case "WARNING":
|
|
// livello = ConditionRed.Level.WARNING;
|
|
// break;
|
|
// case "FAULT":
|
|
// default:
|
|
// livello = ConditionRed.Level.FAULT;
|
|
// break;
|
|
//}
|
|
//ConditionRed mAlarm = (ConditionRed)alarmNode.cObject;
|
|
//mAlarm.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
}
|
|
/// <summary>
|
|
/// Wrapper setup obj allarmi
|
|
/// </summary>
|
|
public override void addAlarmNodes()
|
|
{
|
|
// registro
|
|
DataItemRed newCondNode;
|
|
newCondNode = new DataItemRed(nCncConditions);
|
|
addConditionNode(nCncConditions, newCondNode);
|
|
newCondNode = new DataItemRed(nPlcConditions);
|
|
addConditionNode(nPlcConditions, newCondNode);
|
|
newCondNode = new DataItemRed(nHmiConditions);
|
|
addConditionNode(nHmiConditions, newCondNode);
|
|
}
|
|
/// <summary>
|
|
/// Wrapper inizializzazione allarmi
|
|
/// </summary>
|
|
public override void initAlarms()
|
|
{
|
|
//// trasformo i nodi in elenchi conditions e li aggiungo...
|
|
//foreach (var item in conditionNodes)
|
|
//{
|
|
// ((ConditionRed)item.Value.cObject).Normal();
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// inizializazione allarme a normal
|
|
/// </summary>
|
|
/// <param name="alarmNode"></param>
|
|
public override void initAlarm(itemNode alarmNode)
|
|
{
|
|
//ConditionRed mAlarm = (ConditionRed)alarmNode.cObject;
|
|
//mAlarm.Normal();
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|