using MTC; using OPC_UA_REDIS; namespace SCMA.AdapterCom { public class GatewaySOURS : Gateway { /// /// adapter globale MTC /// /// public AdapterRed mAdapter = new AdapterRed(); #region gestione globale oggetto /// /// Gateway SOUR /// public GatewaySOURS() { protocollo = gwProtocol.SOURS; } /// /// Wrapper metodo Begin /// public override void beginDataCollect() { mAdapter.Begin(); } /// /// Wrapper metodo SendChanged /// public override void sendChanged() { mAdapter.SendChanged(); } /// /// Wrapper metodo imposta tutto a UNAVAILABLE /// public override void setAllUnavailable() { mAdapter.Unavailable(); } /// /// Wrapper metodo START /// 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(); } /// /// Wrapper metodo STOP /// public override void stop() { mAdapter.Stop(); } #endregion #region gestione controllo stato catena applicativi e messaggi da piattaforma /// /// 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 /// /// /// 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... /// /// public override void addItemNode(string key, object value) { if (!itemNodes.ContainsKey(key)) { base.addItemNode(key, value); // aggiungo ad adapter mAdapter.AddDataItem((DataItemRed)value); } } /// /// Effettua chiamata VERA su adapter MTConnect... /// /// 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); } } /// /// Wrapper metodo rimozione di TUTTI gli ITEMS /// public override void removeAllItemNodes() { foreach (var item in itemNodes) { // rimuovo da SCMA mAdapter.RemoveDataItem((DataItemRed)item.Value.cObject); } base.removeAllItemNodes(); } /// /// Wrapper metodo rimozione ITEMS /// /// 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 } /// /// wrapper aggiunta condizione /// /// /// 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 /// /// Speciofica implementazione x formattazione ALLARMI /// /// 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, "", ""); //} } /// /// Specifica implementazione x formattazione ALLARMI /// /// /// Generico nodo di tipo condition 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, "", ""); } /// /// Wrapper setup obj allarmi /// 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); } /// /// Wrapper inizializzazione allarmi /// public override void initAlarms() { //// trasformo i nodi in elenchi conditions e li aggiungo... //foreach (var item in conditionNodes) //{ // ((ConditionRed)item.Value.cObject).Normal(); //} } /// /// inizializazione allarme a normal /// /// public override void initAlarm(itemNode alarmNode) { //ConditionRed mAlarm = (ConditionRed)alarmNode.cObject; //mAlarm.Normal(); } #endregion } }