Update per vers 308: inclusione SIEMENS FAPE
This commit is contained in:
+13
-6
@@ -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
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +45,7 @@ namespace IOB_WIN
|
||||
/// <summary>
|
||||
/// indica se serva refresh parametri e quindi PLC...
|
||||
/// </summary>
|
||||
bool needRefresh = true;
|
||||
protected bool needRefresh = true;
|
||||
/// <summary>
|
||||
/// Oggetto cronometro x test vari...
|
||||
/// </summary>
|
||||
@@ -198,7 +205,7 @@ namespace IOB_WIN
|
||||
/// Test connessione CNC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IPStatus testPing()
|
||||
protected IPStatus testPing()
|
||||
{
|
||||
IPStatus answ = IPStatus.Unknown; ;
|
||||
IPAddress address;
|
||||
@@ -256,7 +263,7 @@ namespace IOB_WIN
|
||||
/// <summary>
|
||||
/// Imposto parametri PLC
|
||||
/// </summary>
|
||||
private void setParamPlc()
|
||||
protected virtual void setParamPlc()
|
||||
{
|
||||
// Creo oggetto connessione NC
|
||||
parentForm.commPlcActive = true;
|
||||
|
||||
+12
-437
@@ -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
|
||||
|
||||
/// <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 connParamS7 parametri;
|
||||
/// <summary>
|
||||
/// Variabile x salvataggio iobConf locale
|
||||
/// </summary>
|
||||
protected IobConfiguration _IOBConf;
|
||||
|
||||
#endregion
|
||||
|
||||
#region area metodi lettura/Scrittura
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// wrapper chiamata LETTURA in blocco MULTI BYTE...
|
||||
/// </summary>
|
||||
/// <param name="MATRICE valori letti"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// wrapper chiamata SCRITTURA in blocco MULTI BYTE...
|
||||
/// </summary>
|
||||
/// <param name="MATRICE valori scritti"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Classe base con i metodi x Siemens
|
||||
/// </summary>
|
||||
@@ -243,6 +87,7 @@ namespace IOB_WIN
|
||||
/// <param name="adpConf"></param>
|
||||
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
|
||||
}
|
||||
/// <summary>
|
||||
/// Test connessione CNC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
/// <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);
|
||||
int pingMsTimeout = parametri.pingMsTimeout;
|
||||
reply = pingSender.Send(address, pingMsTimeout);
|
||||
answ = reply.Status;
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Imposto parametri PLC
|
||||
/// </summary>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Override disconnessione
|
||||
/// </summary>
|
||||
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...");
|
||||
}
|
||||
}
|
||||
/// <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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Caricamento conf memoria DB del SIEMENS
|
||||
/// </summary>
|
||||
private void loadMemConf()
|
||||
{
|
||||
// carico conf memoria
|
||||
loadConfFile(ref memMapR, filePath("MMapR"), 1, ref numByte);
|
||||
loadConfFile(ref memMapW, filePath("MMapW"), 1, ref numByte);
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce path completo file da chaive configurazione
|
||||
/// </summary>
|
||||
/// <param name="keyFile">chaive conf x file richiesto</param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua vero processing contapezzi
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
Vendored
+1
-1
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user