From 285191d4b5cb3cbb10da32b91bf4b084262e19ad Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 9 Aug 2019 07:45:34 +0200 Subject: [PATCH] bozza gestione FANUC --- MTC_Adapter/MTC/baseUtils.cs | 12 ++++++++++ MTC_Adapter/SCMA/AdapterFanuc.cs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/MTC_Adapter/MTC/baseUtils.cs b/MTC_Adapter/MTC/baseUtils.cs index 6da8e2f..c94a89a 100644 --- a/MTC_Adapter/MTC/baseUtils.cs +++ b/MTC_Adapter/MTC/baseUtils.cs @@ -86,6 +86,18 @@ namespace MTC #region area manipolazione bit/byte + + /// + /// verifica se un dato bit sia alzato (come flag di strobe) + /// + /// valore da testare + /// valore cercato come INDICE base 0 del byte (b0..b7) + /// + public static bool IsSetBit(byte currByte, int bitNum) + { + return ((currByte & (1 << bitNum)) != 0); + } + /// /// verifica se un dato bit sia alzato (come flag di strobe) /// diff --git a/MTC_Adapter/SCMA/AdapterFanuc.cs b/MTC_Adapter/SCMA/AdapterFanuc.cs index 4e86ad8..212db74 100644 --- a/MTC_Adapter/SCMA/AdapterFanuc.cs +++ b/MTC_Adapter/SCMA/AdapterFanuc.cs @@ -1298,6 +1298,44 @@ namespace SCMA int[] axis2pathBase = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int[] axis2pathTransf = new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 }; + // processo le assegnazioni, partendo da quelle configurate "teoriche" + int[] assegnazioni = new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 }; + // per iniziare: devo capire quante siano le assegnazioni in ballo (conto i "2") + int numAxComp = 0; + int firstComp = -1; + foreach (var item in assegnazioni) + { + if (item == 1) + { + // solo se NON HO ancora assi COMP... incremento + if (numAxComp == 0) firstComp++; + } + else + { + numAxComp++; + } + } + // verificare: dovrei avere numAxComp = 3 e firstComp = 3 + + // ora scorro il vettore iniziale e verifico dai bit le effettive assegnazioni... + int bitIdx = 0; + for (int i = 0; i < numAxComp; i++) + { + // controllo il bit... + if (baseUtils.IsSetBit(assegnazioni[firstComp + i], bitIdx)) + { + // in questo caso "azzero" l'assegnazione relativa successiva + assegnazioni[firstComp + i + numAxComp] = 0; + } + else + { + // tolgo assegnazione "corrente" + assegnazioni[firstComp + i] = 0; + } + bitIdx++; + } + + byte bmapG1128 = 0; FanucMemRW(R, FANUC.MemType.G, 1128, ref bmapG1128); @@ -1307,7 +1345,7 @@ namespace SCMA // SE ho bit alzati --> effettivamente sul processo 2... for (int i = 0; i < 8; i++) { - if ((bmapG1128 & (1 << i)) != 0) + if ((0 & (1 << i)) != 0) { } }