589 lines
20 KiB
C#
589 lines
20 KiB
C#
using MapoSDK;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IOB_UT_NEXT
|
|
{
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri di base x allarmi
|
|
/// </summary>
|
|
public class BaseAlarmConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Elenco dei contatori blink x gestione caso fronte salita/discesa segnale che blinka
|
|
/// </summary>
|
|
public int[] alarmsBlinkCounter { get; set; }
|
|
|
|
/// <summary>
|
|
/// BitMask 16bit (1 = valido, 0 = filtro) degli allarmi silenziati/disabilitati (se
|
|
/// iniziano per ##) come valore da sottrarre x check
|
|
/// </summary>
|
|
public uint[] alarmsMask { get; set; }
|
|
|
|
/// <summary>
|
|
/// Array dei valori allarme correnti
|
|
/// </summary>
|
|
public uint[] alarmsState { get; set; }
|
|
|
|
/// <summary>
|
|
/// valore di partenza x un segnale di blink in caso di fine variazione (fronte discesa)
|
|
/// </summary>
|
|
public int blinkDownVal { get; set; } = 4;
|
|
|
|
/// <summary>
|
|
/// valore di partenza x un segnale di blink in caso di inizio variazione (fronte salita)
|
|
/// </summary>
|
|
public int blinkUpVal { get; set; } = 3;
|
|
|
|
/// <summary>
|
|
/// Descrizione area allarmi
|
|
/// </summary>
|
|
public string description { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Indice nell'area di memoria (da valore iniziale = 0)
|
|
/// </summary>
|
|
public int index { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Nome "assoluto" della posizione nell'area di memoria (anche diverso da indice)
|
|
/// </summary>
|
|
public string memAddr { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Elenco allarmi configurati x la bitmap
|
|
/// </summary>
|
|
public List<string> messages { get; set; } = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Size in byte
|
|
/// </summary>
|
|
public int size { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Tipo di dato
|
|
/// </summary>
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public plcDataType tipoMem { get; set; } = plcDataType.Boolean;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Calcola il filtro da condizione blink (ovvero maschera per valori indicati blinking)
|
|
/// </summary>
|
|
/// <param name="num"></param>
|
|
/// <returns></returns>
|
|
public uint blinkFilter(int num)
|
|
{
|
|
uint answ = 0;
|
|
int idx = 16 * num;
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
if (alarmsBlinkCounter[idx + i] > 0)
|
|
{
|
|
answ += (uint)1 << i;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update dei contatori blink per gestire i segnali alternati sul fronte di salita/discesa
|
|
/// </summary>
|
|
/// <param name="num"></param>
|
|
/// <param name="newStatus"></param>
|
|
public void checkBlinkCounter(int num, uint newStatus)
|
|
{
|
|
// calcola la maschera di variazione da valore precedente
|
|
var variations = newStatus ^ alarmsState[num];
|
|
// ciclo sui 16 bit...
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
// controllo se è variato
|
|
if ((variations & (1 << i)) == (1 << i))
|
|
{
|
|
// se il valore nuovo è 1 --> è in fronte salita
|
|
if ((newStatus & (1 << i)) == (1 << i))
|
|
{
|
|
// cambio SOLO SE il valore blink è zero...
|
|
if (alarmsBlinkCounter[num * 16 + i] == 0)
|
|
{
|
|
alarmsBlinkCounter[num * 16 + i] = blinkUpVal;
|
|
}
|
|
}
|
|
// altrimenti se è fronte discesa
|
|
else
|
|
{
|
|
// cambio SOLO SE il valore blink è zero...
|
|
if (alarmsBlinkCounter[num * 16 + i] == 0)
|
|
{
|
|
alarmsBlinkCounter[num * 16 + i] = blinkDownVal;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// decremento contatori blink
|
|
int idx = 0;
|
|
foreach (var item in alarmsBlinkCounter)
|
|
{
|
|
alarmsBlinkCounter[idx] = item > 0 ? item - 1 : item;
|
|
idx++;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confronta un valore di stato allarme con lo stato precedentemente salvato considerando blink/veto
|
|
/// </summary>
|
|
/// <param name="num">Numero/indice del banco di allarme (uint16)</param>
|
|
/// <param name="newValue">Valore (bitmap) allarmi come uint16</param>
|
|
/// <returns></returns>
|
|
public bool isChanged(int num, uint newValue)
|
|
{
|
|
// per prima cosa controllo valori RAW
|
|
bool answ = !alarmsState[num].Equals(newValue);
|
|
if (answ)
|
|
{
|
|
// controllo valori filtrati con ## (sottraendo BITMASK dai valori di filtro)
|
|
answ = ((alarmsState[num] & alarmsMask[num]) != (newValue & alarmsMask[num]));
|
|
// se fossero ancora differenti controllo ulteriore mask dato il counter dei blink:
|
|
if (answ)
|
|
{
|
|
var blinkFilt = blinkFilter(num);
|
|
answ = ((alarmsState[num] & (alarmsMask[num] & ~blinkFilt)) != (newValue & (alarmsMask[num] & ~blinkFilt)));
|
|
//answ = ((alarmsState[num] & (alarmsMask[num] | blinkFilt)) != (newValue & (alarmsMask[num] | blinkFilt)));
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inizializzazione classe con valori calcolati: attenzione si aspetta banchi da 32 bit...
|
|
/// </summary>
|
|
public void setupData()
|
|
{
|
|
// inizializzo vettore valore allarmi x banco int16
|
|
alarmsState = new uint[size / 2];
|
|
alarmsMask = new uint[size / 2];
|
|
|
|
// una volta inizializzata la classe di base sistemo vettori allarmi disabilitati ed il
|
|
// contatore blink dei fronti di discesa
|
|
alarmsBlinkCounter = new int[messages.Count];
|
|
int idx = 0;
|
|
int bank = 0;
|
|
foreach (var item in messages)
|
|
{
|
|
if (item.StartsWith("##"))
|
|
{
|
|
alarmsBlinkCounter[idx] = -999;
|
|
}
|
|
else
|
|
{
|
|
alarmsBlinkCounter[idx] = 1;
|
|
alarmsMask[bank] += (uint)1 << idx;
|
|
}
|
|
idx++;
|
|
// sistemo bank/indice
|
|
if (idx > 15)
|
|
{
|
|
bank++;
|
|
idx = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta il valore dello status attuale allarme impostando eventuale valore blink x le variazioni
|
|
/// </summary>
|
|
/// <param name="num"></param>
|
|
/// <param name="newStatus"></param>
|
|
public void updStatusVal(int num, uint newStatus)
|
|
{
|
|
// salvo nuovo valore
|
|
alarmsState[num] = newStatus;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri di base x configuraizone estesa (es MTConnect,
|
|
/// OPC-UA, ...)
|
|
/// </summary>
|
|
public class BaseParamConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione LAVORA / Green
|
|
/// </summary>
|
|
public List<diCheckCondition> condWork { get; set; } = new List<diCheckCondition>();
|
|
|
|
/// <summary>
|
|
/// Indica se l'emergenza armata va riportata verso Mapo come bit a TRUE True --> armata
|
|
/// = 1 / triggered = 0 False --> triggered = 1 / armata = 0
|
|
/// </summary>
|
|
public bool emergencyArmedTrue { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Elenco items FILTRATI da invio come dynData --> FluxLog (events o samples)
|
|
/// </summary>
|
|
public List<string> fluxLogVeto { get; set; } = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Array degli elementi di traduzione item
|
|
/// </summary>
|
|
public Dictionary<string, string> itemTranslation { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Nome variabile x EmergencyStop
|
|
/// </summary>
|
|
public string keyEStop { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Nome variabile x pezzi FATTI
|
|
/// </summary>
|
|
public string keyPartCount { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Nome variabile x Codice Articolo
|
|
/// </summary>
|
|
public string keyPartId { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Nome variabile x pezzi RICHIESTI
|
|
/// </summary>
|
|
public string keyPartReq { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Nome variabile x NOME PROGRAMMA
|
|
/// </summary>
|
|
public string keyProgName { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Nome variabile x RunMode
|
|
/// </summary>
|
|
public string keyRunMode { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Dictionary dei nomi da cercare come "endsWith" a cui applicare la soglia indicata
|
|
/// </summary>
|
|
public Dictionary<string, int> paramsEndThresh { get; set; } = new Dictionary<string, int>();
|
|
|
|
/// <summary>
|
|
/// Indica se il ping sia un criterio valido x determinare powerON impianto
|
|
/// </summary>
|
|
public bool pingAsPowerOn { get; set; } = true;
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe per rappresentare oggetti chiave/valore target x controlo condizioni multiple
|
|
/// </summary>
|
|
public class diCheckCondition
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// nome variabile
|
|
/// </summary>
|
|
public string keyName { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// valore target per esito richeisto
|
|
/// </summary>
|
|
public string targetValue { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe per rappresentare una lista di oggetti chiave/valore target x controlo condizioni
|
|
/// multiple + indicazione modalità di controllo (AND/OR/...)
|
|
/// </summary>
|
|
public class diCheckCondSetup
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Elenco condizioni
|
|
/// </summary>
|
|
public List<diCheckCondition> checkList { get; set; } = new List<diCheckCondition>();
|
|
|
|
/// <summary>
|
|
/// Modalità verifica condizioni
|
|
/// </summary>
|
|
public boolCheckMode checkMode { get; set; } = boolCheckMode.AND;
|
|
|
|
/// <summary>
|
|
/// indica se il check vada NEGATO (esempio se cerco la condizione opposta, esempio num
|
|
/// allarmi 0 --> se true NEGO la condizione HO ALLARMI)
|
|
/// </summary>
|
|
public bool negateValue { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe x definizione delle azioni in fase di setup macchina
|
|
/// </summary>
|
|
public class MachineSetupAction
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Indica se vada disabilitato il contapezzi quando la condizione NotEqual sia soddisfatta
|
|
/// </summary>
|
|
public bool DisablePzCountNotEqual { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Parametro target dell'azione
|
|
/// </summary>
|
|
public string TargetParam { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// parametro da impostare SE il check da esito EQUAL
|
|
/// </summary>
|
|
public int TargetValEqual { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// parametro da impostare SE il check da esito NOT EQUAL
|
|
/// </summary>
|
|
public int TargetValNotEqual { get; set; } = 1;
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definizione parametri di setup incrociato...
|
|
/// </summary>
|
|
public class MachineSetupConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Dizionario dei parametri di corrispondenza tra variabili MES e variabili Macchina MES =
|
|
/// scritte dal MES Macchina = scritte da macchina
|
|
/// </summary>
|
|
public Dictionary<string, string> checkParList { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Abilitazione gestione Setup Avanzato (= scrittura)
|
|
/// </summary>
|
|
public bool EnableAdvSetup { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Modalità gestione setup
|
|
/// </summary>
|
|
public MachineSetupMode SetupMode { get; set; } = MachineSetupMode.ND;
|
|
|
|
/// <summary> Dizionario dei parametri da scrivere quando si rilevano differenze tra i
|
|
/// parametri MES/Macchina string (key) --> memoria da scrivere tuple<int isEqual,int
|
|
/// notEqual> --> valori da scrivere quando uguali o diversi </summary>
|
|
public List<MachineSetupAction> writeParAction { get; set; } = new List<MachineSetupAction>();
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// COnfigurazione blocchi x accesso memoria ottimizzato
|
|
/// </summary>
|
|
public class MemBlockConf
|
|
{
|
|
#region Public Properties
|
|
|
|
public Dictionary<int, int> ReadBlocks { get; set; } = new Dictionary<int, int>();
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri specifici MTC da BaseParamConf
|
|
/// </summary>
|
|
public class MtcParamConf : BaseParamConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione PowerOn
|
|
/// </summary>
|
|
public diCheckCondition condPowerOn { get; set; } = new diCheckCondition();
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri specifici OPC-UA da BaseParamConf
|
|
/// </summary>
|
|
public class OpcUaParamConf : BaseParamConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Elenco Variabili (e valori da impostare) x indicare di resettare contatore lotto e
|
|
/// quindi riavviare produzione (es: impostando valore a 1...)
|
|
/// </summary>
|
|
public Dictionary<string, string> actResetCounter { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Elenco Variabili (e valori da impostare) x indicare di effettuare impostazione nuovo
|
|
/// programma/ricetta (es: impostando valore a 1...)
|
|
/// </summary>
|
|
public Dictionary<string, string> actSetRecipe { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Elenco Variabili (e valori da impostare) x indicare di fermare la produzione (es:
|
|
/// impostando valore a 1...)
|
|
/// </summary>
|
|
public Dictionary<string, string> actStopProd { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Identificativo nodo iniziale
|
|
/// </summary>
|
|
public string BrowseFullVal { get; set; } = "ns=2;s=Scalar_Static";
|
|
|
|
/// <summary>
|
|
/// Indice NS da cui fare il browse dei file
|
|
/// </summary>
|
|
public ushort BrowseNSIndex { get; set; } = 4;
|
|
|
|
/// <summary>
|
|
/// ID del nodo da cui partire x il browse di identificazione nodi iniziale
|
|
/// </summary>
|
|
public uint BrowseValue { get; set; } = 5001;
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Contapezzi Abilitato (se vuoto = sempre abilitato)
|
|
/// </summary>
|
|
public diCheckCondSetup condCountEnabled { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Errore
|
|
/// </summary>
|
|
public diCheckCondSetup condError { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Emergenza
|
|
/// </summary>
|
|
public diCheckCondSetup condEStop { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Manual
|
|
/// </summary>
|
|
public diCheckCondSetup condManual { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione PowerOn
|
|
/// </summary>
|
|
public diCheckCondSetup condPowerOn { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione READY
|
|
/// </summary>
|
|
public diCheckCondSetup condReady { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Setup
|
|
/// </summary>
|
|
public diCheckCondSetup condSetup { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione WarmUp - CoolDown
|
|
/// </summary>
|
|
public diCheckCondSetup condWarmUpCoolDown { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Warning
|
|
/// </summary>
|
|
public diCheckCondSetup condWarning { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Struttura dati x check condizione Errore
|
|
/// </summary>
|
|
public diCheckCondSetup condWorkOpc { get; set; } = new diCheckCondSetup();
|
|
|
|
/// <summary>
|
|
/// Elenco dei NodeId da ignorare intesi come interi rami (se vuoto NON filtro)
|
|
/// </summary>
|
|
public List<string> filterItemsNodeId { get; set; } = new List<string>();
|
|
|
|
public UserIdent Identity { get; set; } = new UserIdent();
|
|
|
|
/// <summary>
|
|
/// Aree di memoria lettura
|
|
/// </summary>
|
|
public Dictionary<string, dataConfTSVC> mMapRead { get; set; } = new Dictionary<string, dataConfTSVC>();
|
|
|
|
/// <summary>
|
|
/// Aree di memoria scrittura
|
|
/// </summary>
|
|
public Dictionary<string, dataConf> mMapWrite { get; set; } = new Dictionary<string, dataConf>();
|
|
|
|
/// <summary>
|
|
/// Elenco item RAW sottoscritti e relative configurazioni di decodifica da byte[]
|
|
/// </summary>
|
|
public Dictionary<string, string> rawSubscribedItemsConf { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Conf gestione setup macchina
|
|
/// </summary>
|
|
public MachineSetupConf SetupConf { get; set; } = new MachineSetupConf();
|
|
|
|
/// <summary>
|
|
/// Elenco dei SOLI item sottoscritti (se vuoto TUTTI)
|
|
/// </summary>
|
|
public List<string> subscribedItems { get; set; } = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Conf Gestione WatchDog
|
|
/// </summary>
|
|
public WatchDogConf WatchDog { get; set; } = new WatchDogConf();
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
public class UserIdent
|
|
{
|
|
#region Public Properties
|
|
|
|
public string Passwd { get; set; } = "";
|
|
public string UserName { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definizione parametri watchdog
|
|
/// </summary>
|
|
public class WatchDogConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Abilitazione WatchDog
|
|
/// </summary>
|
|
public bool IsEnabled { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Valore max contatore prima di resettare
|
|
/// </summary>
|
|
public int MaxVal { get; set; } = 9999;
|
|
|
|
/// <summary>
|
|
/// Conf memoria x lettura WatchDog (ToMes), se !="" è gestito
|
|
/// </summary>
|
|
public string MemConfRead { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Conf memoria x scrittura WatchDog (FromMes), se !="" è gestito
|
|
/// </summary>
|
|
public string MemConfWrite { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
}
|
|
} |