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 flogJson { public List fluxData { get; set; } } /// /// Tracciato FluxLog in formato JSON valido /// public class flogData { /// /// nome del flusso /// public string flux { get; set; } = "ND"; /// /// 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; } = ""; /// /// 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; } } /// /// 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 #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 }