diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index 3572a5d..d285282 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -484,7 +484,8 @@ namespace MTC_Adapter try { // aggiorno vettore allarmi x intero! size del vettore di destinazione (in byte!!!!) - Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length); + //Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length); // da testare FANUC!!! + Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, AlarmFlags.Length); } catch (Exception exc) { diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index 3f618e7..4e17cd9 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using CMSCncLib.CNC; namespace MTC_Adapter { @@ -1611,6 +1612,259 @@ namespace MTC_Adapter return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim()); } + #region oggetti specifici per CNC OSAI/FANUC/SIEMENS... + + #region CNC OSAI + + /// + /// Oggetto MAIN x connessione OSAI + /// + protected OSAI OSAI_ref; + /// + /// wrapper chiamata lettura/scrittura OSAI x BYTE... + /// + /// + /// + /// + /// 0/1 orimo o secondo byte della word... + /// + /// + public bool OsaiMemRW_Byte(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, Int32 memOrderStart, ref byte[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_Byte(bWrite, MemType, memIndex, memOrderStart, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura x WORD... + /// + /// + /// + /// + /// + /// + public bool OsaiMemRW_Word(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref ushort[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_Word(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura x DOUBLE-WORD... + /// + /// + /// + /// + /// + /// + public bool OsaiMemRW_DWord(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref uint[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_DWord(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura x Short... + /// + /// + /// + /// + /// + /// + public bool OsaiMemRW_Short(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref short[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_Short(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura x INT... + /// + /// + /// + /// + /// + /// + public bool OsaiMemRW_Integer(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref int[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_Integer(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura x Double... + /// + /// + /// + /// + /// + /// + public bool OsaiMemRW_Double(bool bWrite, OSAI.MemTypeDouble MemType, Int32 memIndex, ref double[] Value) + { + bool answ = false; + if (OSAI_ref.Connected) + { + try + { + answ = OSAI_ref.O_RW_Double(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + + #endregion + + #region CNC Siemens + + /// + /// Oggetto MAIN x connessione SIEMENS + /// + protected SIEMENS SIEMENS_ref; + + /// + /// Area di memoria base x MTConnect con SIEMENS (DB1499) + /// + protected int baseMemDb = 1499; + /// + /// Area di memoria base x dati UTENSILE (DB253) + /// + protected int baseMemUT = 253; + /// + /// Area di memoria base x dati TESTE (DB254) + /// + protected int baseMemUO = 254; + + /// + /// wrapper chiamata lettura/scrittura SINGOLO BYTE... + /// + /// + /// main address (1499/1500) + /// + /// + /// + public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte Value) + { + bool answ = false; + // chiamo la versione multibyte... + byte[] ValArray = new byte[1]; + SIEMENSMemRW_Byte(bWrite, MemType, memIndex, ref ValArray); + Value = ValArray[0]; + return answ; + } + /// + /// wrapper chiamata lettura/scrittura MULTI BYTE... + /// + /// + /// main address (1499/1500) + /// + /// + /// + public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte[] Value) + { + bool answ = false; + if (SIEMENS_ref.Connected) + { + try + { + answ = SIEMENS_ref.S_RW_Byte(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura MULTI Word... + /// + /// + /// main address (1499/1500) + /// + /// + /// + public bool SIEMENSMemRW_Word(bool bWrite, int MemType, Int32 memIndex, ref ushort[] Value) + { + bool answ = false; + if (SIEMENS_ref.Connected) + { + try + { + answ = SIEMENS_ref.S_RW_Word(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + /// + /// wrapper chiamata lettura/scrittura MULTI DWord... + /// + /// + /// main address (1499/1500) + /// + /// + /// + public bool SIEMENSMemRW_DWord(bool bWrite, int MemType, Int32 memIndex, ref uint[] Value) + { + bool answ = false; + if (SIEMENS_ref.Connected) + { + try + { + answ = SIEMENS_ref.S_RW_DWord(bWrite, MemType, memIndex, ref Value); + } + catch + { } + } + return answ; + } + + #endregion + + + #endregion + #region metodi adapter /// @@ -2181,147 +2435,147 @@ namespace MTC_Adapter { } - /// - /// Gestione STROBE --> ACK per codici M/S/T - /// - /// byte di strobe corrente - /// 0/1/2 - /// vettore da restituire di ACK - /// shift memoria x buffer dati da leggere - /// Vettore completo dei valori + buffer code M/S/T - /// Quale coda: M/S/T - /// Path (0,1,...) - public void gestStrobeCodMST(StFlag8 currStrobe, int bitNum, ref byte[] retACK_DW1, int memShift, byte[] MemBlock, string Coda, int idxPath) - { - int numEv = 0; - int codEv = 0; - if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum))) - { - // verifico sia > 0 il numero di valori da leggere - indice 0 sull'area... - numEv = BitConverter.ToUInt16(MemBlock, 2 * memShift); - if (numEv > 0) - { - // il num ev rappresenta quanti slot 16bit (da 2 byte) sono stati valorizzati, VA FATTO CICLO E LETTI TUTTI - for (int i = 0; i < numEv; i++) - { - // leggo valore Codice - codEv = BitConverter.ToUInt16(MemBlock, 2 * (i + 2 + memShift)); - // accodo evento Codice - appendCodeMST(Coda, codEv.ToString(), idxPath); - } - } - // memorizzo allarme nel vettore ack.... - retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum); - } + /// + /// Gestione STROBE --> ACK per codici M/S/T + /// + /// byte di strobe corrente + /// 0/1/2 + /// vettore da restituire di ACK + /// shift memoria x buffer dati da leggere + /// Vettore completo dei valori + buffer code M/S/T + /// Quale coda: M/S/T + /// Path (0,1,...) + public void gestStrobeCodMST(StFlag8 currStrobe, int bitNum, ref byte[] retACK_DW1, int memShift, byte[] MemBlock, string Coda, int idxPath) + { + int numEv = 0; + int codEv = 0; + if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum))) + { + // verifico sia > 0 il numero di valori da leggere - indice 0 sull'area... + numEv = BitConverter.ToUInt16(MemBlock, 2 * memShift); + if (numEv > 0) + { + // il num ev rappresenta quanti slot 16bit (da 2 byte) sono stati valorizzati, VA FATTO CICLO E LETTI TUTTI + for (int i = 0; i < numEv; i++) + { + // leggo valore Codice + codEv = BitConverter.ToUInt16(MemBlock, 2 * (i + 2 + memShift)); + // accodo evento Codice + appendCodeMST(Coda, codEv.ToString(), idxPath); + } + } + // memorizzo allarme nel vettore ack.... + retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum); + } } - /// - /// Gestione strobe UserAction: salva dati e gestione ACK - /// - /// - /// - /// - /// - public void gestStrobeUserAction(int bitNum, ref byte[] retACK_DW1, ref string UserAction, string azione) - { - if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum))) - { - // salvo evento UserAction in variabile... - UserAction += azione; - // memorizzo allarme nel vettore ack.... - retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum); - } + /// + /// Gestione strobe UserAction: salva dati e gestione ACK + /// + /// + /// + /// + /// + public void gestStrobeUserAction(int bitNum, ref byte[] retACK_DW1, ref string UserAction, string azione) + { + if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum))) + { + // salvo evento UserAction in variabile... + UserAction += azione; + // memorizzo allarme nel vettore ack.... + retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum); + } } - /// - /// Ricarica dati da file di scambio con CMSConnect - /// - public void reloadDataFromFile() - { - if (utils.CRB("verbose")) lg.Info("Inizio lettura dati da file"); - int totRighe = 0; - // da rivedere: se sono N+1 file (N=path + generale) deve essere ad esempio nomeComune_*.mtc --> ciclo per leggerne N - string fileName = string.Format(@"{0}\{1}", utils.dataDir, utils.CRS("GeneralStatusFilePath")); - string linea; - // creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco... - generalStatus = new Dictionary(); - try - { - totRighe = File.ReadLines(fileName).Count(); - // carica da file... - System.IO.StreamReader file = new System.IO.StreamReader(fileName); - if (file != null) - { - // leggo 1 linea alla volta... - string[] valori; - while ((linea = file.ReadLine()) != null) - { - // SE non è un commento... - if (linea.Substring(0, 1) != "#") - { - valori = linea.Split(utils.CRC("testCharSep")); - generalStatus.Add(valori[0], valori[1]); - } - } - // chiudo file - file.Close(); - if (utils.CRB("verbose")) lg.Info("Fine lettura dati da file"); - } - } - catch - { - lg.Info("Errore in lettura dati da file"); - } - - - // ora salvo valori letti... - foreach (KeyValuePair item in generalStatus) - { - // verifico la chiave e nel caso aggiorno... - switch (item.Key) - { - case "OperatorId": - mOperator.Value = item.Value; - break; - case "Path_01_CurrProg": - istPathProgrName[0] = item.Value; - break; - case "Path_02_CurrProg": - istPathProgrName[1] = item.Value; - break; - case "Path_03_CurrProg": - istPathProgrName[2] = item.Value; - break; - case "Path_04_CurrProg": - istPathProgrName[3] = item.Value; - break; - case "Path_05_CurrProg": - istPathProgrName[4] = item.Value; - break; - case "Path_06_CurrProg": - istPathProgrName[5] = item.Value; - break; - case "Path_01_PartId": - istPathPartId[0] = item.Value; - break; - case "Path_02_PartId": - istPathPartId[1] = item.Value; - break; - case "Path_03_PartId": - istPathPartId[2] = item.Value; - break; - case "Path_04_PartId": - istPathPartId[3] = item.Value; - break; - case "Path_05_PartId": - istPathPartId[4] = item.Value; - break; - case "Path_06_PartId": - istPathPartId[5] = item.Value; - break; - default: - break; - } - } + /// + /// Ricarica dati da file di scambio con CMSConnect + /// + public void reloadDataFromFile() + { + if (utils.CRB("verbose")) lg.Info("Inizio lettura dati da file"); + int totRighe = 0; + // da rivedere: se sono N+1 file (N=path + generale) deve essere ad esempio nomeComune_*.mtc --> ciclo per leggerne N + string fileName = string.Format(@"{0}\{1}", utils.dataDir, utils.CRS("GeneralStatusFilePath")); + string linea; + // creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco... + generalStatus = new Dictionary(); + try + { + totRighe = File.ReadLines(fileName).Count(); + // carica da file... + System.IO.StreamReader file = new System.IO.StreamReader(fileName); + if (file != null) + { + // leggo 1 linea alla volta... + string[] valori; + while ((linea = file.ReadLine()) != null) + { + // SE non è un commento... + if (linea.Substring(0, 1) != "#") + { + valori = linea.Split(utils.CRC("testCharSep")); + generalStatus.Add(valori[0], valori[1]); + } + } + // chiudo file + file.Close(); + if (utils.CRB("verbose")) lg.Info("Fine lettura dati da file"); + } + } + catch + { + lg.Info("Errore in lettura dati da file"); + } + + + // ora salvo valori letti... + foreach (KeyValuePair item in generalStatus) + { + // verifico la chiave e nel caso aggiorno... + switch (item.Key) + { + case "OperatorId": + mOperator.Value = item.Value; + break; + case "Path_01_CurrProg": + istPathProgrName[0] = item.Value; + break; + case "Path_02_CurrProg": + istPathProgrName[1] = item.Value; + break; + case "Path_03_CurrProg": + istPathProgrName[2] = item.Value; + break; + case "Path_04_CurrProg": + istPathProgrName[3] = item.Value; + break; + case "Path_05_CurrProg": + istPathProgrName[4] = item.Value; + break; + case "Path_06_CurrProg": + istPathProgrName[5] = item.Value; + break; + case "Path_01_PartId": + istPathPartId[0] = item.Value; + break; + case "Path_02_PartId": + istPathPartId[1] = item.Value; + break; + case "Path_03_PartId": + istPathPartId[2] = item.Value; + break; + case "Path_04_PartId": + istPathPartId[3] = item.Value; + break; + case "Path_05_PartId": + istPathPartId[4] = item.Value; + break; + case "Path_06_PartId": + istPathPartId[5] = item.Value; + break; + default: + break; + } + } } /// /// verifica gli status attivi diff --git a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs index 7247683..b09a67f 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs @@ -10,144 +10,6 @@ namespace MTC_Adapter { public class AdapterOsai : AdapterGeneric { - /// - /// Oggetto MAIN x connessione OSAI - /// - protected OSAI OSAI_ref; - - /// - /// wrapper chiamata lettura/scrittura OSAI x BYTE... - /// - /// - /// - /// - /// 0/1 orimo o secondo byte della word... - /// - /// - public bool OsaiMemRW_Byte(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, Int32 memOrderStart, ref byte[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_Byte(bWrite, MemType, memIndex, memOrderStart, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura x WORD... - /// - /// - /// - /// - /// - /// - public bool OsaiMemRW_Word(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref ushort[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_Word(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura x DOUBLE-WORD... - /// - /// - /// - /// - /// - /// - public bool OsaiMemRW_DWord(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref uint[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_DWord(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura x Short... - /// - /// - /// - /// - /// - /// - public bool OsaiMemRW_Short(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref short[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_Short(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura x INT... - /// - /// - /// - /// - /// - /// - public bool OsaiMemRW_Integer(bool bWrite, OSAI.MemTypeWord MemType, Int32 memIndex, ref int[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_Integer(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura x Double... - /// - /// - /// - /// - /// - /// - public bool OsaiMemRW_Double(bool bWrite, OSAI.MemTypeDouble MemType, Int32 memIndex, ref double[] Value) - { - bool answ = false; - if (OSAI_ref.Connected) - { - try - { - answ = OSAI_ref.O_RW_Double(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } /// /// struttura dati OSAI x dati NC (pag 148) /// @@ -566,6 +428,13 @@ namespace MTC_Adapter /// boolean: se si debba tornare ACK public override void refreshAlarmState(StFlag32 Alarm2Refresh, bool giveAck) { + // indici memorie allarmi: strobe ed ACK + int memIndex = 19036; + int memIndexAck = 19018; + + + + // log bitmap se verboso attivo + ho allarmi da refreshare if ((Alarm2Refresh != StFlag32.NONE) && utils.CRB("verbose")) { @@ -580,8 +449,6 @@ namespace MTC_Adapter inizio = DateTime.Now; uint[] MemBlock; - // primo blocco memoria allarmi - int memIndex = 19036; // controllo, SE devo leggere tutto uso un unico accesso ai 128byte, altrimenti leggo a blocchi di 32bit... if (Alarm2Refresh == (StFlag32)unchecked((int)UInt32.MaxValue)) { @@ -639,11 +506,9 @@ namespace MTC_Adapter // scrivo ack se richiesto!!! if (giveAck) { - // mi preparo a scrivere ACK - memIndex = 19018; // scrivo update ad ack!!! inizio = DateTime.Now; - OsaiMemRW_Byte(W, OSAI.MemTypeWord.MW_CODE, memIndex, 0, ref retACK_DW0); + OsaiMemRW_Byte(W, OSAI.MemTypeWord.MW_CODE, memIndexAck, 0, ref retACK_DW0); if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", retACK_DW0.Length), DateTime.Now.Subtract(inizio).Ticks); ackReturned = true; } diff --git a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs index 3187ea5..710a47d 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs @@ -10,108 +10,6 @@ namespace MTC_Adapter { public class AdapterSiemens : AdapterGeneric { - /// - /// Oggetto MAIN x connessione SIEMENS - /// - protected SIEMENS SIEMENS_ref; - - /// - /// Area di memoria base x MTConnect con SIEMENS (DB1499) - /// - protected int baseMemDb = 1499; - /// - /// Area di memoria base x dati UTENSILE (DB253) - /// - protected int baseMemUT = 253; - /// - /// Area di memoria base x dati TESTE (DB254) - /// - protected int baseMemUO = 254; - - /// - /// wrapper chiamata lettura/scrittura SINGOLO BYTE... - /// - /// - /// main address (1499/1500) - /// - /// - /// - public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte Value) - { - bool answ = false; - // chiamo la versione multibyte... - byte[] ValArray = new byte[1]; - SIEMENSMemRW_Byte(bWrite, MemType, memIndex, ref ValArray); - Value = ValArray[0]; - return answ; - } - /// - /// wrapper chiamata lettura/scrittura MULTI BYTE... - /// - /// - /// main address (1499/1500) - /// - /// - /// - public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte[] Value) - { - bool answ = false; - if (SIEMENS_ref.Connected) - { - try - { - answ = SIEMENS_ref.S_RW_Byte(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura MULTI Word... - /// - /// - /// main address (1499/1500) - /// - /// - /// - public bool SIEMENSMemRW_Word(bool bWrite, int MemType, Int32 memIndex, ref ushort[] Value) - { - bool answ = false; - if (SIEMENS_ref.Connected) - { - try - { - answ = SIEMENS_ref.S_RW_Word(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// - /// wrapper chiamata lettura/scrittura MULTI DWord... - /// - /// - /// main address (1499/1500) - /// - /// - /// - public bool SIEMENSMemRW_DWord(bool bWrite, int MemType, Int32 memIndex, ref uint[] Value) - { - bool answ = false; - if (SIEMENS_ref.Connected) - { - try - { - answ = SIEMENS_ref.S_RW_DWord(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - return answ; - } - /// /// struttura dati SIEMENS x ALL DYN DATA /// C:\Users\samuele\Documents\FOCAS A02B-0207-K737_04.20\Document\SpecE\Position\cnc_rddynamic2.htm @@ -548,7 +446,7 @@ namespace MTC_Adapter try { // aggiorno vettore allarmi x intero! size del vettore di destinazione (in byte!!!!) - Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length); + Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, AlarmFlags.Length); } catch (Exception exc) {