From 62bff0939b7006e60ce2ca178e46661ade482188 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Thu, 31 Oct 2019 19:04:13 +0100 Subject: [PATCH] Modifiche IOB OMRON (da testare read/write) --- IOB-WIN/IobOmron.cs | 390 ++++++++++++++++++-------------------------- Jenkinsfile | 2 +- 2 files changed, 160 insertions(+), 232 deletions(-) diff --git a/IOB-WIN/IobOmron.cs b/IOB-WIN/IobOmron.cs index ea663c8d..e4ca7396 100644 --- a/IOB-WIN/IobOmron.cs +++ b/IOB-WIN/IobOmron.cs @@ -8,41 +8,6 @@ namespace IOB_WIN public class IobOmron : IobGeneric { -#if false - /// - /// Enum segnali status macchina (ByteStatus) come flag - /// - [Flags] - public enum bitStatus - { - NONE = 0, - POWER_ON = 1 << 0, - AUTO = 1 << 1, - RUN = 1 << 2, - ERROR = 1 << 3, - ALARM = 1 << 4, - EMERG_OK = 1 << 5, - DOOR_CLOSED = 1 << 6, - READY_LOAD = 1 << 7 - } - /// - /// Enum segnali macchina ulteriori (ByteSignals) - /// - [Flags] - public enum bitSignals - { - NONE = 0, - TRANSF_AUTO = 1 << 0, - PUNZ_AUTO = 1 << 1, - BARR_TAV_RIPR = 1 << 2, - ARIA_OK = 1 << 3, - CONS_TRANS_OK = 1 << 4, - TAV_A = 1 << 5, - TAV_B = 1 << 6, - RICH_ACCESSO = 1 << 7 - } -#endif - /// /// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO /// @@ -55,22 +20,31 @@ namespace IOB_WIN /// Array delle risposte dal controllo OMRON /// protected System.Collections.ArrayList resDataArray; + /// - /// Variabile STATUS corrente (8bit INT) + /// Array valori letti da memoria CIO /// - protected string cStatus; + protected short[] memReadCIO; /// - /// Variabile SIGNALS corrente (8bit INT) + /// Array valori letti da memoria DM /// - protected string cSignals; + protected short[] memReadDM; /// - /// Num pezzi prelevati + /// Array valori letti da memoria WR /// - protected int numPzPrel; + protected short[] memReadWR; /// - /// Ultimo TC registrato da robot + /// Array valori SCRITTI su memoria CIO /// - protected decimal lastRecTC; + protected short[] memWriteCIO; + /// + /// Array valori SCRITTI su memoria DM + /// + protected short[] memWriteDM; + /// + /// Array valori SCRITTI su memoria WR + /// + protected short[] memWriteWR; /// /// estende l'init della classe base... @@ -228,7 +202,7 @@ namespace IOB_WIN return taskDone; } /// - /// Effettua reset del contapezzi + /// Effettua reset del contapezzi, in questo caso il conteggio dei KG /// /// public override bool resetContapezziCNC() @@ -258,7 +232,7 @@ namespace IOB_WIN return answ; } /// - /// Effettua IMPOSTAZIONE FORZATA del contapezzi + /// Effettua IMPOSTAZIONE FORZATA del contapezzi, in questo caso il conteggio dei KG /// /// public override bool setContapezziCNC(int newPzCount) @@ -288,6 +262,7 @@ namespace IOB_WIN return answ; } +#if false /// /// Imposto connessione /// @@ -299,8 +274,6 @@ namespace IOB_WIN // inizializzo correttamente aree memoria secondo CONF - iniFileName IniFile fIni = new IniFile(cIobConf.iniFileName); - // fix enable prgName - enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", false); // SE è necessario refresh... if (needRefresh) @@ -325,44 +298,9 @@ namespace IOB_WIN needRefresh = false; } parentForm.commPlcActive = false; - // gestione pzCounter -#if false - if (utils.CRB("enableContapezzi")) - { - lgInfo("OMRON: inizio gestione contapezzi"); - try - { - // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area) - if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "") - { - if (getOptPar("PZCOUNT_MODE").StartsWith("STD")) - { - pzCntReload(true); - // refresh associazione Macchina - IOB - sendM2IOB(); - // per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...) - lastCountCNC = contapezzi; - } - else - { - contapezzi = 0; - lgInfo("Contapezzi STD disabilitato: modalità {0}", getOptPar("PZCOUNT_MODE")); - } - } - else - { - contapezzi = 0; - lgInfo("Parametro mancante PZCOUNT_MODE"); - } - } - catch (Exception exc) - { - lgError(exc, "Errore in contapezzi OMRON"); - } - } -#endif } - } + } +#endif /// /// Vera connessione ad OMRON /// @@ -483,106 +421,82 @@ namespace IOB_WIN public override void forceAlarmCheck() { - //base.forceAlarmCheck(); + // controllo tutta la memoria allarmi SE richiesto } - - /// - /// Oggetto per lettura counter pezzi PRELEVATI + // + /// Calcola la conversione da byte --> num decimale --> HEX --> conversione come stringa in INT /// - protected int pzPrelevati + /// + /// + protected int convDHD(short valore) + { + int answ = 0; + string hexVal = valore.ToString("x"); + int.TryParse(hexVal, out answ); + return answ; + } + // + /// Calcola la conversione da INTERO a intero HEX x OMRON + /// + /// + /// + protected short convHD(string hexVal) + { + short answ = 0; + short.TryParse(hexVal, out answ); + return answ; + } + /// + /// Oggetto per lettura PESO rilevato (DM20-21) + /// + protected int pesoRilevato { get { int answ = 0; -#if false - if (OMRON_ref.IsConnected) + try { - resDataArray = OMRON_ref.command("TYPE i_prelevati", 3000); // num pz prelevati --> "0\r\n" - int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ); - } -#endif + short[] valDM; + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out valDM); + // legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa) + // esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1] + answ = convDHD(valDM[0]) + 10000 * convDHD(valDM[1]); + } + catch + { } return answ; } } + /// - /// Oggetto per lettura/scrittura counter pezzi robot + /// Oggetto per lettura (DM22-23) /scrittura (DM26-27) PESO RICHIESTO /// - protected int pzCounter + protected int pesoRichiesto { get { int answ = 0; -#if false - if (OMRON_ref.IsConnected) + try { - resDataArray = OMRON_ref.command("TYPE i_cicli", 3000); // num cicli depositati/fatti --> " 0\r\n" - int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ); - } -#endif + short[] valDM; + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out valDM); + // legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa) + // esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1] + answ = convDHD(valDM[0]) + 10000 * convDHD(valDM[1]); + } + catch + { } return answ; } set { -#if false - if (OMRON_ref.IsConnected) - { - comando = string.Format("i_cicli={0}", value); - // scrivo valore cicli - resDataArray = OMRON_ref.command(comando, 3000); // imposto cicli depositati/fatti --> " 0\r\n" - } -#endif - } - } - /// - /// Restituisce stato macchina nel formato (da sx a dx): - /// B0: POWER_ON - /// B1: AUTO - /// B2: RUN - /// B3: ERROR - /// B4: ALLARME - /// B5: EMERGENZA OK - /// B6: PORTA CHIUSA - /// B7: PRONTO AL LOAD - /// - protected string currBitmapStatus - { - get - { - string answ = ""; -#if false - if (OMRON_ref.IsConnected) - { - resDataArray = OMRON_ref.command("TYPE $status", 3000); // status --> "0|0|1|0|0|1|0|0\r\n" - answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", ""); - } -#endif - return answ; - } - } - /// - /// Restituisce SEGNALI macchina nel formato: - /// B0: Transfer in auto - /// B1: Punzonatrice in AUTO - /// B2: Barriera tavola ripristinata - /// B3: Aria in linea OK - /// B4: Console Transfer in fuori ingombro - /// B5: TAV A - /// B6: TAV B - /// B7: Richiesta accesso attiva - /// - protected string currBitmapSignals - { - get - { - string answ = ""; -#if false - if (OMRON_ref.IsConnected) - { - resDataArray = OMRON_ref.command("TYPE $signal", 3000); // segnali --> "1|0|1|1|1|0|0|0\r\n" - answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", ""); - } -#endif - return answ; + // DA PROVARE!!! + short[] valDM = new short[2]; + int highVal = value / 10000; + int lowVal = value - (highVal * 10000); + valDM[0] = convHD(lowVal.ToString("x")); + valDM[1] = convHD(highVal.ToString("x")); + OMRON_ref.WriteWords(OmronFinsTCP.Net.PlcMemory.DM, 26, 2, valDM); } } @@ -614,33 +528,8 @@ namespace IOB_WIN } } /// - /// Effettua processing del recupero delle OVERRIDE (spindle, feedrate, rapid) + /// Lettura e log valori x debug /// - public override void processOverride() - { - } - /// - /// lettura bit semafori - /// - public override void readSemafori() - { - base.readSemafori(); - if (verboseLog) - { - lgInfo("inizio read semafori"); - } - - parentForm.sIN = Semaforo.SV; - - - // effettuo TUTTE le letture - cStatus = currBitmapStatus; - cSignals = currBitmapSignals; - lastCountCNC = pzCounter; - // decodifica e gestione - decodeToBaseBitmap(); - } - private void readAndLog() { #if false @@ -657,25 +546,22 @@ namespace IOB_WIN #endif - short[] responseCIO; - short[] responseDM; - short[] responseWR; - OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 8, out responseCIO); - OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out responseDM); - OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out responseWR); + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 8, out memReadCIO); + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM); + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR); lgInfo("Effettuata lettura dati CIO"); - foreach (var item in responseCIO) + foreach (var item in memReadCIO) { lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}"); } lgInfo("Effettuata lettura dati DM"); - foreach (var item in responseDM) + foreach (var item in memReadDM) { lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}"); } lgInfo("Effettuata lettura dati WR"); - foreach (var item in responseWR) + foreach (var item in memReadWR) { lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}"); } @@ -700,6 +586,52 @@ namespace IOB_WIN } + /// + /// lettura bit semafori + /// + public override void readSemafori() + { + base.readSemafori(); + if (verboseLog) + { + lgInfo("inizio read semafori"); + } + + parentForm.sIN = Semaforo.SV; + + + // effettuo TUTTE le letture + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 60, out memReadCIO); + //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM); + //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR); + + + lastCountCNC = pesoRilevato; + // decodifica e gestione + decodeToBaseBitmap(); + } + + /// + /// Verifico se abbia ALMENO un errore... + /// + protected bool hasError + { + get + { + bool answ = false; + // controllo primi errori, parto dal primo e poi OR + answ = answ || ((memReadCIO[0] & (1 << 7)) == 1); + answ = answ || ((memReadCIO[1] & (1 << 0)) == 1); + answ = answ || ((memReadCIO[1] & (1 << 1)) == 1); + answ = answ || ((memReadCIO[1] & (1 << 3)) == 1); + answ = answ || (memReadCIO[2] > 0); + answ = answ || ((memReadCIO[3] & (1 << 0)) == 1); + answ = answ || ((memReadCIO[3] & (1 << 1)) == 1); + + return answ; + } + } + /// /// Effettua decodifica aree memoria alla bitmap usata x MAPO /// @@ -707,7 +639,8 @@ namespace IOB_WIN { // init a zero... B_input = 0; -#if false + + /* ----------------------------------------------------- * bitmap MAPO * B0: POWER_ON @@ -715,37 +648,34 @@ namespace IOB_WIN * B2: pzCount * B3: allarme * B4: manuale - * B5: emergenza - * B6: error prog - * B7: auto mode + * B5: carico SILOS + * B6: carico AUTOBOTTE ----------------------------------------------------- */ - // bit 0 (poweron) imposto a 1 SE connected... - B_input = OMRON_ref.IsConnected ? 1 : 0; - // RUN - if (cStatus[2] == '1') + // bit 0 (poweron) imposto a 1 SE pingo... + B_input = testPing == IPStatus.Success ? 1 : 0; + + + // RUN se CIO_bit 0.01 è 1 + if ((memReadCIO[0] & (1 << 1)) == 1) { B_input += (1 << 1); } - // ERROR prog/macchina - if (cStatus[3] == '1') - { - B_input += (1 << 6); - } - // allarme - if (cStatus[4] == '1') + // ERROR generale (CORREGGERE!) + if (hasError) { B_input += (1 << 3); } - // Automatico (porta chiusa) - if (cStatus[6] == '1' || cStatus[1] == '1') - { - B_input += (1 << 4); - } - // NON EMERGENZA (1=armed, 0=triggered) - if (cStatus[5] == '0') + + // carico SILOS + if ((memReadCIO[55] & (1 << 2)) == 1) { B_input += (1 << 5); } + // carico AUTOBOTTE + if ((memReadCIO[55] & (1 << 2)) == 1) + { + B_input += (1 << 6); + } // process ODL e contapezzi string currODL = ""; @@ -761,7 +691,8 @@ namespace IOB_WIN } } else - { // se variato o scaduto timeout log... + { + // se variato o scaduto timeout log... if (periodicLog || (currIdxODL.ToString() != currODL)) { lgInfo(string.Format("OMRON | Lettura ODL, currODL: {0} --> currIdxODL prec: {1}", currODL, currIdxODL)); @@ -778,6 +709,7 @@ namespace IOB_WIN lastWarnODL = DateTime.Now; } } +#if false if (currODL != null && currODL != "" && currODL != "0") { // ora processo il contapezzi... @@ -821,14 +753,14 @@ namespace IOB_WIN // resetto timer... lastPzCountSend = DateTime.Now; } - } + } +#endif // log opzionale! if (verboseLog) { lgInfo(string.Format("Trasformazione B_input: {0}", B_input)); - } -#endif + } } /// @@ -838,16 +770,12 @@ namespace IOB_WIN { // valore non presente in vers default... se gestito fare override Dictionary outVal = new Dictionary(); - outVal.Add("NUM_PZ_PREL", pzPrelevati.ToString()); -#if false - outVal.Add("NUM_PZ_LAV", pzCounter.ToString()); - outVal.Add("CURR_SIGNALS", currBitmapSignals.ToString()); -#endif + outVal.Add("PESO_RILEVATO", pesoRilevato.ToString()); + outVal.Add("PESO_RICHIESTO", pesoRichiesto.ToString()); - // leggo e scrivo LOG... + // leggo e scrivo LOG... !!!FIXME!!! poi togliere readAndLog(); - return outVal; } diff --git a/Jenkinsfile b/Jenkinsfile index 4a0ff149..08d27e8a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=483']) { + withEnv(['NEXT_BUILD_NUMBER=484']) { // env.versionNumber = VersionNumber(versionNumberString : '2.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'