502 lines
16 KiB
C#
502 lines
16 KiB
C#
using MapoSDK;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace IOB_UT_NEXT
|
|
{
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri di base x allarmi
|
|
/// </summary>
|
|
public class BaseAlarmConf
|
|
{
|
|
#region Public Fields
|
|
|
|
/// <summary>
|
|
/// valore di partenza x un segnale di blink in caso di inizio variazione
|
|
/// </summary>
|
|
public int blinkVal = 30;
|
|
|
|
#endregion Public Fields
|
|
|
|
#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>
|
|
/// 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 il decremento dei contatori blink (se >0) per gestire i segnali alternati sul fronte di discesa
|
|
/// </summary>
|
|
public void decreaseBlinkCounter()
|
|
{
|
|
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 (sottraendo BITMASK i 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)));
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
// calcola la maschera di variazione da valore precedente
|
|
var variations = newStatus ^ alarmsState[num];
|
|
// ciclo sui 16 bit...
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
if ((variations & (1 << i)) == (1 << i))
|
|
{
|
|
alarmsBlinkCounter[num * 16 + i] = blinkVal;
|
|
}
|
|
}
|
|
// 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;
|
|
|
|
#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>
|
|
/// Definizione parametri watchdog
|
|
/// </summary>
|
|
public class WatchDogConf
|
|
{
|
|
/// <summary>
|
|
/// Abilitazione WatchDog
|
|
/// </summary>
|
|
public bool IsEnabled { get; set; } = false;
|
|
/// <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; } = "";
|
|
/// <summary>
|
|
/// Valore max contatore prima di resettare
|
|
/// </summary>
|
|
public int MaxVal { get; set; } = 9999;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definizione parametri di setup incrociato...
|
|
/// </summary>
|
|
public class MachineSetupConf
|
|
{
|
|
/// <summary>
|
|
/// Modalità gestione setup
|
|
/// </summary>
|
|
public MachineSetupMode SetupMode { get; set; } = MachineSetupMode.ND;
|
|
|
|
/// <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>
|
|
/// 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>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe x definizione delle azioni in fase di setup macchina
|
|
/// </summary>
|
|
public class MachineSetupAction
|
|
{
|
|
/// <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;
|
|
|
|
/// <summary>
|
|
/// Indica se vada disabilitato il contapezzi quando la condizione NotEqual sia soddisfatta
|
|
/// </summary>
|
|
public bool DisablePzCountNotEqual { get; set; } = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe gestione configurazione parametri specifici OPC-UA da BaseParamConf
|
|
/// </summary>
|
|
public class OpcUaParamConf : BaseParamConf
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <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 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 Setup
|
|
/// </summary>
|
|
public diCheckCondSetup condSetup { 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>();
|
|
|
|
/// <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 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();
|
|
|
|
/// <summary>
|
|
/// Conf gestione setup macchina
|
|
/// </summary>
|
|
public MachineSetupConf SetupConf { get; set; } = new MachineSetupConf();
|
|
|
|
#endregion Public Properties
|
|
}
|
|
} |