From e8bf265c064019903f70d07af9236d9635a599cd Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 27 Nov 2018 22:04:37 +0100 Subject: [PATCH] Update per vers 308: inclusione SIEMENS FAPE --- IOB-WIN/IobSiemens.cs | 19 +- IOB-WIN/IobSiemensFape.cs | 449 +------------------------------------- Jenkinsfile | 2 +- 3 files changed, 26 insertions(+), 444 deletions(-) diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs index bb2b5274..6ab2976f 100644 --- a/IOB-WIN/IobSiemens.cs +++ b/IOB-WIN/IobSiemens.cs @@ -11,8 +11,15 @@ namespace IOB_WIN { public class IobSiemens : IobGeneric { - //APPUNTI x funzionare - // proteione: meccanismi di collegamento / consenti put/get + /* -------------------------------------------------------------------------------- + * Controlli SIEMENS tramite libreria S7.net + * - basasto su SIEMENS + * - S7 testato vers 300 e 1200 + * - attenzione conf rack/slot x varie serie controlli + * - necessità apertura metodi pu/get + * + * -------------------------------------------------------------------------------- */ + #region area componenti base /// @@ -38,7 +45,7 @@ namespace IOB_WIN /// /// indica se serva refresh parametri e quindi PLC... /// - bool needRefresh = true; + protected bool needRefresh = true; /// /// Oggetto cronometro x test vari... /// @@ -198,7 +205,7 @@ namespace IOB_WIN /// Test connessione CNC /// /// - private bool testCncConn() + protected bool testCncConn() { bool answ = false; IPStatus pingStatus = testPing(); @@ -240,7 +247,7 @@ namespace IOB_WIN /// test ping all'indirizzo impostato nei parametri /// /// - private IPStatus testPing() + protected IPStatus testPing() { IPStatus answ = IPStatus.Unknown; ; IPAddress address; @@ -256,7 +263,7 @@ namespace IOB_WIN /// /// Imposto parametri PLC /// - private void setParamPlc() + protected virtual void setParamPlc() { // Creo oggetto connessione NC parentForm.commPlcActive = true; diff --git a/IOB-WIN/IobSiemensFape.cs b/IOB-WIN/IobSiemensFape.cs index bc27aab0..4994e42f 100644 --- a/IOB-WIN/IobSiemensFape.cs +++ b/IOB-WIN/IobSiemensFape.cs @@ -2,10 +2,7 @@ using S7.Net; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Net; -using System.Net.NetworkInformation; namespace IOB_WIN { @@ -79,163 +76,10 @@ namespace IOB_WIN COMANDO_CARRO_A_DESTRA = 36, INCREMENTO_CONTAPEZZI = 38, CONTROLLO_TIME_OUT_CICLO = 40, - RILANCIO_CICLO_[F42] = 42, + RILANCIO_CICLO_F42 = 42, ATTESA_FINE_CICLO = 45 } - #region area componenti base - - /// - /// Configurazione valori da LEGGERE dal PLC - /// - public otherData[] memMapR; - /// - /// Configurazione valori da SCRIVERE nel PLC - /// - public otherData[] memMapW; - /// - /// Byte dimensione buffer dati memoria (da file map) - /// - public int numByte = 0; - /// - /// Lungh massima stringhe - /// - protected int maxStrChar = 20; - /// - /// Oggetto PLC da ri-utilizzare... - /// - protected Plc currPLC; - /// - /// indica se serva refresh parametri e quindi PLC... - /// - bool needRefresh = true; - /// - /// Oggetto cronometro x test vari... - /// - protected Stopwatch sw = new Stopwatch(); - /// - /// parametri di connessione - /// - protected connParamS7 parametri; - /// - /// Variabile x salvataggio iobConf locale - /// - protected IobConfiguration _IOBConf; - - #endregion - - #region area metodi lettura/Scrittura - - - /// - /// wrapper chiamata LETTURA in blocco MULTI BYTE... - /// - /// - /// - public bool S7ReadBB(ref byte[] Value) - { - bool answ = false; - sw.Restart(); - parentForm.commPlcActive = true; - if (testCncConn()) - { - // decodifico memoria... - memAreaSiemens memoria = new memAreaSiemens(parametri.memAddrRead); - int numByte = parametri.memSizeRead; - Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte); - // copio in value, sennò do errore... - if (memByteRead.Length == Value.Length) - { - Value = memByteRead; - } - else - { - lgError(string.Format("Mismatch dimensione array memoria: passato array di {0} byte, letti da S7 {1} byte", Value.Length, memByteRead.Length)); - } - string titolo = string.Format("READ BLOCK MEM BYTE: {0} --> {1} byte", parametri.memAddrRead, numByte); - if (verboseLog) - { - lgInfo(titolo); - } - - string contenuto = string.Format("Contenuto area memoria aquisita{0}", Environment.NewLine); - string byteVal = ""; - for (int i = 0; i < memByteRead.Length; i++) - { - byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0'); - contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, memByteRead[i], Environment.NewLine); - } - // loggo lettura... - if (verboseLog) - { - lgInfo(contenuto); - } - } - else - { - connectionOk = false; - } - parentForm.commPlcActive = false; - sw.Stop(); - if (utils.CRB("recTime")) - { - TimingData.addResult(currIobConf.codIOB, string.Format("{0}|{1}", parametri.memAddrRead, numByte), sw.ElapsedTicks); - } - - return answ; - } - /// - /// wrapper chiamata SCRITTURA in blocco MULTI BYTE... - /// - /// - /// - public bool S7WriteBB(ref byte[] Value) - { - bool answ = false; - -#if false - sw.Restart(); - if (testCncConn()) - { - // decodifico memoria... - memAddress memoria = new memAddress(txtMemArea.Text); - int numByte = 1; - int.TryParse(txtMemSize.Text, out numByte); - Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte); - titolo = string.Format("READ BLOCK MEM BYTE: {0} --> {1} byte", txtMemArea.Text, numByte); - contenuto = ""; - string byteVal = ""; - for (int i = 0; i < memByteRead.Length; i++) - { - byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0'); - contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, memByteRead[i], Environment.NewLine); - } - showOut(titolo, contenuto); - } - sw.Stop(); - tslRTime.Text = string.Format("{0}", sw.Elapsed); -#endif - - -#if false - if (FANUC_ref.Connected) - { - try - { - parentForm.commPlcActive = true; - answ = FANUC_ref.F_RW_Byte(bWrite, MemType, memIndex, ref Value); - } - catch - { } - } - parentForm.commPlcActive = false; -#endif - return answ; - } - - - #endregion - /// /// Classe base con i metodi x Siemens /// @@ -243,6 +87,7 @@ namespace IOB_WIN /// public IobSiemensFape(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { +#if false // gestione invio ritardato contapezzi pzCountDelay = utils.CRI("pzCountDelay"); lastPzCountSend = DateTime.Now; @@ -262,298 +107,27 @@ namespace IOB_WIN memSizeRead = 0, memSizeWrite = 0 }; - setParamPlc(); + setParamPlc(); +#endif } - /// - /// Test connessione CNC - /// - /// - private bool testCncConn() - { - bool answ = false; - IPStatus pingStatus = testPing(); - // se passa il ping faccio il resto... - if (pingStatus != IPStatus.Success) - { - lgError(string.Format("Errore in testCncConn: reply Status per {0}: {1}", parametri.ipAdrr, pingStatus)); - } - else - { - if (!currPLC.IsConnected) - { - currPLC.Open(); - } - if (!currPLC.IsAvailable) - { - lgError(string.Format("PLC Siemens NON disponibile:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString)); - currPLC.ClearLastError(); - } - else - { - if (!currPLC.IsConnected) - { - lgError(string.Format("PLC Siemens NON connesso:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString)); - currPLC.ClearLastError(); - parentForm.updateComStats("NO connection"); - } - else - { - parentForm.updateComStats("Connection OK"); - answ = true; - } - } - } - return answ; - } - /// - /// test ping all'indirizzo impostato nei parametri - /// - /// - private IPStatus testPing() - { - IPStatus answ = IPStatus.Unknown; ; - IPAddress address; - PingReply reply; - Ping pingSender = new Ping(); - address = IPAddress.Loopback; - IPAddress.TryParse(parametri.ipAdrr, out address); - int pingMsTimeout = parametri.pingMsTimeout; - reply = pingSender.Send(address, pingMsTimeout); - answ = reply.Status; - return answ; - } /// /// Imposto parametri PLC /// - private void setParamPlc() + protected override void setParamPlc() { - // Creo oggetto connessione NC - parentForm.commPlcActive = true; - lgInfo("Start init Adapter SIEMENS all'IP {0} | CPU: {1} | R/S: {2}/{3} | --> IOB {4}", _IOBConf.cncIpAddr, _IOBConf.cpuType, _IOBConf.rack, _IOBConf.slot, _IOBConf.codIOB); - // SE è necessario refresh... - if (needRefresh) - { - lgInfo("Refreshing connection..."); - try - { - parametri.slot = _IOBConf.slot; - parametri.rack = _IOBConf.rack; - parametri.tipoCpu = (CpuType)Enum.Parse(typeof(CpuType), _IOBConf.cpuType); - parametri.ipAdrr = _IOBConf.cncIpAddr; - // leggo file init... - IniFile fIni = new IniFile(_IOBConf.iniFileName); - // ora leggo valori speciali - parametri.memAddrRead = fIni.ReadString("MEMORY", "ADDR_READ", ""); - parametri.memAddrWrite = fIni.ReadString("MEMORY", "ADDR_WRITE", ""); - parametri.memSizeRead = fIni.ReadInteger("MEMORY", "SIZE_READ", 0); - parametri.memSizeWrite = fIni.ReadInteger("MEMORY", "SIZE_WRITE", 0); - // salvo vettori memoria... - RawInput = new byte[parametri.memSizeRead]; - RawOutput = new byte[parametri.memSizeWrite]; - // salvo parametri conn! - lgInfo(string.Format("Parametri memoria: memAddrRead: {0} | memAddrWrite: {1} | memSizeRead: {2} | memSizeWrite: {3}", parametri.memAddrRead, parametri.memAddrWrite, parametri.memSizeRead, parametri.memSizeWrite)); - } - catch (Exception exc) - { - lgError(exc, "Errore in parse parametri da IOBConf"); - } - // ora tento avvio PLC... SE PING OK... - if (testPing() == IPStatus.Success) - { - try - { - currPLC = new Plc(parametri.tipoCpu, parametri.ipAdrr, parametri.rack, parametri.slot); - // disconnetto e connetto... - if (utils.CRB("verbose")) - { - lgInfo("SIEMENS: tryDisconnect"); - } + lgInfo("Start init Adapter SIEMENS versione FAPE"); + base.setParamPlc(); + } - tryDisconnect(); - lgInfo("SIEMENS: tryConnect"); - tryConnect(); - lgInfo("End init Adapter SIEMENS"); - if (utils.CRB("verbose")) - { - lgInfo("S7+ CONNESSIONE AVVENUTA"); - } - } - catch (Exception exc) - { - lgError(exc, "Errore in INIT PLC S7+"); - } - needRefresh = false; - } - parentForm.commPlcActive = false; - // carico conf vettore memoria... - loadMemConf(); - if (utils.CRB("enableContapezzi")) - { - lgInfo("SIEMENS: inizio gestione contapezzi"); - try - { - // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area) - if (currIobConf.optPar.Count > 0 && currIobConf.optPar["PZCOUNT_MODE"] != "") - { - if (currIobConf.optPar["PZCOUNT_MODE"].StartsWith("STD")) - { - pzCntReload(); - // 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}", currIobConf.optPar["PZCOUNT_MODE"]); - } - } - else - { - contapezzi = 0; - lgInfo("Parametro mancante PZCOUNT_MODE"); - } - } - catch (Exception exc) - { - lgError(exc, "Errore in contapezzi SIEMENS"); - } - } - } - } - /// - /// Override disconnessione - /// - public override void tryDisconnect() - { - if (connectionOk) - { - string szStatusConnection = ""; - try - { - currPLC.Close(); - connectionOk = false; - lgInfo(szStatusConnection); - lgInfo("Effettuata disconnessione adapter SIEMENS!"); - } - catch (Exception exc) - { - lgFatal(exc, "Errore nella disconnessione dall'adapter SIEMENS"); - } - } - else - { - lgError("IMPOSSIBILE effettuare disconnessione SIEMENS: Connessione non disponibile..."); - } - } - /// - /// Override connessione - /// - public override void tryConnect() - { - if (!connectionOk) - { - // controllo che il ping sia stato tentato almeno pingTestSec fa... - if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec")) - { - if (verboseLog || periodicLog) - { - lgInfo("ConnKO - tryConnect"); - } - // in primis salvo data ping... - lastPING = DateTime.Now; - // se passa il ping faccio il resto... - if (testPing() == IPStatus.Success) - { - string szStatusConnection = ""; - try - { - // ora provo connessione... - parentForm.commPlcActive = true; - currPLC.Open(); - parentForm.commPlcActive = false; - lgInfo("szStatusConnection: " + szStatusConnection); - connectionOk = true; - // refresh stato allarmi!!! - if (connectionOk) - { - if (adpRunning) - { - // carico status allarmi (completo) - lgInfo("Inizio refresh completo stato allarmi..."); - forceAlarmCheck(); - lgInfo("Completato refresh completo stato allarmi!"); - } - else - { - lgInfo("Connessione OK"); - } - } - else - { - lgError("Impossibile procedere, connessione mancante..."); - } - } - catch (Exception exc) - { - lgFatal(string.Format("Errore nella connessione all'adapter SIEMENS: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc)); - connectionOk = false; - lgInfo(string.Format("Eccezione in TryConnect, Adapter SIEMENS NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec"))); - } - } - else - { - // loggo no risposta ping ... - connectionOk = false; - if (verboseLog || periodicLog) - { - lgInfo(string.Format("Attenzione: SIEMENS controllo PING fallito per IP {0}", currIobConf.cncIpAddr)); - } - } - } - } - // se non è ancora connesso faccio procesisng memoria caso disconnesso... - if (!connectionOk) - { - // processo semafori ed invio... - processMemoryDiscon(); - } - } - /// - /// Caricamento conf memoria DB del SIEMENS - /// - private void loadMemConf() - { - // carico conf memoria - loadConfFile(ref memMapR, filePath("MMapR"), 1, ref numByte); - loadConfFile(ref memMapW, filePath("MMapW"), 1, ref numByte); - } - /// - /// Restituisce path completo file da chaive configurazione - /// - /// chaive conf x file richiesto - /// - protected string filePath(string keyFile) - { - string answ = ""; - try - { - answ = string.Format(@"{0}\{1}", utils.confDir, utils.CRS(keyFile)); - } - catch (Exception exc) - { - lgError(exc, "Eccezione in recupero filePath"); - } - return answ; - } /// /// Effettua vero processing contapezzi /// public override void processContapezzi() { + // process contapezzi FAPE... +#if false if (utils.CRB("enableContapezzi")) { try @@ -614,7 +188,8 @@ namespace IOB_WIN { lgError(exc, "Errore in contapezzi SIEMENS"); } - } + } +#endif } #region da completare diff --git a/Jenkinsfile b/Jenkinsfile index e29860ad..383baf04 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=307']) { + withEnv(['NEXT_BUILD_NUMBER=308']) { // env.versionNumber = VersionNumber(versionNumberString : '1.18.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '1.18.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'