From 9afcbf5690b1a3e5440ae8999dca7b0e8da63444 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 3 Apr 2020 17:40:39 +0200 Subject: [PATCH 1/3] Cambio namespaces x adapters CMS --- MTC_Adapter/SCMA/{ => AdapterPLC}/AdapterDemo.cs | 2 +- .../SCMA/{ => AdapterPLC}/AdapterGeneric.cs | 2 +- .../SCMA/{ => AdapterPLC/CMS}/AdapterFanuc.cs | 2 +- .../SCMA/{ => AdapterPLC/CMS}/AdapterOsai.cs | 2 +- .../SCMA/{ => AdapterPLC/CMS}/AdapterSiemens.cs | 2 +- .../SCMA/AdapterPLC/SCM/{ESA.cs => EsaKvara.cs} | 4 ++-- MTC_Adapter/SCMA/MainForm.cs | 14 +++++++------- MTC_Adapter/SCMA/SCMA.csproj | 16 +++++++--------- 8 files changed, 21 insertions(+), 23 deletions(-) rename MTC_Adapter/SCMA/{ => AdapterPLC}/AdapterDemo.cs (99%) rename MTC_Adapter/SCMA/{ => AdapterPLC}/AdapterGeneric.cs (99%) rename MTC_Adapter/SCMA/{ => AdapterPLC/CMS}/AdapterFanuc.cs (99%) rename MTC_Adapter/SCMA/{ => AdapterPLC/CMS}/AdapterOsai.cs (99%) rename MTC_Adapter/SCMA/{ => AdapterPLC/CMS}/AdapterSiemens.cs (99%) rename MTC_Adapter/SCMA/AdapterPLC/SCM/{ESA.cs => EsaKvara.cs} (99%) diff --git a/MTC_Adapter/SCMA/AdapterDemo.cs b/MTC_Adapter/SCMA/AdapterPLC/AdapterDemo.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterDemo.cs rename to MTC_Adapter/SCMA/AdapterPLC/AdapterDemo.cs index df595e9..784c712 100644 --- a/MTC_Adapter/SCMA/AdapterDemo.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/AdapterDemo.cs @@ -3,7 +3,7 @@ using MTConnect; using SCMA.AdapterCom; using System; -namespace SCMA +namespace SCMA.AdapterPLC { public class AdapterDemo : AdapterGeneric { diff --git a/MTC_Adapter/SCMA/AdapterGeneric.cs b/MTC_Adapter/SCMA/AdapterPLC/AdapterGeneric.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterGeneric.cs rename to MTC_Adapter/SCMA/AdapterPLC/AdapterGeneric.cs index dc86d86..46de8d9 100644 --- a/MTC_Adapter/SCMA/AdapterGeneric.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/AdapterGeneric.cs @@ -5,7 +5,7 @@ using System.IO; using System.Linq; using System.Text; -namespace SCMA +namespace SCMA.AdapterPLC { using AdapterCom; using MTC; diff --git a/MTC_Adapter/SCMA/AdapterFanuc.cs b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterFanuc.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterFanuc.cs rename to MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterFanuc.cs index 59d56cb..9bf8091 100644 --- a/MTC_Adapter/SCMA/AdapterFanuc.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterFanuc.cs @@ -4,7 +4,7 @@ using SCMA.AdapterCom; using System; using System.Text; -namespace SCMA +namespace SCMA.AdapterPLC.CMS { public class AdapterFanuc : AdapterGeneric { diff --git a/MTC_Adapter/SCMA/AdapterOsai.cs b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterOsai.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterOsai.cs rename to MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterOsai.cs index cc10cf0..2581b7c 100644 --- a/MTC_Adapter/SCMA/AdapterOsai.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterOsai.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace SCMA +namespace SCMA.AdapterPLC.CMS { public class AdapterOsai : AdapterGeneric { diff --git a/MTC_Adapter/SCMA/AdapterSiemens.cs b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterSiemens.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterSiemens.cs rename to MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterSiemens.cs index 077c32e..2f05881 100644 --- a/MTC_Adapter/SCMA/AdapterSiemens.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/CMS/AdapterSiemens.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace SCMA +namespace SCMA.AdapterPLC.CMS { public class AdapterSiemens : AdapterGeneric { diff --git a/MTC_Adapter/SCMA/AdapterPLC/SCM/ESA.cs b/MTC_Adapter/SCMA/AdapterPLC/SCM/EsaKvara.cs similarity index 99% rename from MTC_Adapter/SCMA/AdapterPLC/SCM/ESA.cs rename to MTC_Adapter/SCMA/AdapterPLC/SCM/EsaKvara.cs index b0eb3ac..a1f8886 100644 --- a/MTC_Adapter/SCMA/AdapterPLC/SCM/ESA.cs +++ b/MTC_Adapter/SCMA/AdapterPLC/SCM/EsaKvara.cs @@ -9,7 +9,7 @@ using System.Threading; namespace SCMA.AdapterPLC.SCM { - public class ESA : AdapterGeneric + public class EsaKvara : AdapterGeneric { /// /// Configurazione valori da leggere IOT_Byte @@ -245,7 +245,7 @@ namespace SCMA.AdapterPLC.SCM /// FORM chaimante /// CONFIGURAZIONE adapter /// OGGETTO gestione comunicazione OUT (tipologia e metodi) - public ESA(MainForm caller, AdapterConf adpConf, Gateway gatewayObj) : base(caller, adpConf, gatewayObj) + public EsaKvara(MainForm caller, AdapterConf adpConf, Gateway gatewayObj) : base(caller, adpConf, gatewayObj) { string iniPath = string.Format(@"{0}\{1}", utils.confDir, utils.CRS("defaultEsaFile")); diff --git a/MTC_Adapter/SCMA/MainForm.cs b/MTC_Adapter/SCMA/MainForm.cs index 35f2022..e2b01af 100644 --- a/MTC_Adapter/SCMA/MainForm.cs +++ b/MTC_Adapter/SCMA/MainForm.cs @@ -63,7 +63,7 @@ namespace SCMA /// /// Oggetto x gestione dell'adapter GENERICO (x poter usare metodi di ognuno...) /// - AdapterGeneric agObj; + AdapterPLC.AdapterGeneric agObj; /// /// configurazione caricata /// @@ -380,38 +380,38 @@ namespace SCMA switch (tipoScelto) { case tipoAdapter.DEMO: - agObj = new AdapterDemo(this, adpConf, currGateway); + agObj = new AdapterPLC.AdapterDemo(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], true); EnableTab(tabCtrlMain.TabPages[2], true); start.Enabled = true; break; case tipoAdapter.ESAGV: - agObj = new AdapterPLC.SCM.ESA(this, adpConf, currGateway); + agObj = new AdapterPLC.SCM.EsaKvara(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], true); EnableTab(tabCtrlMain.TabPages[2], false); start.Enabled = true; break; case tipoAdapter.FANUC: - agObj = new AdapterFanuc(this, adpConf, currGateway); + agObj = new AdapterPLC.CMS.AdapterFanuc(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], true); EnableTab(tabCtrlMain.TabPages[2], false); start.Enabled = true; break; case tipoAdapter.OSAI: - agObj = new AdapterOsai(this, adpConf, currGateway); + agObj = new AdapterPLC.CMS.AdapterOsai(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], true); EnableTab(tabCtrlMain.TabPages[2], false); start.Enabled = true; break; case tipoAdapter.SIEMENS: - agObj = new AdapterSiemens(this, adpConf, currGateway); + agObj = new AdapterPLC.CMS.AdapterSiemens(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], true); EnableTab(tabCtrlMain.TabPages[2], false); start.Enabled = true; break; case tipoAdapter.ND: default: - agObj = new AdapterDemo(this, adpConf, currGateway); + agObj = new AdapterPLC.AdapterDemo(this, adpConf, currGateway); EnableTab(tabCtrlMain.TabPages[1], false); EnableTab(tabCtrlMain.TabPages[2], false); start.Enabled = false; diff --git a/MTC_Adapter/SCMA/SCMA.csproj b/MTC_Adapter/SCMA/SCMA.csproj index d16a2c6..a0ad5a1 100644 --- a/MTC_Adapter/SCMA/SCMA.csproj +++ b/MTC_Adapter/SCMA/SCMA.csproj @@ -141,12 +141,12 @@ - - - - - - + + + + + + @@ -397,9 +397,7 @@ false - - - + normal/niente, altrimenti è l'allarme indicato!!! + if (numAlarmCNC == 0) + { + // init TUTTI i nodi... + currGateway.initAlarms(); + } + else + { + allarme currAllarm = elencoAllarmiCNC[numAlarmCNC - 1]; + // forzo a CNC x siocurezza... + currAllarm.gruppo = currGateway.nCncConditions; + currGateway.addAlarm(currAllarm); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_S_MD_")) + { + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_S_MD_", "")); + // salvo in vettore SE possibile... + if (numero <= vettUnOp.Length) + { + currGateway.updateItemNodeValue(vettUnOp[numero - 1].speedKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_T_MD_")) + { + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_T_MD_", "")); + // salvo in vettore SE possibile... + if (numero <= vettUnOp.Length) + { + currGateway.updateItemNodeValue(vettUnOp[numero - 1].toolIdKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_C_TC_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_C_TC_", "")); + // salvo in vettore SE possibile... + if (numero <= vettUnOp.Length) + { + currGateway.updateItemNodeValue(vettUnOp[numero - 1].numCUKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_C_H_MD_")) + { + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_C_H_MD_", "")); + // salvo in vettore SE possibile... + if (numero <= vettUnOp.Length) + { + currGateway.updateItemNodeValue(vettUnOp[numero - 1].accTimeKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_C_H_VAC_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_C_H_VAC_", "")); + // salvo in vettore SE possibile... + if (numero <= vettVacPump.Length) + { + currGateway.updateItemNodeValue(vettVacPump[numero - 1].workTimeKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_PGMR_A_")) + { + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_PGMR_A_", "")); + // salvo in vettore SE possibile... + if (numero <= vettMemArea.Length) + { + currGateway.updateItemNodeValue(vettMemArea[numero - 1].numRepKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + else if (mapIOT_Word[i].varName.StartsWith("IOT_C_EXEC_A_")) + { + try + { + numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_C_EXEC_A_", "")); + // salvo in vettore SE possibile... + if (numero <= vettMemArea.Length) + { + currGateway.updateItemNodeValue(vettMemArea[numero - 1].numExeKey, ncDevice.PLC_MemoryAreaIOT_Word[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_Word[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_Word[i].varName); + } + } + } + // verifico se nei mandini ho un tool e quanti cambi... + for (int i = 0; i < vettUnOp.Length; i++) + { + if (currGateway.getItemNode(vettUnOp[i].toolIdKey).ToString() != "") + { + sb.AppendLine(string.Format("UnOp_{0}: ToolId: {1} | NumCU: {2}", i + 1, currGateway.getItemNode(vettUnOp[i].toolIdKey), currGateway.getItemNode(vettUnOp[i].numCUKey))); + } + } + // update form! + parentForm.dataMonitor_2 += sb.ToString(); + } + /// + /// Carica ed acquisisce dati del buffer DWORD (32 bit) di memoria + /// + protected void getIotMem_DWord() + { + // accodo dati path in DataMonitor...... + StringBuilder sb = new StringBuilder(); + if (connectionOk) + { + // leggo TUTTO il blocco di memoria + parentForm.commPlcActive = true; + inizio = DateTime.Now; + ncDevice.ReadBufferDWord(); + if (utils.CRB("recTime")) + { + TimingData.addResult(string.Format("R{0}-PLC_IOT-DWord", ncDevice.PLC_MemoryAreaIOT_DWord.Length), DateTime.Now.Subtract(inizio).Ticks); + } + + parentForm.commPlcActive = false; + } + else + { + lg.Error("Errore connessione mancante in getIotMem_DWord"); + } + + int numero = 0; + int byteNum = 0; + double valDouble = 0; + // Processing area WORD + for (int i = 0; i < mapIOT_DWord.Length; i++) + { + int.TryParse(mapIOT_DWord[i].memAddr, out byteNum); + if (mapIOT_DWord[i].varName == "IOT_FEED") + { + FeedRate = BitConverter.ToInt32(BitConverter.GetBytes(ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]), 0); + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_FEED_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_FEED_", "")); + // salvo in vettore SE possibile... + if (numero <= FeedRateGrp.Length) + { + FeedRateGrp[numero - 1] = BitConverter.ToInt32(BitConverter.GetBytes(ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]), 0); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_DWord[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_C_KU_AX_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_C_KU_AX_", "")); + // salvo in vettore SE possibile... + if (numero <= vettAxis.Length) + { + currGateway.updateItemNodeValue(vettAxis[numero - 1].distDoneKey, ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_DWord[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_C_KINV_AX_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_C_KINV_AX_", "")); + // salvo in vettore SE possibile... + if (numero <= vettAxis.Length) + { + currGateway.updateItemNodeValue(vettAxis[numero - 1].invDDoneKey, ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_DWord[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_POS_AX_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_POS_AX_", "")); + // recupero valore pos assi (in micron) + valDouble = BitConverter.ToInt32(BitConverter.GetBytes(ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]), 0); + // salvo in vettore SE possibile... + if (numero <= vettAxis.Length) + { + // riporto il dato in mm (divido x 1000) + currGateway.updateItemNodeValue(vettAxis[numero - 1].posActKey, valDouble / utils.CRI("fattdecimale")); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_DWord[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_C_KREV_MD_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_C_KREV_MD_", "")); + // salvo in vettore SE possibile... + if (numero <= vettUnOp.Length) + { + currGateway.updateItemNodeValue(vettUnOp[numero - 1].kRevKey, ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]); + } + else + { + lg.Error("Errore in inserimento vettore " + mapIOT_DWord[i].varName); + } + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + else if (mapIOT_DWord[i].varName.StartsWith("IOT_PLC_MSG_")) + { + // recupero NUMERO + try + { + numero = Convert.ToInt32(mapIOT_DWord[i].varName.Replace("IOT_PLC_MSG_", "")); + // copio allarmi in vettore generale AlarmFlags (dove lo gestisce) 4 byte alla volta + Buffer.BlockCopy(BitConverter.GetBytes(ncDevice.PLC_MemoryAreaIOT_DWord[byteNum]), 0, currGateway.AlarmFlags, numero * 4, 4); + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_DWord[i].varName); + } + } + } + // aggiungo feedrate + sb.AppendLine(string.Format("FeedRate: {0} mm/min", FeedRate)); + // verifico se nei gruppi di feed ho qualcosa di diverso da zero... + for (int i = 0; i < 20; i++) + { + if (FeedRateGrp[i] != 0) + { + sb.AppendLine(string.Format("FeedRate_{1}: {0:00} mm/min", FeedRateGrp[i], i)); + } + } + // update form! + parentForm.dataMonitor_1 += sb.ToString(); + } + /// + /// Carica ed acquisisce dati del buffer STRING di memoria + /// + protected void getIotMem_String() + { + // accodo dati path in DataMonitor...... + StringBuilder sb = new StringBuilder(); + if (connectionOk) + { + // leggo TUTTO il blocco di memoria + parentForm.commPlcActive = true; + inizio = DateTime.Now; + ncDevice.ReadBufferString(); + if (utils.CRB("recTime")) + { + TimingData.addResult(string.Format("R{0}-PLC_IOT-DWord", ncDevice.PLC_MemoryAreaIOT_DWord.Length), DateTime.Now.Subtract(inizio).Ticks); + } + + parentForm.commPlcActive = false; + } + else + { + lg.Error("Errore connessione mancante in getIotMem_DWord"); + } + + // Processing area STRING: OGNI area di memoria... + for (int j = 0; j < mapIOT_String.Length; j++) + { + string valString = ""; + + for (int i = 0; i < numString; i++) + { + try + { + valString += Convert.ToChar(ncDevice.PLC_MemoryAreaIOT_String[j, i]).ToString().Replace("\0", " "); + } + catch (Exception exc) + { + lg.Error(exc, "Errore in decodifica " + mapIOT_String[i].varName); + } + } + // trimmo! + valString = valString.Trim(); + // salvo + currGateway.updateItemNodeCodeValue(vettMemArea[j].prgNameKey, j.ToString(), valString); + // aggiungo nomi programmi... + sb.AppendLine(string.Format("{0}: {1}", mapIOT_String[j].varName, valString)); + } + // update form! + parentForm.dataMonitor_2 += sb.ToString(); + } + public override void getGlobalData() + { + base.getGlobalData(); + } + + /// + /// Processing di TUTTA l'area di memoria configurata e delle variabili derivate... + /// + public override void processAllMemory() + { + // inizializzo data monitor su FORM + parentForm.dataMonitor_1 = ""; + parentForm.dataMonitor_2 = ""; + parentForm.dataMonitor_3 = ""; + + // recupero le varie memorie (prima string che mi serve x area selezionata --> programma selezionato) + getIotMem_String(); + getIotMem_Byte(); + getIotMem_Word(); + getIotMem_DWord(); + + // processo componenti specifici x info... + getUnOp(); + getPath(); + getAxis(); + } + + /// + /// Recupera la speed override x i mandrini (UnOp) + /// + public override void getUnOp() + { + // cicl su UnOp + for (int i = 0; i < currAdpConf.nUnOp; i++) + { + currGateway.updateItemNodeValue(vettUnOp[i].speedOverKey, SpeedRateOver); + } + } + + /// + /// Carica info accessorie assi (direzione, feed, ...) + /// + public override void getAxis() + { + // mostro assi in DataMonitor...... + StringBuilder sb = new StringBuilder(); + + // nuova posizione (per calcoli) + double newPos = 0; + double distPerc = 0; + int newDir = 0; + string tipoAsse = ""; + string direzione = ""; + int numInvAx = 0; + + // leggo in modo "cablato" i dati dei vari assi... + for (int i = 0; i < currAdpConf.nAxis; i++) + { + // verifico: se l'asse appartiene ad un gruppo uso la sua feedrate... + int axGroup = 0; + try + { + axGroup = Convert.ToInt32(currGateway.getItemNode(vettAxis[i].groupKey)); + } + catch + { } + if (axGroup > 0) + { + currGateway.updateItemNodeValue(vettAxis[i].feedrateKey, FeedRateGrp[axGroup - 1]); + } + else + { + currGateway.updateItemNodeValue(vettAxis[i].feedrateKey, FeedRate); + } + + currGateway.updateItemNodeValue(vettAxis[i].feedOverKey, FeedRateOver); + + // calcolo distanza e salvo valore... + newPos = Convert.ToDouble(currGateway.getItemNode(vettAxis[i].posActKey)); + distPerc = newPos - prevPosAxis[i]; + + // sistemo direzione +/- (POS/NEG se lineari, CCW/CW se rotativi) + if (distPerc != 0) + { + newDir = Convert.ToInt32(distPerc / Math.Abs(distPerc)); + } + else + { + newDir = prevDirAxis[i]; + } + + + // verifico tipo direzione da tipo asse... + tipoAsse = currGateway.getItemNode(vettAxis[i].typeKey).ToString(); + if (tipoAsse == "LINEAR") + { + // ?: conditional operator. + direzione = (newDir > 0) ? "POSITIVE" : "NEGATIVE"; + } + else if (tipoAsse == "ROTARY") + { + direzione = (newDir > 0) ? "CLOCKWISE" : "COUNTER_CLOCKWISE"; + } + + currGateway.updateItemNodeValue(vettAxis[i].directionKey, direzione); + + // se la direzione è variata salvo il cambio direzione... + if (newDir != prevDirAxis[i]) + { + // recupero num prec... + numInvAx = Convert.ToInt32(istNumInvAssi[i].vcMedian); + numInvAx++; + // salvo "+1" come cambi direzione.... ATTENZIONE servirà che la finestra sia "corta" (tipo 1 sec...) mentre io ne inserisco 3 distanziati di 1/5 sec + istNumInvAssi[i].addValue(DateTime.Now.AddMilliseconds(-400), numInvAx); + istNumInvAssi[i].addValue(DateTime.Now.AddMilliseconds(-200), numInvAx); + istNumInvAssi[i].addValue(DateTime.Now, numInvAx); + } + + if (utils.CRB("verbose")) + { + sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3} | {2}", i, newPos, direzione)); + } + + // salvo valori vettore prec... + prevPosAxis[i] = newPos; + prevDirAxis[i] = newDir; + } + + parentForm.dataMonitor_3 += sb.ToString(); + } + } +} diff --git a/MTC_Adapter/SCMA/SCMA.csproj b/MTC_Adapter/SCMA/SCMA.csproj index 6ae6c9a..b60b9e9 100644 --- a/MTC_Adapter/SCMA/SCMA.csproj +++ b/MTC_Adapter/SCMA/SCMA.csproj @@ -141,6 +141,7 @@ +