ancora integrazione S7+
This commit is contained in:
+5
-1
@@ -673,7 +673,11 @@ namespace IOB_UT
|
||||
/// <summary>
|
||||
/// Adapter SIEMENS
|
||||
/// </summary>
|
||||
SIEMENS
|
||||
SIEMENS,
|
||||
/// <summary>
|
||||
/// Adapter SIEMENS, interfaccia versione Torri
|
||||
/// </summary>
|
||||
SIEMENS_TORRI
|
||||
}
|
||||
|
||||
public enum gatherCycle
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,7 +4,7 @@ CNCTYPE=FANUC
|
||||
;IDXMACC=3003
|
||||
|
||||
[CNC]
|
||||
; TEST TORNOS!
|
||||
; CMZ
|
||||
IP=192.168.1.82
|
||||
PORT=8193
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -37,6 +37,18 @@ namespace IOB_WIN
|
||||
/// </summary>
|
||||
public string cncPort { get; set; }
|
||||
/// <summary>
|
||||
/// TipoCPU (es: Siemens)
|
||||
/// </summary>
|
||||
public string cpuType { get; set; }
|
||||
/// <summary>
|
||||
/// Rack (Siemens S7)
|
||||
/// </summary>
|
||||
public short rack { get; set; }
|
||||
/// <summary>
|
||||
/// Slot (Siemens S7)
|
||||
/// </summary>
|
||||
public short slot { get; set; }
|
||||
/// <summary>
|
||||
/// Dati di conf del server MoonPro cui comunicare
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Configurazione valori da LEGGERE dal PLC
|
||||
/// </summary>
|
||||
public otherData[] memMapR;
|
||||
/// <summary>
|
||||
/// Configurazione valori da SCRIVERE nel PLC
|
||||
/// </summary>
|
||||
public otherData[] memMapW;
|
||||
/// <summary>
|
||||
/// Byte dimensione buffer dati memoria (da file map)
|
||||
/// </summary>
|
||||
public int numByte = 0;
|
||||
/// <summary>
|
||||
/// Lungh massima stringhe
|
||||
/// </summary>
|
||||
protected int maxStrChar = 20;
|
||||
/// <summary>
|
||||
/// Oggetto PLC da ri-utilizzare...
|
||||
/// </summary>
|
||||
protected Plc currPLC;
|
||||
/// <summary>
|
||||
/// indica se serva refresh parametri e quindi PLC...
|
||||
/// </summary>
|
||||
bool needRefresh = true;
|
||||
/// <summary>
|
||||
/// Oggetto cronometro x test vari...
|
||||
/// </summary>
|
||||
protected Stopwatch sw = new Stopwatch();
|
||||
/// <summary>
|
||||
/// parametri di connessione
|
||||
/// </summary>
|
||||
protected connParam parametri;
|
||||
/// <summary>
|
||||
/// Variabile x salvataggio iobConf locale
|
||||
/// </summary>
|
||||
protected IobConfiguration _IOBConf;
|
||||
|
||||
/// <summary>
|
||||
/// estende l'init della classe base con i metodi x Siemens specifici x Torri
|
||||
/// </summary>
|
||||
@@ -16,6 +58,185 @@ namespace IOB_WIN
|
||||
/// <param name="adpConf"></param>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// test ping all'indirizzo impostato nei parametri
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Imposto parametri PLC
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Override disconnessione
|
||||
/// </summary>
|
||||
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...");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Override connessione
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Caricamento conf memoria DB del SIEMENS
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user