297 lines
11 KiB
C#
297 lines
11 KiB
C#
using EgwProxy.Icoel;
|
|
using EgwProxy.Icoel.SizerService;
|
|
using IOB_UT_NEXT;
|
|
using MapoSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation;
|
|
|
|
namespace IOB_WIN_NEXT
|
|
{
|
|
/// <summary>
|
|
/// Adapter specializzato per ICOEL e le chiamate tramite WS Soap al Sizer, con libreria EgwProxy.Icoel
|
|
/// </summary>
|
|
public class IobIcoelSoap : IobGeneric
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Costruttore dell'IOB Icoel SOAP
|
|
/// </summary>
|
|
/// <param name="caller">AdapterForm chiamante</param>
|
|
/// <param name="IOBConf">Configurazione IOB per avvio</param>
|
|
public IobIcoelSoap(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
/* --------------------------------------
|
|
* todo's
|
|
* --------------------------------------
|
|
* - init obj comunicazione da conf e nuget
|
|
* - test comunicazione
|
|
* - estensione IOB come OPT_PAR di OVERRIDE (x inviare dati di un unico iOB da più IOB programs)
|
|
* - gestione processCustomTaskLF
|
|
* - x lettura dei 2 batch correnti (sx/dx)
|
|
* - calcolo batch in corso/chiusi da date inizio/fine
|
|
* - trasmettere a MP/IO risultato valutazioni
|
|
* - gestione executeTasks
|
|
* - task di invio batch configurato in coda
|
|
* - task di recupero info anagrafiche (grower, variety, layout,...)
|
|
* - contapezzi (SE ha senso con sizer oppure saltare)
|
|
*/
|
|
|
|
IcoelSizer = new Connector(IOBConf.cncIpAddr, IOBConf.cncPort);
|
|
lastPING = DateTime.Now.AddHours(-1);
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Implementazione custom esecuzione task specifici
|
|
/// </summary>
|
|
/// <param name="task2exe"></param>
|
|
/// <returns></returns>
|
|
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
|
|
{
|
|
/*---------------------------------------
|
|
* fixme todo fare !!!
|
|
* gestione execute task SPECIFICI x il sizer:
|
|
* - recupero anagrafice variety/layout (attivi)
|
|
* - recupero grower
|
|
* - invio batch da accodare
|
|
* - recupero dati da sizer (OVE disponibili)
|
|
* - recupero batch corrente (modalità force/resync?)
|
|
*
|
|
*---------------------------------------*/
|
|
|
|
return base.executeTasks(task2exe);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dizionario parametri correnti
|
|
/// </summary>
|
|
protected Dictionary<string, double> perfParamDict { get; set; } = new Dictionary<string, double>();
|
|
|
|
/// <summary>
|
|
/// Recupero dati dinamici...
|
|
/// </summary>
|
|
public override Dictionary<string, string> getDynData()
|
|
{
|
|
// valore non presente in vers default... se gestito fare override
|
|
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
|
// recupero da libreria il dizionario dei performance parameters...
|
|
perfParamDict = IcoelSizer.GetPerfMeters();
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetPerfMeters()");
|
|
foreach (var item in perfParamDict)
|
|
{
|
|
saveValue(ref outVal, item.Value, item.Key);
|
|
}
|
|
|
|
lastReadPLC = DateTime.Now;
|
|
return outVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua processing CUSTOM x Icoel:
|
|
/// - recupera elenco batch delle 2 linee
|
|
/// - invia al sistema
|
|
/// </summary>
|
|
public override void processCustomTaskLF()
|
|
{
|
|
lgInfo($"Richiesto processCustomTaskLF");
|
|
var currBatch = IcoelSizer.GetCurrentBatch();
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetCurrentBatch()");
|
|
if (currBatch != null)
|
|
{
|
|
// verifico se i batch siano variati... e quindi da inviare...
|
|
bool doSend = (currBatchList == null || currBatchList.Count == 0);
|
|
if (currBatch.Count > 0 && !doSend)
|
|
{
|
|
foreach (var item in currBatch)
|
|
{
|
|
// se variato ID è cambiato
|
|
doSend = doSend || (currBatchList[item.Key].Id != item.Value.Id);
|
|
}
|
|
}
|
|
// se devo inviare impacchetto dati
|
|
if (doSend)
|
|
{
|
|
accodaRawData(rawTransfType.IcoelBatch, currBatch);
|
|
currBatchList = currBatch;
|
|
}
|
|
}
|
|
|
|
lastReadPLC = DateTime.Now;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua lettura semafori principale <paramref name="currDispData">Parametri da
|
|
/// aggiornare x display in form</paramref>
|
|
/// </summary>
|
|
public override void readSemafori(ref newDisplayData currDispData)
|
|
{
|
|
if (connectionOk)
|
|
{
|
|
B_input = 1;
|
|
currDispData.semIn = Semaforo.SV;
|
|
if (currBatchList == null)
|
|
{
|
|
// se nullo --> provo a leggere!
|
|
var currBatch = IcoelSizer.GetCurrentBatch();
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetCurrentBatch()");
|
|
if (currBatch != null)
|
|
{
|
|
currBatchList = currBatch;
|
|
accodaRawData(rawTransfType.IcoelBatch, currBatch);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//se i perf parameters mi danno valire > 0 x quantità frutta...
|
|
if (perfParamDict != null && perfParamDict.Count > 0)
|
|
{
|
|
if (perfParamDict.ContainsKey("VelFruttiMinuto"))
|
|
{
|
|
if (perfParamDict["VelFruttiMinuto"] > 0)
|
|
{
|
|
B_input += (1 << 1);
|
|
}
|
|
// metto manuale
|
|
else
|
|
{
|
|
B_input += (1 << 4);
|
|
}
|
|
}
|
|
}
|
|
|
|
//usato altro criterio x stato verde da vel frutti minuto
|
|
#if false
|
|
// se ho batch NON chiusi (data = minValue) allora lavora
|
|
if (currBatchList[1].EndTime == DateTime.MinValue || currBatchList[1].EndTime == DateTime.MinValue)
|
|
{
|
|
B_input = 3;
|
|
}
|
|
#endif
|
|
}
|
|
// accodo NON emergenza
|
|
B_input += (1 << 7);
|
|
}
|
|
else
|
|
{
|
|
B_input = 0;
|
|
currDispData.semIn = Semaforo.SR;
|
|
}
|
|
}
|
|
|
|
/// <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("IcoelSoap: ConnKO - tryConnect");
|
|
}
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
// se passa il ping faccio il resto...
|
|
if (testPingMachine == IPStatus.Success)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
// ora provo connessione...
|
|
parentForm.commPlcActive = true;
|
|
// recupero elenco batch... se != vuoto -_> connesso!
|
|
var batchList = IcoelSizer.GetCurrentBatch();
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetCurrentBatch()");
|
|
if (batchList != null && batchList.Count > 0)
|
|
{
|
|
lgInfo($"szStatusConnection IcoelSoap, recuperato elenco di {batchList.Count} batch");
|
|
parentForm.commPlcActive = false;
|
|
connectionOk = true;
|
|
}
|
|
// refresh stato connessione!!!
|
|
if (connectionOk)
|
|
{
|
|
if (adpRunning)
|
|
{
|
|
lgInfo("Connessione OK");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile procedere, connessione mancante...");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgFatal($"Errore nella connessione all'adapter IcoelSoap: {szStatusConnection}{Environment.NewLine}{exc}");
|
|
connectionOk = false;
|
|
lgInfo($"Eccezione in TryConnect, Adapter IcoelSoap NON running, pausa di {utils.CRI("waitRecMSec")} msec prima di ulteriori tentativi di riconnessione");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// loggo no risposta ping ...
|
|
connectionOk = false;
|
|
if (verboseLog || periodicLog)
|
|
{
|
|
lgInfo($"Attenzione: IcoelSoap controllo PING fallito per IP {cIobConf.cncIpAddr}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
needRefresh = true;
|
|
}
|
|
}
|
|
|
|
public override void tryDisconnect()
|
|
{
|
|
// registro solo che è disconnesso
|
|
connectionOk = false;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// elenco dei BAtch correntemente caricati x testing variazione
|
|
/// </summary>
|
|
protected Dictionary<int, Batch> currBatchList { get; set; }
|
|
|
|
protected Connector IcoelSizer { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// recupera le variety ed i rispettivi layout e li invia al sistema MP/IO
|
|
/// </summary>
|
|
protected void refreshVarietyData()
|
|
{
|
|
///determina se recuperare SOLO varietà attive o tutte
|
|
bool soloAttive = false;
|
|
var varList = IcoelSizer.GetVarietyList(soloAttive);
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetVarietyList()");
|
|
if (varList != null && varList.Length > 0)
|
|
{
|
|
var varietyData = IcoelSizer.GetLayoutForVarietyList(varList);
|
|
lgTrace("SOAP: effettuata chiamata IcoelSizer.GetLayoutForVarietyList()");
|
|
}
|
|
|
|
lastReadPLC = DateTime.Now;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |