From ece150ab56369da4e483a21c61ea34824dff75ae Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 19 Jul 2019 20:52:55 +0200 Subject: [PATCH] Sistemato FIXME x TIPO ASSI!!! --- Jenkinsfile | 2 +- MTC_Adapter/SCMA/AdapterFanuc.cs | 28 ++---- MTC_Adapter/SCMA/AdapterGeneric.cs | 131 ++++++++++++++++++++++++++++- MTC_Adapter/SCMA/AdapterOsai.cs | 30 +++---- MTC_Adapter/SCMA/AdapterSiemens.cs | 45 ++-------- 5 files changed, 155 insertions(+), 81 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8641729..bc238cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=411']) { + withEnv(['NEXT_BUILD_NUMBER=417']) { // env.versionNumber = VersionNumber(versionNumberString : '2.1.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.1.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'SCMA' diff --git a/MTC_Adapter/SCMA/AdapterFanuc.cs b/MTC_Adapter/SCMA/AdapterFanuc.cs index b0eaab0..4293c13 100644 --- a/MTC_Adapter/SCMA/AdapterFanuc.cs +++ b/MTC_Adapter/SCMA/AdapterFanuc.cs @@ -599,7 +599,7 @@ namespace SCMA } // salvo! ouStatus = MemBlock[0]; - + // recupero valore PUNTUALE status da apposita area memoria... se ha valore >=0... if (ouStatusByPlc && ouStatus >= 0) { @@ -644,7 +644,7 @@ namespace SCMA // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 14000; byte[] tabDatiMtzByte = new byte[4 * maintData.Length]; - uint[] tabDatiMtz = new uint[maintData.Length]; + uint[] tabDatiMtz = new uint[maintDataMaxNum]; inizio = DateTime.Now; FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiMtzByte); if (utils.CRB("recTime")) @@ -674,8 +674,8 @@ namespace SCMA { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 15000; - byte[] tabDatiAnalogByte = new byte[4 * analogData.Length]; - uint[] tabDatiAnalog = new uint[analogData.Length]; + byte[] tabDatiAnalogByte = new byte[4 * analogDataMaxNum]; + uint[] tabDatiAnalog = new uint[analogDataMaxNum]; inizio = DateTime.Now; FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiAnalogByte); if (utils.CRB("recTime")) @@ -702,11 +702,11 @@ namespace SCMA bool fatto = false; try { - if (statusData.Length > 0) + if (statusDataMaxNum > 0) { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 14512; - int numByte = 1 + (statusData.Length / 8); + int numByte = 1 + (statusDataMaxNum / 8); byte[] tabDatiStatus = new byte[numByte]; inizio = DateTime.Now; FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiStatus); @@ -1177,7 +1177,6 @@ namespace SCMA double newPos = 0; double distPerc = 0; int newDir = 0; - string tipoAsse = ""; string direzione = ""; for (int i = 0; i < currAdpConf.nAxis; i++) @@ -1342,18 +1341,9 @@ namespace SCMA { 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"; - } + // calcolo direzione + direzione = calculateDirection(newDir, i); + // imposto direzione currGateway.updateItemNodeValue(vettAxis[i].directionKey, direzione); if (utils.CRB("verbose")) diff --git a/MTC_Adapter/SCMA/AdapterGeneric.cs b/MTC_Adapter/SCMA/AdapterGeneric.cs index 2e7e6c8..817c984 100644 --- a/MTC_Adapter/SCMA/AdapterGeneric.cs +++ b/MTC_Adapter/SCMA/AdapterGeneric.cs @@ -2431,7 +2431,58 @@ namespace SCMA eh_refreshed(this, new EventArgs()); } } - + /// + /// Effettua verifica direzione asse + /// + /// + /// + protected string calculateDirection(int newDir, int i) + { + string tipoAsse = ""; + string direzione = ""; + // controllo se tipo MTC/SOUR + if (currGateway.protocollo != gwProtocol.SOURS) + { + tipoAsse = currGateway.getItemNode(vettAxis[i].typeKey).ToString(); + } + else + { + // recupero info TIPO ASSE + List> drl = vettAxis[i].dataRefList; + foreach (var item in drl) + { + if (item.Key == vettAxis[i].typeKey) + { + tipoAsse = item.Value; + } + } + } + // verifico tipo direzione da tipo asse... + if (tipoAsse == "LINEAR") + { + if (currGateway.protocollo == gwProtocol.SOURS) + { + direzione = (newDir > 0) ? "POS" : "NEG"; + } + else + { + // ?: conditional operator. + direzione = (newDir > 0) ? "POSITIVE" : "NEGATIVE"; + } + } + else if (tipoAsse == "ROTARY") + { + if (currGateway.protocollo == gwProtocol.SOURS) + { + direzione = (newDir > 0) ? "CW" : "CCW"; + } + else + { + direzione = (newDir > 0) ? "CLOCKWISE" : "COUNTER_CLOCKWISE"; + } + } + return direzione; + } /// /// Area per effettuazione test (tipicamente variabili scambiate da MTC --> generali... /// @@ -4187,6 +4238,31 @@ namespace SCMA // return! return answ; } + /// + /// Numero massimo (indice) valori maintData (privato) + /// + protected int _maintDataMaxNum = 0; + /// + /// Numero massimo (indice) valori maintData (calcolato) + /// + public int maintDataMaxNum + { + get + { + if (_maintDataMaxNum == 0) + { + // prima stima + int idx = maintData.Length; + // ora ciclo... + foreach (var item in maintData) + { + int.TryParse(item.codNum, out idx); + _maintDataMaxNum = idx > _maintDataMaxNum ? idx : _maintDataMaxNum; + } + } + return _maintDataMaxNum; + } + } /// /// Processa la tabella di memoria dei dati di manutenzione @@ -4326,7 +4402,7 @@ namespace SCMA catch (Exception exc) { valRead = 0; - lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); + lg.Error(string.Format("Errore in recupero num AccTime:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); } istAccTimeAssi[numero - 1].addValue(DateTime.Now, Convert.ToInt32(valRead)); } @@ -4469,7 +4545,31 @@ namespace SCMA } } } - + /// + /// Numero massimo (indice) valori analogData (privato) + /// + protected int _analogDataMaxNum = 0; + /// + /// Numero massimo (indice) valori analogData (calcolato) + /// + public int analogDataMaxNum + { + get + { + if (_analogDataMaxNum == 0) + { + // prima stima + int idx = analogData.Length; + // ora ciclo... + foreach (var item in analogData) + { + int.TryParse(item.codNum, out idx); + _analogDataMaxNum = idx > _analogDataMaxNum ? idx : _analogDataMaxNum; + } + } + return _analogDataMaxNum; + } + } /// /// Processa la tabella di memoria dei dati analogici /// @@ -4551,6 +4651,31 @@ namespace SCMA } } + /// + /// Numero massimo (indice) valori analogData (privato) + /// + protected int _statusDataMaxNum = 0; + /// + /// Numero massimo (indice) valori analogData (calcolato) + /// + public int statusDataMaxNum + { + get + { + if (_statusDataMaxNum == 0) + { + // prima stima + int idx = statusData.Length; + // ora ciclo... + foreach (var item in statusData) + { + int.TryParse(item.codNum, out idx); + _statusDataMaxNum = idx > _statusDataMaxNum ? idx : _statusDataMaxNum; + } + } + return _statusDataMaxNum; + } + } /// /// Processa la tabella di memoria degli status di manutenzione /// diff --git a/MTC_Adapter/SCMA/AdapterOsai.cs b/MTC_Adapter/SCMA/AdapterOsai.cs index 19beeda..5f5542f 100644 --- a/MTC_Adapter/SCMA/AdapterOsai.cs +++ b/MTC_Adapter/SCMA/AdapterOsai.cs @@ -680,7 +680,8 @@ namespace SCMA { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 1000; - uint[] tabDatiMtz = new uint[maintData.Length]; + // calcolo indice max scorrendo... + uint[] tabDatiMtz = new uint[maintDataMaxNum]; inizio = DateTime.Now; OsaiMemRW_DWord(R, OSAI.MemTypeWord.GW_CODE, memIndex, ref tabDatiMtz); if (utils.CRB("recTime")) @@ -710,7 +711,7 @@ namespace SCMA { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 19434; - uint[] tabDatiAnalog = new uint[analogData.Length]; + uint[] tabDatiAnalog = new uint[analogDataMaxNum]; inizio = DateTime.Now; OsaiMemRW_DWord(R, OSAI.MemTypeWord.MW_CODE, memIndex, ref tabDatiAnalog); if (utils.CRB("recTime")) @@ -736,11 +737,11 @@ namespace SCMA bool fatto = false; try { - if (statusData.Length > 0) + if (statusDataMaxNum > 0) { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 19426; - int numByte = 1 + (statusData.Length / 8); + int numByte = 1 + (statusDataMaxNum / 8); byte[] tabDatiStatus = new byte[numByte]; inizio = DateTime.Now; OsaiMemRW_Byte(R, OSAI.MemTypeWord.MW_CODE, memIndex, 0, ref tabDatiStatus); @@ -1017,9 +1018,9 @@ namespace SCMA // 2017.01.16 da rivedere currGateway.updateItemNodeValue(vettPath[i].currProgRowNumKey, ""); currGateway.updateItemNodeValue(vettPath[i].activeAxesKey, ""); + sb_2.AppendLine(string.Format("Path {0}, PROG: {1}", i + 1, currGateway.getItemNode(vettPath[i].currProgKey))); } - sb_2.AppendLine(string.Format("Path {0}, PROG: {1}", i + 1, currGateway.getItemNode(vettPath[i].currProgKey))); sb_3.AppendLine(string.Format("Path {0}, GCodes: {1}", i + 1, GCodAttivi)); parentForm.dataMonitor_2 += sb_2.ToString(); @@ -1139,7 +1140,6 @@ namespace SCMA double newPosTgt = 0; double distPerc = 0; int newDir = 0; - string tipoAsse = ""; string direzione = ""; // ORA ho tutto in posizione corretta, PROCESSO!!! for (int i = 0; i < currAdpConf.nAxis; i++) @@ -1185,20 +1185,9 @@ namespace SCMA { newDir = prevDirAxis[i]; } - - // controllo se tipo MTC/SOUR - // 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"; - } - + // calcolo direzione + direzione = calculateDirection(newDir, i); + // imposto direzione currGateway.updateItemNodeValue(vettAxis[i].directionKey, direzione); if (utils.CRB("verbose")) @@ -1226,5 +1215,6 @@ namespace SCMA parentForm.commPlcActive = false; parentForm.dataMonitor_3 += sb.ToString(); } + } } diff --git a/MTC_Adapter/SCMA/AdapterSiemens.cs b/MTC_Adapter/SCMA/AdapterSiemens.cs index 3981da6..622252d 100644 --- a/MTC_Adapter/SCMA/AdapterSiemens.cs +++ b/MTC_Adapter/SCMA/AdapterSiemens.cs @@ -3,6 +3,7 @@ using MTC; using SCMA.AdapterCom; using Siemens.Sinumerik.Operate.Services; using System; +using System.Collections.Generic; using System.Text; namespace SCMA @@ -676,7 +677,7 @@ namespace SCMA { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 536; - uint[] tabDatiMtz = new uint[maintData.Length]; + uint[] tabDatiMtz = new uint[maintDataMaxNum]; inizio = DateTime.Now; SIEMENSMemRW_DWord(R, baseMemDb, memIndex, ref tabDatiMtz); if (utils.CRB("recTime")) @@ -700,11 +701,11 @@ namespace SCMA bool fatto = false; try { - if (statusData.Length > 0) + if (statusDataMaxNum > 0) { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 1048; - int numByte = 1 + (statusData.Length / 8); + int numByte = 1 + (statusDataMaxNum / 8); byte[] tabDatiStatus = new byte[numByte]; inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref tabDatiStatus); @@ -733,7 +734,7 @@ namespace SCMA { // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 1064; - uint[] tabDatiAnalog = new uint[analogData.Length]; + uint[] tabDatiAnalog = new uint[analogDataMaxNum]; inizio = DateTime.Now; SIEMENSMemRW_DWord(R, baseMemDb, memIndex, ref tabDatiAnalog); if (utils.CRB("recTime")) @@ -986,7 +987,6 @@ namespace SCMA double newPos = 0; double distPerc = 0; int newDir = 0; - string tipoAsse = ""; string direzione = ""; // recupero in blocco dati assi... @@ -1023,39 +1023,8 @@ namespace SCMA { newDir = prevDirAxis[i]; } - - // FIXME!!! CONTROLLARE TIPO ASSI - // verifico tipo direzione da tipo asse... - tipoAsse = "LINEAR"; - try - { - currGateway.getItemNode(vettAxis[i].typeKey).ToString(); - } - catch - { } - if (tipoAsse == "LINEAR") - { - if (currGateway.protocollo == gwProtocol.SOURS) - { - direzione = (newDir > 0) ? "POS" : "NEG"; - } - else - { - // ?: conditional operator. - direzione = (newDir > 0) ? "POSITIVE" : "NEGATIVE"; - } - } - else if (tipoAsse == "ROTARY") - { - if (currGateway.protocollo == gwProtocol.SOURS) - { - direzione = (newDir > 0) ? "CW" : "CCW"; - } - else - { - direzione = (newDir > 0) ? "CLOCKWISE" : "COUNTER_CLOCKWISE"; - } - } + // calcolo direzione + direzione = calculateDirection(newDir, i); // imposto direzione currGateway.updateItemNodeValue(vettAxis[i].directionKey, direzione);