8bb0f158b5
- proj di base con le 2 form da ereditare - progetto globale che contiene TUTTI gli adapter (pronto a venire spezzettato - gettate le basi x "portare fuori" i vari componenti oppure fare compilazione condizonale
196 lines
8.1 KiB
C#
196 lines
8.1 KiB
C#
using IOB_UT_NEXT;
|
|
using MapoSDK;
|
|
using Newtonsoft.Json;
|
|
using Opc.Ua;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using static IOB_UT_NEXT.CustomObj;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace IOB_WIN_NEXT.IobOpc
|
|
{
|
|
public class OpcUaKpwRama : OpcUaKpw
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Estende l'init della classe base, impiegando il pacchetto Nuget OPC-UA foundation con la
|
|
/// gestione specifica per adapter KepWare OPC-UA (es RAMA RED by Unitech x TFT)
|
|
/// https://github.com/OPCFoundation/UA-.NETStandard
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="IOBConf"></param>
|
|
public OpcUaKpwRama(AdapterFormNext caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
lgInfo("Init OpcUa Kepware x RAMA");
|
|
// inizializzo classe base...
|
|
if (!string.IsNullOrEmpty(getOptPar("CHANGE_ODL_MODE")))
|
|
{
|
|
CHANGE_ODL_MODE = getOptPar("CHANGE_ODL_MODE");
|
|
}
|
|
// gestione restart OpcUa client...
|
|
if (!string.IsNullOrEmpty(getOptPar("ENABLE_CLI_RESTART")))
|
|
{
|
|
bool.TryParse(getOptPar("ENABLE_CLI_RESTART"), out enableCliRestart);
|
|
}
|
|
// init lastCurrentMaxElapsed
|
|
if (!string.IsNullOrEmpty(getOptPar("MAX_ELAPSED_TIME_SEC")))
|
|
{
|
|
int.TryParse(getOptPar("MAX_ELAPSED_TIME_SEC"), out lastCurrentMaxElapsed);
|
|
}
|
|
sendKeyRichiesta = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua sync dati inviando RICETTA
|
|
/// </summary>
|
|
protected override void processDataSync()
|
|
{
|
|
lgInfo("--------------------------------------------");
|
|
lgInfo($"executeTasks --> syncDbData --> processDataSync");
|
|
lgInfo("--------------------------------------------");
|
|
// effettua sync recuperando dati ed effettuando scrittura su kepware
|
|
var taskGet = iobGetSendDossierKepware();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero dati da server x invio dati ricetta a KepWare (Ex RAMA x TFT)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool iobGetSendDossierKepware()
|
|
{
|
|
bool answ;
|
|
|
|
lg.Info("iobGetSendDossier: Inizio scrittura dati a KepWare");
|
|
/*-----------------------------------------
|
|
* STEPS processo:
|
|
* - recupero ARTICOLI (solo quelli dei PODL attivi)
|
|
* - recupero PODL (tutti)
|
|
* - recupero elenco DOSSIER last x macchina (legato ai PODL attivi)
|
|
* - prendo SOLO PODL attivi, e prendo il + vecchio
|
|
* - se trovo dossier x articolo del PODL + vecchio (e dovrebbe...) procedo
|
|
* - uso Dictionary dei memWrite x tradurre l'elenco fluxLog in nuovi valori
|
|
* - preparo il set di valori da scrivere con traduzione
|
|
* - invio scritture
|
|
* - aggiungo info articolo (+ ODL...)
|
|
* - aggiungo il valore di "scrittura effettuata"
|
|
*----------------------------------------- */
|
|
|
|
bool okArt = false;
|
|
bool okDoss = false;
|
|
bool okPodl = false;
|
|
List<AnagArticoli> listaArt = new List<AnagArticoli>();
|
|
List<PODLModel> listaPODL = new List<PODLModel>();
|
|
List<DossiersModel> listaDoss = new List<DossiersModel>();
|
|
// recupera dati da server tramite chiamate REST a MP/IO/IOB...
|
|
var rawListArt = callUrl(urlGetCurrArt, false);
|
|
var rawListDOSS = callUrl(urlGetCurrDOSS, false);
|
|
// fixme todo verificare se usare urlGetActPODL
|
|
var rawListPODL = callUrl(urlGetNextPODL, false);
|
|
if (!string.IsNullOrEmpty(rawListArt))
|
|
{
|
|
try
|
|
{
|
|
listaArt = JsonConvert.DeserializeObject<List<AnagArticoli>>(rawListArt);
|
|
okArt = listaArt.Count > 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error($"Errore: chiamata elenco ART ha restituito errore{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lg.Error($"Errore: chiamata elenco ART ({urlGetCurrArt}) ha restituito valore vuoto");
|
|
}
|
|
if (!string.IsNullOrEmpty(rawListDOSS))
|
|
{
|
|
try
|
|
{
|
|
listaDoss = JsonConvert.DeserializeObject<List<DossiersModel>>(rawListDOSS);
|
|
okDoss = listaDoss.Count > 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error($"Errore: chiamata elenco DOSSIER ha restituito errore{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lg.Error($"Errore: chiamata elenco DOSSIER ({urlGetCurrDOSS}) ha restituito valore vuoto");
|
|
}
|
|
if (!string.IsNullOrEmpty(rawListPODL))
|
|
{
|
|
try
|
|
{
|
|
listaPODL = JsonConvert.DeserializeObject<List<PODLModel>>(rawListPODL);
|
|
okPodl = listaPODL.Count > 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error($"Errore: chiamata elenco DOSSIER ha restituito errore{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lg.Error($"Errore: chiamata elenco PODL ({urlGetNextPODL}) ha restituito valore vuoto");
|
|
}
|
|
|
|
answ = okArt && okPodl && okDoss;
|
|
if (answ)
|
|
{
|
|
// verifico i PODL attivi...
|
|
var listPodlAct = listaPODL.Where(x => x.Attivabile).OrderBy(x => x.InsertDate).ToList();
|
|
if (listPodlAct.Count > 0)
|
|
{
|
|
string codArt = listPodlAct.FirstOrDefault().CodArticolo;
|
|
// verifico di avere il dossier e l'articolo x questo PODL
|
|
var selArt = listaArt.Where(x => x.CodArticolo == codArt).FirstOrDefault();
|
|
var selDoss = listaDoss.Where(x => x.CodArticolo == codArt).FirstOrDefault();
|
|
// prendo il primo e recupero...
|
|
if (selArt != null && selDoss != null)
|
|
{
|
|
// recupero il resultset dei valori FluxLog da caricare
|
|
DossierFluxLogDTO resultSet = JsonConvert.DeserializeObject<DossierFluxLogDTO>(selDoss.Valore);
|
|
List<FluxLog> listFluxLog = resultSet.ODL;
|
|
|
|
// preparo elenco parametri da inviare...
|
|
ListaCalcParams = new List<objItem>();
|
|
// per ogni valore ricevuto nel dossier --> calcolo parametro da inviare
|
|
foreach (var item in listFluxLog)
|
|
{
|
|
objItem currData = new objItem()
|
|
{
|
|
uid = item.CodFlux,
|
|
reqValue = item.Valore,
|
|
name = item.CodFlux
|
|
};
|
|
// aggiungo!
|
|
ListaCalcParams.Add(currData);
|
|
lgInfo($"Add param: {currData.uid} | reqVal: {currData.reqValue}");
|
|
}
|
|
// aggiungo ultimo parametro di newRecipe...
|
|
objItem newRecipeData = new objItem()
|
|
{
|
|
uid = "NewRecipe",
|
|
reqValue = "true",
|
|
name = "NewRecipe"
|
|
};
|
|
ListaCalcParams.Add(newRecipeData);
|
|
|
|
// effettua chiamata scrittura verso impianto...
|
|
plcWriteParams(ref ListaCalcParams);
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
|
|
#endregion Public Constructors
|
|
|
|
}
|
|
} |