using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
namespace MapoSDK
{
#region oggetti per scambio dati IO - IOB
public class fileEmbed
{
///
/// Array di file da inviare
///
public List fileList { get; set; } = new List();
}
///
/// Classe x definire un file (corto) inviato come Json tramite httpost
///
public class smallFile
{
public string fileName { get; set; } = "";
public string content { get; set; } = "";
}
///
/// Array elementi tipo KeyValuePair inviati come JSon che indicano lo stato LIVE dell'IOB
///
public class liveIOB
{
public List> dataList { get; set; }
}
///
/// Array valori tipo flogData inviati come JSon
///
public class flogJsonPayload
{
public List fluxData { get; set; }
}
///
/// Tracciato FluxLog in formato JSON valido
///
public class flogData : evData
{
///
/// nome del flusso
///
public string flux { get; set; } = "ND";
}
///
/// Array valori tipo evData inviati come JSon
///
public class evJsonPayload
{
public List eventList { get; set; }
}
///
/// Tracciato InputEvents in formato JSON valido
/// Derivato da input realtime valore=3&dtEve=20181206180600000&dtCurr=20181206180600000&cnt=999
///
public class evData
{
///
/// Valore del dato di flusso registrato
///
public string valore { get; set; } = "-";
///
/// DataOra evento
///
public DateTime dtEve { get; set; } = DateTime.Now;
///
/// DataOra corrente della trasmissione
///
public DateTime dtCurr { get; set; } = DateTime.Now;
///
/// Contatore incrementale x riordino invio (opzionale)
///
public int cnt { get; set; } = 0;
}
///
/// Dati resoconto IOB
///
public class IOB_data
{
public string name;
public string IP;
public IobType iType;
public string typeCss;
public bool CNC_Counter;
}
///
/// Struttura conf tipo dati
///
public class dataConf
{
///
/// NOME parametro
///
public string name { get; set; } = "none";
///
/// DESCRIZIONE parametro
///
public string description { get; set; } = "";
///
/// Tipo di dato
///
[JsonConverter(typeof(StringEnumConverter))]
public plcDataType tipoMem { get; set; } = plcDataType.Int;
///
/// Indice nell'area di memoria (da valore iniziale = 0)
///
public int index { get; set; } = 0;
///
/// Nome "assoluto" della posizione nell'area di memoria (anche diverso da indice)
///
public string memAddr { get; set; } = "";
///
/// Size in byte
///
public int size { get; set; } = 0;
///
/// Fattore per eventuale divisione (es leggo 1234 --> 12,34 con factor=100)
///
public int factor { get; set; } = 1;
///
/// Valore parametro (come stringa, decimali con ",", default VUOTO), poi LETTO da PLC (o appena scritto)
///
public string value { get; set; } = "";
///
/// Valore minimo ammesso (ove usato, es simulazione)
///
public int minVal { get; set; } = 0;
///
/// Valore massimo ammesso (ove usato, es simulazione)
///
public int maxVal { get; set; } = 9999;
}
///
/// Classe gestione ITEM di un OBJ (machine) generico (read/write)
///
public class objItem
{
///
/// UID univoco
///
public string uid { get; set; } = "";
///
/// NOME item
///
public string name { get; set; } = "";
///
/// Valore parametro (come stringa, decimali con ",", default VUOTO), sul CNC/PLC
///
public string value { get; set; } = "";
///
/// DataOra ultima lettura
///
public DateTime lastRead { get; set; } = DateTime.Now.AddHours(-1);
///
/// Indica se sia abilitato in scrittura (WRITE)
///
public bool writable { get; set; } = false;
///
/// Indica il NUOVO valore richiesto x l'item
///
public string reqValue { get; set; } = "";
///
/// DataOra ultima richiesta scrittura
///
public DateTime lastRequest { get; set; } = DateTime.Now.AddDays(-1);
///
/// Ultimo messaggio associato (conferma scrittura, errore, ...)
///
public string lastMessage { get; set; } = "";
#if false
///
/// Indica se il parametro sia stato salvato (value = newValue) oppure newValue NON impostato
///
public bool saved
{
get
{
bool hasData = !string.IsNullOrWhiteSpace(value);
bool areEqual = value == newValue;
bool noWriteReq = string.IsNullOrWhiteSpace(newValue);
return (areEqual || (hasData && noWriteReq));
}
}
#endif
}
///
/// Struttura conf tipo dati
///
public class dataConfTSVC : dataConf
{
///
/// Tipo di funzione da applicare al dato
///
[JsonConverter(typeof(StringEnumConverter))]
public VC_func func { get; set; } = VC_func.MAX;
///
/// Periodo campionamento
///
public int period { get; set; } = 60;
}
///
/// Struttura conf memorie PLC (inizialmente SIEMENS)
///
public class plcMemMap
{
///
/// Parametri ammessi per IOB x scrittura
///
public Dictionary mMapWrite = new Dictionary();
///
/// Parametri ammessi per IOB x lettura
///
public Dictionary mMapRead = new Dictionary();
}
///
/// Classe oggetto base TimeSeries
///
public class tsData
{
///
/// Nome Macchina
///
public string vcMachine { get; set; } = "";
///
/// Nome della Var Casuale
///
public string vcName { get; set; } = "";
///
/// Data-Ora riferimento campione
///
public DateTime timeStamp { get; set; } = DateTime.Now;
///
/// Tipo di valore gestito
///
[JsonConverter(typeof(StringEnumConverter))]
public plcDataType vcType { get; set; } = plcDataType.Int;
///
/// Valore in formato stringa (che può venire customizzato)
///
public string strValue { get; set; } = "";
///
/// In base al tipo di oggetto restituisce il valore cona deguata conversione......
///
public object actValue
{
get
{
object answ = null;
bool currBool = false;
int currInt = 0;
double currDouble = 0;
switch (vcType)
{
case plcDataType.Boolean:
bool.TryParse(strValue, out currBool);
answ = currBool;
break;
case plcDataType.Int:
case plcDataType.DInt:
int.TryParse(strValue, out currInt);
answ = currInt;
break;
case plcDataType.Real:
double.TryParse(strValue, out currDouble);
answ = currDouble;
break;
case plcDataType.String:
default:
answ = strValue;
break;
}
return answ;
}
}
///
/// Valore intero
///
public int intVal { get; set; } = 0;
///
/// Valore float
///
public float floatVal { get; set; } = 0;
}
///
/// Aggregazione dati VC
///
public class tsGrouped
{
///
/// Nome Macchina
///
public string vcMachine { get; set; } = "";
///
/// Nome della Var Casuale
///
public string vcName { get; set; } = "";
///
/// Unità di Misura
///
public string UM { get; set; } = "#";
///
/// Data-Ora riferimento campione
///
public DateTime timeStamp { get; set; } = DateTime.Now;
///
/// Valore medio (NON definito)
///
public object avgValue { get; set; }
///
/// Periodo di aggregazione di riferimento
///
public timeWindow period { get; set; } = timeWindow.hour;
///
/// Campioni effettivi nel periodo
///
public List samples { get; set; }
}
#region gestione dati FluxLog
///
/// Classe oggetto statistiche sui dati
///
public class varStats
{
///
/// Nome della Variabile tracciata
///
public string varName { get; set; } = "";
///
/// Num record
///
public int numRec { get; set; } = 0;
///
/// Valore medio/mediano
///
public float avg { get; set; } = 0;
///
/// Valore max
///
public float max { get; set; } = 0;
///
/// Valore min
///
public float min { get; set; } = 0;
}
///
/// Classe oggetto base TimeSeries
///
public class rawSample
{
///
/// Data-Ora riferimento campione
///
public DateTime timeStamp { get; set; } = DateTime.Now;
///
/// Valore in formato stringa
///
public string value { get; set; } = "";
}
///
/// Raccolta dati di storici sintetici per Macchina e Variabile
///
public class histData
{
///
/// Macchina
///
public string macName { get; set; } = "";
///
/// Tipo di valore registrato (internamente è string)
///
//[JsonConverter(typeof(StringEnumConverter))]
public plcDataType varType { get; set; } = plcDataType.Int;
///
/// Data riferimento campione in formato YMD = yyyyMMdd
///
public int dateYMD { get; set; } = 0;
///
/// Periodo di aggregazione di riferimento
///
//[JsonConverter(typeof(StringEnumConverter))]
public timeWindow period { get; set; } = timeWindow.day;
///
/// Statistiche raccolte nel periodo
///
public List stats { get; set; } = null;
}
///
/// Raccolta dati di storici raw per Macchina e Variabile
///
public class rawData
{
///
/// Macchina
///
public string macName { get; set; } = "";
///
/// Nome della Variabile tracciata
///
public string varName { get; set; } = "";
///
/// Tipo di valore registrato (internamente è string)
///
//[JsonConverter(typeof(StringEnumConverter))]
public plcDataType varType { get; set; } = plcDataType.Int;
///
/// Data riferimento campione in formato YMD = yyyyMMdd
///
public int dateYMD { get; set; } = 0;
///
/// Periodo di aggregazione di riferimento
///
//[JsonConverter(typeof(StringEnumConverter))]
public timeWindow period { get; set; } = timeWindow.day;
///
/// Dati raw registrati nel periodo
///
public List samples { get; set; } = null;
}
///
/// Classe x inviare messaggi di tipo esecuzione di una generica esecuzione
///
public class exeResult
{
///
/// Esito del risultato
///
[JsonConverter(typeof(StringEnumConverter))]
public esitoExec esito { get; set; } = esitoExec.undone;
///
/// Messaggio associato
///
public string message { get; set; } = "";
}
#endregion
#region gestione ALARMS / CONDITIONS
///
/// Definizione classe evento allarme
///
public class alarmEvent
{
///
/// Anno di riferimento allarme (per chiave yyyy.n)
///
public int yCurr { get; set; } = 0;
///
/// Contatore incrementale univoco annuale (per chiave yyyy.n)
///
public int yCounter { get; set; } = 0;
///
/// Data riferimento campione in formato YMD = yyyyMMdd
///
public int dateYMD { get; set; } = 0;
///
/// Data-Ora inizio evento
///
public DateTime started { get; set; } = DateTime.Now;
///
/// Data-Ora inizio evento
///
public DateTime ended { get; set; } = DateTime.Now;
///
/// Lista delle condizioni di allarme attive ad inizio evento
///
public List activeConditions { get; set; } = null;
///
/// Elenco dei dati di tipo FluxLog nei minuti antecedenti l'evento
///
public List blackBoxData { get; set; } = null;
}
///
/// Definizione classe evento allarme
///
public class alarmStats
{
///
/// Anno riferimento
///
public int year { get; set; } = 0;
///
/// Valore Contatore univoco annuale raggiunto yyyy.n
///
public int yCounter { get; set; } = 1;
///
/// Valore cumulato complessivo degli allarmi registrati
///
public double totalDuration { get; set; } = 0;
///
/// Durata media annuale allarmi
///
public double avgDuration
{
get
{
double answ = 0;
try
{
answ = totalDuration / yCounter;
}
catch
{ }
return answ;
}
}
}
///
/// Definizione allarme
///
public class alarmData
{
///
/// Codice univoco
///
public string code { get; set; } = "";
///
/// Descrizione
///
public string description { get; set; } = "";
///
/// Severity (0....1000, minimo...massimo)
///
public int severity { get; set; } = 0;
}
#endregion
#region gestione oggetti conf MTConnect
///
/// Configurazione delle macchine MTC
///
public class MtcSetup
{
///
/// IdxMacchina cui ci riferiamo
///
public string idxMacchina { get; set; } = "";
///
/// Setup della macchina
///
public List dataItems { get; set; }
}
///
/// Descrittore oggetto DataItem generico
///
public class machDataItem
{
public machDataItem()
{ }
///
/// ID generico
///
public string uuid { get; set; }
///
/// Categoria oggetto
///
public DataItemCategory Category { get; set; }
///
/// Nome / descrizione
///
public string Name { get; set; }
///
/// Tipologia principale
///
public string Type { get; set; }
///
/// Tipologia specifica
///
public string SubType { get; set; }
///
/// Unità di misura
///
public string Units { get; set; }
}
#endregion
#region gestione oggetti stato IOB scambiati tra IOB-MAN e IOB-WIN
///
/// Rappresentazione dello stato corrente dell'IOB
///
public class IobWinCurrentState
{
///
/// Semaforo IN (IOB-PLC)
///
public Semaforo SemIn { get; set; } = Semaforo.ND;
///
/// Semaforo OUT (IOB-MPserver)
///
public Semaforo SemOut { get; set; } = Semaforo.ND;
///
/// Contatore IOB
///
public float counterIOB { get; set; } = 0;
///
/// Contatore Macchina
///
public float counterMAC { get; set; } = 0;
///
/// Lunghezza coda EVENTI in uscita
///
public int queueEvLen { get; set; } = 0;
///
/// Lunghezza coda FluxLog in uscita
///
public int queueFLogLen { get; set; } = 0;
///
/// DataOra ultima comunicazione IN (con PLC)
///
public DateTime lastDataIn { get; set; } = DateTime.Now.AddYears(-1);
///
/// DataOra ultima comunicazione OUT (con MP Server)
///
public DateTime lastDataOut { get; set; } = DateTime.Now.AddYears(-1);
///
/// Ultimo stato noto dei parametri in memoria letti da PLC
///
public Dictionary currParams { get; set; } = null;
}
#if false
///
/// Calendario eventi
///
public class EventsCalendar
{
///
/// Lista di eventi
///
public List EventsList { get; set; }
}
#endif
///
/// Singolo dettaglio evento
///
public class EventDetail
{
///
/// Data di riferimento
///
public DateTime when { get; set; }
///
/// Nome evento
///
public string what { get; set; } = "";
}
#endregion
#endregion
#if false
///
/// Classe definizione parametri singolo ordine produzione
///
public class OrdineProdArt
{
///
/// Codice univoco ordine
///
public string OrdNum;
///
/// Articolo associato ad ordine
///
public Articolo ArtOrd;
///
/// Quantità Articolo
///
public int Qta;
}
///
/// Oggetto generico articolo
///
public class Articolo
{
///
/// Codice articolo
///
public string Codice;
///
/// Descrizione Articolo
///
public string Descrizione;
}
///
/// Classe definizione parametri ordine x KIT di articoli
///
public class OrdineProdKit
{
///
/// Codice univoco ordine
///
public string OrdNum;
///
/// Codice KIT
///
public string Codice;
///
/// Vettore ordini articolo associati a KIT
///
public List OrdiniArt;
///
/// Quantità KIT
///
public int Qta;
}
#endif
}