From 9d121ede87a3bf85274b73ce6f5cdd0d2adf67f1 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Mon, 29 Jan 2018 12:22:19 +0100 Subject: [PATCH] ancora integrazione S7+ --- IOB-UT/baseUtils.cs | 6 +- IOB-WIN/AdapterForm.cs | 7 ++ IOB-WIN/DATA/CONF/3003.ini | 2 +- IOB-WIN/DATA/CONF/3004.ini | 10 +- IOB-WIN/DATA/CONF/MAIN.ini | 2 +- IOB-WIN/IobConfiguration.cs | 15 +++ IOB-WIN/IobSiemensTorri.cs | 221 ++++++++++++++++++++++++++++++++++++ 7 files changed, 256 insertions(+), 7 deletions(-) diff --git a/IOB-UT/baseUtils.cs b/IOB-UT/baseUtils.cs index bc2f0edd..6d02587d 100644 --- a/IOB-UT/baseUtils.cs +++ b/IOB-UT/baseUtils.cs @@ -673,7 +673,11 @@ namespace IOB_UT /// /// Adapter SIEMENS /// - SIEMENS + SIEMENS, + /// + /// Adapter SIEMENS, interfaccia versione Torri + /// + SIEMENS_TORRI } public enum gatherCycle diff --git a/IOB-WIN/AdapterForm.cs b/IOB-WIN/AdapterForm.cs index 70597046..a46329a7 100644 --- a/IOB-WIN/AdapterForm.cs +++ b/IOB-WIN/AdapterForm.cs @@ -445,6 +445,9 @@ namespace IOB_WIN codIOB = CurrIOB, // fIni.ReadString("IOB", "IDXMACC", "0"), cncIpAddr = fIni.ReadString("CNC", "IP", "::1"), cncPort = fIni.ReadString("CNC", "PORT", "0"), + cpuType = fIni.ReadString("CNC", "CPUTYPE", ""), + rack = (short)fIni.ReadInteger("CNC", "RACK", 0), + slot = (short)fIni.ReadInteger("CNC", "SLOT", 0), serverData = new serverMapo(fIni.ReadString("SERVER", "MPIP", "::1"), fIni.ReadString("SERVER", "MPURL", "/"), fIni.ReadString("SERVER", "CMDBASE", "/"), fIni.ReadString("SERVER", "CMDFLOG", "/"), fIni.ReadString("SERVER", "CMDALIVE", "/"), fIni.ReadString("SERVER", "CMDENABLED", "/"), fIni.ReadString("SERVER", "CMDREBO", "/")), MAX_COUNTER_BLINK = Convert.ToInt32(fIni.ReadString("BLINK", "MAX_COUNTER_BLINK", "1")), BLINK_FILT = Convert.ToInt32(fIni.ReadString("BLINK", "BLINK_FILT", "0")) @@ -586,6 +589,10 @@ namespace IOB_WIN iobObj = new IobSiemens(this, IOBConf); start.Enabled = true; break; + case tipoAdapter.SIEMENS_TORRI: + iobObj = new IobSiemensTorri(this, IOBConf); + start.Enabled = true; + break; case tipoAdapter.ND: default: iobObj = new IobDemo(this, IOBConf); diff --git a/IOB-WIN/DATA/CONF/3003.ini b/IOB-WIN/DATA/CONF/3003.ini index f0a3a3e5..1e3589a9 100644 --- a/IOB-WIN/DATA/CONF/3003.ini +++ b/IOB-WIN/DATA/CONF/3003.ini @@ -4,7 +4,7 @@ CNCTYPE=FANUC ;IDXMACC=3003 [CNC] -; TEST TORNOS! +; CMZ IP=192.168.1.82 PORT=8193 diff --git a/IOB-WIN/DATA/CONF/3004.ini b/IOB-WIN/DATA/CONF/3004.ini index 9ea1ef1c..c55a5e2f 100644 --- a/IOB-WIN/DATA/CONF/3004.ini +++ b/IOB-WIN/DATA/CONF/3004.ini @@ -1,12 +1,14 @@ ;Configurazione IOB-WIN [IOB] -CNCTYPE=FANUC +CNCTYPE=SIEMENS_TORRI ;IDXMACC=3004 [CNC] -; TEST TORNOS! -IP=192.168.1.83 -PORT=8193 +; Siemens Torri (Vaumard) +IP=192.168.1.208 +CPUTYPE=S7300 +RACK=0 +SLOT=2 [SERVER] MPIP=http://10.74.82.219 diff --git a/IOB-WIN/DATA/CONF/MAIN.ini b/IOB-WIN/DATA/CONF/MAIN.ini index 2ceb2629..333d953a 100644 --- a/IOB-WIN/DATA/CONF/MAIN.ini +++ b/IOB-WIN/DATA/CONF/MAIN.ini @@ -9,5 +9,5 @@ MPURL=/MP/IO CMDREBO=/sendReboot.aspx?IP= [IOB] -STARTLIST=3000,3001,3000,3001 +STARTLIST=3001,3004,3000,3000 ;STARTLIST=3001,3002,3003,3004,3005 \ No newline at end of file diff --git a/IOB-WIN/IobConfiguration.cs b/IOB-WIN/IobConfiguration.cs index 34b1f4ad..90c7773f 100644 --- a/IOB-WIN/IobConfiguration.cs +++ b/IOB-WIN/IobConfiguration.cs @@ -37,6 +37,18 @@ namespace IOB_WIN /// public string cncPort { get; set; } /// + /// TipoCPU (es: Siemens) + /// + public string cpuType { get; set; } + /// + /// Rack (Siemens S7) + /// + public short rack { get; set; } + /// + /// Slot (Siemens S7) + /// + public short slot { get; set; } + /// /// Dati di conf del server MoonPro cui comunicare /// public serverMapo serverData { get; set; } @@ -65,6 +77,9 @@ namespace IOB_WIN versIOB = "0"; cncIpAddr = "127.0.0.1"; cncPort = "0"; + cpuType = ""; + rack = 0; + slot = 0; tipoIob = tipoAdapter.DEMO; serverData = new serverMapo("127.0.0.1", "/", "/IOB/input/", "/IOB/flog/", "/IOB", "/IOB/enabled/", "/sendReboot.aspx?idxMacchina="); MAX_COUNTER_BLINK = 10; diff --git a/IOB-WIN/IobSiemensTorri.cs b/IOB-WIN/IobSiemensTorri.cs index 5da2927d..04c63842 100644 --- a/IOB-WIN/IobSiemensTorri.cs +++ b/IOB-WIN/IobSiemensTorri.cs @@ -4,11 +4,53 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using IOB_UT; +using S7.Net; +using System.Net.NetworkInformation; +using System.Net; +using NLog; +using System.Diagnostics; namespace IOB_WIN { public class IobSiemensTorri : IobGeneric { + /// + /// 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 connParam parametri; + /// + /// Variabile x salvataggio iobConf locale + /// + protected IobConfiguration _IOBConf; + /// /// estende l'init della classe base con i metodi x Siemens specifici x Torri /// @@ -16,6 +58,185 @@ namespace IOB_WIN /// public IobSiemensTorri(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { + _IOBConf = IOBConf; + // inizializzo parametri... + parametri = new connParam() + { + ipAdrr = "127.0.0.1", + tipoCpu = CpuType.S7200, + slot = 0, + rack = 0 + }; + setParamPlc(); + } + /// + /// 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); + reply = pingSender.Send(address, 100); + answ = reply.Status; + return answ; + } + /// + /// Imposto parametri PLC + /// + private void setParamPlc() + { + // Creo oggetto connessione NC + parentForm.commPlcActive = true; + lg.Info("Start init Adapter SISMENS TORRI 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) + { + lg.Info("Refreshing connection..."); + try + { + parametri.slot = _IOBConf.slot; + parametri.rack = _IOBConf.rack; + parametri.tipoCpu = (CpuType)Enum.Parse(typeof(CpuType), _IOBConf.cpuType); + parametri.ipAdrr = _IOBConf.cncIpAddr; + } + catch (Exception exc) + { + lg.Error(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")) lg.Info("SIEMENS-TORRI: tryDisconnect"); + tryDisconnect(); + lg.Info("SIEMENS-TORRI: tryConnect"); + tryConnect(); + lg.Info("End init Adapter SIEMENS-TORRI"); + if (utils.CRB("verbose")) lg.Info("S7+ CONNESSIONE AVVENUTA"); + } + catch (Exception exc) + { + lg.Error(exc, "Errore in INIT PLC S7+"); + } + needRefresh = false; + } + parentForm.commPlcActive = false; + // carico conf vettore memoria... + loadMemConf(); + } + } + /// + /// Override disconnessione + /// + public override void tryDisconnect() + { + if (connectionOk) + { + string szStatusConnection = ""; + try + { + currPLC.Close(); + connectionOk = false; + lg.Info(szStatusConnection); + lg.Info("Effettuata disconnessione adapter SIEMENS-TORRI!"); + } + catch (Exception exc) + { + lg.Fatal(exc, "Errore nella disconnessione dall'adapter SIEMENS-TORRI"); + } + } + else + { + lg.Error("IMPOSSIBILE effettuare disconnessione SIEMENS-TORRI: 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) lg.Info("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; + lg.Info("szStatusConnection: " + szStatusConnection); + connectionOk = true; + // refresh stato allarmi!!! + if (connectionOk) + { + if (adpRunning) + { + // carico status allarmi (completo) + lg.Info("Inizio refresh completo stato allarmi..."); + forceAlarmCheck(); + lg.Info("Completato refresh completo stato allarmi!"); + } + else + { + lg.Info("Connessione OK"); + } + } + else + { + lg.Error("Impossibile procedere, connessione mancante..."); + } + } + catch (Exception exc) + { + lg.Fatal(string.Format("Errore nella connessione all'adapter SIEMENS-TORRI: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc)); + connectionOk = false; + lg.Info(string.Format("Eccezione in TryConnect, Adapter SIEMENS-TORRI 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) lg.Info(string.Format("Attenzione: SIEMENS-TORRI 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() + { +#if false + // carico conf memoria + utils.loadConfFile(ref memMapR, filePath("MMapR"), 1, ref numByte); + utils.loadConfFile(ref memMapW, filePath("MMapW"), 1, ref numByte); +#endif } } }