2570 lines
94 KiB
C#
2570 lines
94 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using NLog;
|
|
|
|
namespace MTC_Adapter
|
|
{
|
|
using MTConnect;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
#region macro oggetti da istanziare a blocchi da configurazione XML
|
|
|
|
/// <summary>
|
|
/// Singola pompa da vuoto, 0..n
|
|
/// </summary>
|
|
public class VacuumPomp : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mVacPumpAlias;
|
|
/// <summary>
|
|
/// valore indca stato aperto/chiuso
|
|
/// </summary>
|
|
public Event mVacPumpStatus;
|
|
/// <summary>
|
|
/// valore work time della pompa vuoto
|
|
/// </summary>
|
|
public Event mVacPumpWrkTime;
|
|
/// <summary>
|
|
/// Classe Vacuum Pump (pompa)
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public VacuumPomp(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
// genero elementi specifici MTConnect
|
|
mVacPumpAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mVacPumpAlias.Value = alias;
|
|
mVacPumpStatus = new Event(dataRefList[0].Key);
|
|
mVacPumpWrkTime = new Event(dataRefList[1].Key);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singolo attuatore vuoto, 0..n
|
|
/// </summary>
|
|
public class VacuumAct : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mVacActAlias;
|
|
/// <summary>
|
|
/// valore numero attivazioni/disattivazioni valvola
|
|
/// </summary>
|
|
public Event mVacActCount;
|
|
|
|
/// <summary>
|
|
/// Classe Vacuum Actuator (valvola)
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public VacuumAct(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mVacActAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mVacActAlias.Value = alias;
|
|
mVacActCount = new Event(dataRefList[0].Key);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singolo attuatore per lubrificazione, 0..n
|
|
/// </summary>
|
|
public class Lubro : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mLubroAlias;
|
|
/// <summary>
|
|
/// numero pompate necessarie per far scattare sensore
|
|
/// </summary>
|
|
public Event mLubroNum;
|
|
/// <summary>
|
|
/// Status
|
|
/// </summary>
|
|
public Event mLubroStatus;
|
|
|
|
/// <summary>
|
|
/// Classe Lubrorefrigerante
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Lubro(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mLubroAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mLubroAlias.Value = alias;
|
|
mLubroNum = new Event(dataRefList[0].Key);
|
|
mLubroStatus = new Event(string.Format("{0}_Status", ident));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singolo refrigeratore, 0..n
|
|
/// </summary>
|
|
public class Cooler : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mCoolAlias;
|
|
/// <summary>
|
|
/// Stato istantaneo (evento aperto/chiuso)
|
|
/// </summary>
|
|
public Event mCoolStatus;
|
|
|
|
/// <summary>
|
|
/// Classe refrigeratore
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Cooler(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mCoolAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mCoolAlias.Value = alias;
|
|
mCoolStatus = new Event(dataRefList[0].Key);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singola Pressione rilevata, 0..n
|
|
/// </summary>
|
|
public class Press : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mPressAlias;
|
|
/// <summary>
|
|
/// valore pressione istantaneo
|
|
/// </summary>
|
|
public Sample mPressValIst;
|
|
/// <summary>
|
|
/// Classe pressione con Idx e descrizione
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Press(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mPressAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mPressAlias.Value = alias;
|
|
mPressValIst = new Sample(dataRefList[0].Key);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singola temperatura rilevata, 0..n
|
|
/// </summary>
|
|
public class Tempe : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mTempAlias;
|
|
/// <summary>
|
|
/// valore temperatura istantaneo
|
|
/// </summary>
|
|
public Sample mTempValIst;
|
|
/// <summary>
|
|
/// Classe temperatura con Idx e descrizione
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Tempe(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mTempAlias = new Event(string.Format("{0}_Alias", ident));
|
|
mTempAlias.Value = alias;
|
|
mTempValIst = new Sample(dataRefList[0].Key);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singolo path, da 1..20
|
|
/// </summary>
|
|
public class Path : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public MTConnect.Message mPathAlias;
|
|
/// <summary>
|
|
/// Tipo Path (LAVOR/ASSERV)
|
|
/// </summary>
|
|
public MTConnect.Message mPathType;
|
|
/// <summary>
|
|
/// Cod Particolare su Path
|
|
/// </summary>
|
|
public Event mPathPartId;
|
|
/// <summary>
|
|
/// Contapezzi x PATH
|
|
/// </summary>
|
|
public Event mPathPartCount;
|
|
/// <summary>
|
|
/// Codici M sul PATH
|
|
/// </summary>
|
|
public MTConnect.Message mPathCodM;
|
|
/// <summary>
|
|
/// Codici S sul PATH
|
|
/// </summary>
|
|
public MTConnect.Message mPathCodS;
|
|
/// <summary>
|
|
/// Codici T sul PATH
|
|
/// </summary>
|
|
public MTConnect.Message mPathCodT;
|
|
/// <summary>
|
|
/// Modalità RUN del PATH: AUTO/EDIT/MDI/JOG/JOGINC/REF/HANDLE
|
|
/// </summary>
|
|
public Event mPathRunMode;
|
|
/// <summary>
|
|
/// Modalità execution del path: RUN/HOLD/FEED_HOLD/...
|
|
/// </summary>
|
|
public Event mPathExeMode;
|
|
/// <summary>
|
|
/// Programma corrente
|
|
/// </summary>
|
|
public Event mPathCurrProg;
|
|
/// <summary>
|
|
/// num riga corrente
|
|
/// </summary>
|
|
public Event mPathCurrProgRowNum;
|
|
/// <summary>
|
|
/// Assi attivi per path
|
|
/// </summary>
|
|
public Event mPathActiveAxes;
|
|
/// <summary>
|
|
/// Feedrate
|
|
/// </summary>
|
|
public Sample mPathFeed;
|
|
/// <summary>
|
|
/// Override feed
|
|
/// </summary>
|
|
public Sample mPathFeedOver;
|
|
/// <summary>
|
|
/// Override speed
|
|
/// </summary>
|
|
public Sample mPathRapidOver;
|
|
/// <summary>
|
|
/// Posizione X
|
|
/// </summary>
|
|
public Sample mPathPosActX;
|
|
/// <summary>
|
|
/// Posizione Y
|
|
/// </summary>
|
|
public Sample mPathPosActY;
|
|
/// <summary>
|
|
/// Posizione Z
|
|
/// </summary>
|
|
public Sample mPathPosActZ;
|
|
/// <summary>
|
|
/// Angolo I
|
|
/// </summary>
|
|
public Sample mPathPosActI;
|
|
/// <summary>
|
|
/// Angolo J
|
|
/// </summary>
|
|
public Sample mPathPosActJ;
|
|
/// <summary>
|
|
/// Angolo K
|
|
/// </summary>
|
|
public Sample mPathPosActK;
|
|
/// <summary>
|
|
/// Stato dei codici G attivi
|
|
/// </summary>
|
|
public MTConnect.Message mPathCodG_Act;
|
|
/// <summary>
|
|
/// Stato dei SubMode attivi
|
|
/// </summary>
|
|
public MTConnect.Message mPathSubMode;
|
|
/// <summary>
|
|
/// Allarmi CNC del PATH
|
|
/// </summary>
|
|
public Condition mPathAlarmCNC;
|
|
/// <summary>
|
|
/// Allarmi PCL del PATH
|
|
/// </summary>
|
|
public Condition mPathAlarmPLC;
|
|
|
|
/// <summary>
|
|
/// Classe Path con Idx e descrizione
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Path(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mPathAlias = new MTConnect.Message(string.Format("{0}_Alias", ident));
|
|
mPathAlias.Value = alias;
|
|
mPathFeed = new Sample(dataRefList[0].Key);
|
|
mPathFeedOver = new Sample(dataRefList[1].Key);
|
|
mPathRapidOver = new Sample(dataRefList[2].Key);
|
|
mPathPosActX = new Sample(dataRefList[3].Key);
|
|
mPathPosActY = new Sample(dataRefList[4].Key);
|
|
mPathPosActZ = new Sample(dataRefList[5].Key);
|
|
mPathPosActI = new Sample(dataRefList[6].Key);
|
|
mPathPosActJ = new Sample(dataRefList[7].Key);
|
|
mPathPosActK = new Sample(dataRefList[8].Key);
|
|
// aggiunta x revisione 2016.05.05
|
|
mPathType = new MTConnect.Message(dataRefList[9].Key);
|
|
mPathPartId = new Event(dataRefList[10].Key);
|
|
mPathPartCount = new Event(dataRefList[11].Key);
|
|
mPathCodM = new MTConnect.Message(dataRefList[12].Key);
|
|
mPathCodS = new MTConnect.Message(dataRefList[13].Key);
|
|
mPathCodT = new MTConnect.Message(dataRefList[14].Key);
|
|
mPathRunMode = new Event(dataRefList[15].Key);
|
|
mPathExeMode = new Event(dataRefList[16].Key);
|
|
mPathCurrProg = new Event(dataRefList[17].Key);
|
|
mPathCurrProgRowNum = new Event(dataRefList[18].Key);
|
|
mPathActiveAxes = new Event(dataRefList[19].Key);
|
|
mPathCodG_Act = new MTConnect.Message(dataRefList[20].Key);
|
|
mPathSubMode = new MTConnect.Message(dataRefList[21].Key);
|
|
mPathAlarmCNC = new Condition(string.Format("{0}_AlarmCNC", ident));
|
|
mPathAlarmPLC = new Condition(string.Format("{0}_AlarmPLC", ident));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Singolo mandrino, 1..n
|
|
/// </summary>
|
|
public class UnOp : element
|
|
{
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public MTConnect.Message mUnOpAlias;
|
|
/// <summary>
|
|
/// Alias
|
|
/// </summary>
|
|
public Event mUnOpToolId;
|
|
/// <summary>
|
|
/// valore numero Cambi Utensili effettuato
|
|
/// </summary>
|
|
public Event mUnOpNumCU;
|
|
/// <summary>
|
|
/// status utensil
|
|
/// </summary>
|
|
public Event mUnOpStatus;
|
|
/// <summary>
|
|
/// valore vita residua utensile
|
|
/// </summary>
|
|
public Event mUnOpVitaRes;
|
|
/// <summary>
|
|
/// tipologia di vita residua utensile:
|
|
/// 0 : "ND" (famiglia senza gestione vitautensili)
|
|
/// 1 : "Time [s]"
|
|
/// 2 : "Stroke [n]"
|
|
/// 3 : "Distance [m]" ([ft] se la macchina è impostata in pollici)
|
|
/// </summary>
|
|
public MTConnect.Message mUnOpVitaResType;
|
|
/// <summary>
|
|
/// valore speed
|
|
/// </summary>
|
|
public Sample mUnOpSpeed;
|
|
/// <summary>
|
|
/// valore speed override
|
|
/// </summary>
|
|
public Sample mUnOpSpeedOverr;
|
|
/// <summary>
|
|
/// valore load
|
|
/// </summary>
|
|
public Sample mUnOpLoad;
|
|
/// <summary>
|
|
/// valore tempo cumulato di impiego
|
|
/// </summary>
|
|
public Sample mUnOpAccTime;
|
|
/// <summary>
|
|
/// contatore cumulato di giri mandrino (migliaia)
|
|
/// </summary>
|
|
public Sample mUnOpKRev;
|
|
/// <summary>
|
|
/// Classe Unita Operatrice (Mandrino) con Idx e descrizione
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public UnOp(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
mUnOpAlias = new MTConnect.Message(string.Format("{0}_Alias", ident));
|
|
mUnOpAlias.Value = alias;
|
|
mUnOpToolId = new Event(dataRefList[0].Key);
|
|
mUnOpNumCU = new Event(dataRefList[1].Key);
|
|
mUnOpStatus = new Event(dataRefList[2].Key);
|
|
mUnOpVitaRes = new Event(dataRefList[3].Key);
|
|
mUnOpSpeed = new Sample(dataRefList[4].Key);
|
|
mUnOpSpeedOverr = new Sample(dataRefList[5].Key);
|
|
mUnOpLoad = new Sample(dataRefList[6].Key);
|
|
mUnOpAccTime = new Sample(dataRefList[7].Key);
|
|
mUnOpVitaResType = new MTConnect.Message(dataRefList[8].Key);
|
|
mUnOpKRev = new Sample(string.Format("{0}_KREV", ident));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Asse singolo, 1..n
|
|
/// </summary>
|
|
public class Axis : element
|
|
{
|
|
/// <summary>
|
|
/// Descrizione / Alias
|
|
/// </summary>
|
|
public MTConnect.Message mAxAlias;
|
|
/// <summary>
|
|
/// Processo di appartenenza
|
|
/// </summary>
|
|
public MTConnect.Message mAxMainProc;
|
|
/// <summary>
|
|
/// Bit se sia master (=1) o slave (=0)
|
|
/// </summary>
|
|
public MTConnect.Message mAxIsMaster;
|
|
/// <summary>
|
|
/// ID del master
|
|
/// </summary>
|
|
public Event mAxMastId;
|
|
/// <summary>
|
|
/// Event tipo asse: lineare, rotazionale...
|
|
/// </summary>
|
|
public Event mAxType;
|
|
/// <summary>
|
|
/// Bit direzione: 1 = avanti/clockwise, 0 indietro/counterclockwise
|
|
/// </summary>
|
|
public Event mAxDir;
|
|
/// <summary>
|
|
/// Load
|
|
/// </summary>
|
|
public Sample mAxLoad;
|
|
/// <summary>
|
|
/// Posizione Attuale
|
|
/// </summary>
|
|
public Sample mAxPosAct;
|
|
/// <summary>
|
|
/// Posizione Target
|
|
/// </summary>
|
|
public Sample mAxPosTgt;
|
|
/// <summary>
|
|
/// Feed Attuale
|
|
/// </summary>
|
|
public Sample mAxFeedAct;
|
|
/// <summary>
|
|
/// Feed Override
|
|
/// </summary>
|
|
public Sample mAxFeedOver;
|
|
/// <summary>
|
|
/// Accelerazione Attuale
|
|
/// </summary>
|
|
public Sample mAxAccelAct;
|
|
/// <summary>
|
|
/// Tempo Lavoro cumulato
|
|
/// </summary>
|
|
public Sample mAxAccTime;
|
|
/// <summary>
|
|
/// Carica batteria
|
|
/// </summary>
|
|
public Sample mAxBattery;
|
|
/// <summary>
|
|
/// Distanza compiuta nell'intervallo di tempo
|
|
/// </summary>
|
|
public Sample mAxDistDone;
|
|
/// <summary>
|
|
/// numero di inversioni di direzione fatte nell'intervallo di tempo
|
|
/// </summary>
|
|
public Sample mAxInvDDone;
|
|
/// <summary>
|
|
/// Allarmi CNC del PATH
|
|
/// </summary>
|
|
public Condition mAxAlarmCNC;
|
|
/// <summary>
|
|
/// Allarmi PCL del PATH
|
|
/// </summary>
|
|
public Condition mAxAlarmPLC;
|
|
|
|
/// <summary>
|
|
/// Classe Asse con relativo ID UNIVOCO ed alias
|
|
/// </summary>
|
|
/// <param name="baseElem">element base contenente parametri (da XML)</param>
|
|
public Axis(element baseElem)
|
|
{
|
|
ident = baseElem.ident;
|
|
alias = baseElem.alias;
|
|
fonte = baseElem.fonte;
|
|
dataRefList = baseElem.dataRefList;
|
|
|
|
// inizializzo vari eventi, sample, condizioni
|
|
mAxAlias = new MTConnect.Message(string.Format("{0}_Alias", ident));
|
|
mAxAlias.Value = alias;
|
|
mAxMainProc = new MTConnect.Message(dataRefList[0].Key);
|
|
mAxIsMaster = new MTConnect.Message(dataRefList[1].Key);
|
|
mAxMastId = new Event(dataRefList[2].Key);
|
|
mAxType = new Event(dataRefList[3].Key);
|
|
mAxType.Value = dataRefList[3].Value;
|
|
mAxDir = new Event(dataRefList[4].Key);
|
|
mAxLoad = new Sample(dataRefList[5].Key);
|
|
mAxPosAct = new Sample(dataRefList[6].Key);
|
|
mAxPosTgt = new Sample(dataRefList[7].Key);
|
|
mAxFeedAct = new Sample(dataRefList[8].Key);
|
|
mAxFeedOver = new Sample(dataRefList[9].Key);
|
|
mAxAccelAct = new Sample(dataRefList[10].Key);
|
|
mAxAccTime = new Sample(dataRefList[11].Key);
|
|
mAxBattery = new Sample(dataRefList[12].Key);
|
|
mAxDistDone = new Sample(dataRefList[13].Key);
|
|
mAxInvDDone = new Sample(dataRefList[14].Key);
|
|
|
|
mAxAlarmCNC = new Condition(string.Format("{0}_AlarmCNC", ident));
|
|
mAxAlarmPLC = new Condition(string.Format("{0}_AlarmPLC", ident));
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
public class AdapterGeneric
|
|
{
|
|
/// <summary>
|
|
/// alias booleano false = R
|
|
/// </summary>
|
|
public bool R = false;
|
|
/// <summary>
|
|
/// alias booleano true = W
|
|
/// </summary>
|
|
public bool W = true;
|
|
/// <summary>
|
|
/// wrapper di log
|
|
/// </summary>
|
|
public static Logger lg;
|
|
/// <summary>
|
|
/// valore booleano di check se sia in fase di COMUNICAZIONE ATTIVA con il PLC/NC
|
|
/// </summary>
|
|
protected bool adpCommAct;
|
|
/// <summary>
|
|
/// valore booleano di check se sia stato AVVIATO l'adapter (Running)
|
|
/// </summary>
|
|
public bool adpRunning = false;
|
|
/// <summary>
|
|
/// valore booleano (richiesta di riavvio automatico)
|
|
/// </summary>
|
|
public bool adpTryRestart;
|
|
/// <summary>
|
|
/// Determina se utilizzare blocchi di memoria IOT contigui (e quindi processing "monoblocco" semplificato"=
|
|
/// </summary>
|
|
public bool procIotMem = false;
|
|
/// <summary>
|
|
/// porta x adapter (x restart)
|
|
/// </summary>
|
|
protected int adpPortNum;
|
|
/// <summary>
|
|
/// DataOra ultimo avvio adapter x watchdog
|
|
/// </summary>
|
|
protected DateTime adpStartRun;
|
|
/// <summary>
|
|
/// Data/ora ultimo avvio adapter
|
|
/// </summary>
|
|
public DateTime dtAvvioAdp = DateTime.Now;
|
|
/// <summary>
|
|
/// Data/ora ultimo spegnimento adapter
|
|
/// </summary>
|
|
public DateTime dtStopAdp = DateTime.Now;
|
|
/// <summary>
|
|
/// vettore gestione cronometraggi
|
|
/// </summary>
|
|
public DateTime inizio;
|
|
/// <summary>
|
|
/// Conteggio ATTUALE ore macchina ON
|
|
/// </summary>
|
|
public double contOreMaccOn;
|
|
/// <summary>
|
|
/// Conteggio ATTUALE ore macchina IN LAVORO
|
|
/// </summary>
|
|
public double contOreMaccLav;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori giri cumulati elettromandrino (migliaia)
|
|
/// </summary>
|
|
public uint[] contGiriElettrom;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del movimento degli assi
|
|
/// </summary>
|
|
public double[] contDistMovAssi;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del tempo cumulato degli assi
|
|
/// </summary>
|
|
public double[] contAccTimeAssi;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del num inv degli assi
|
|
/// </summary>
|
|
public uint[] contNumInvAssi;
|
|
/// <summary>
|
|
/// vettore dei ProgramName dei path ATTIVI
|
|
/// </summary>
|
|
public string[] currPathProgrName;
|
|
/// <summary>
|
|
/// vettore dei PartId dei path ATTIVI
|
|
/// </summary>
|
|
public string[] currPathPartId;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del num pezzi fatti x PartId
|
|
/// </summary>
|
|
public uint[] currPathPartCount;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del work time x VacPump
|
|
/// </summary>
|
|
public uint[] currVacPumpWrkTime;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del numero impieghi VacAct
|
|
/// </summary>
|
|
public uint[] currVacActCount;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del Lubro
|
|
/// </summary>
|
|
public uint[] currLubroCount;
|
|
/// <summary>
|
|
/// Vettore ATTUALE dei contatori del numero cambi utensili x UnOp
|
|
/// </summary>
|
|
public uint[] currNumCambiUt;
|
|
|
|
|
|
/// <summary>
|
|
/// Conteggio ISTANTANEO ore macchina ON
|
|
/// </summary>
|
|
public double istOreMaccOn;
|
|
/// <summary>
|
|
/// isteggio ISTANTANEO ore macchina IN LAVORO
|
|
/// </summary>
|
|
public double istOreMaccLav;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori giri cumulati elettromandrino (migliaia)
|
|
/// </summary>
|
|
public uint[] istGiriElettrom;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del movimento degli assi
|
|
/// </summary>
|
|
public double[] istDistMovAssi;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del tempo cumulato degli assi
|
|
/// </summary>
|
|
public double[] istAccTimeAssi;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del num inv degli assi
|
|
/// </summary>
|
|
public uint[] istNumInvAssi;
|
|
/// <summary>
|
|
/// vettore dei Program Name dei path ISTANTANEI (nuovi/letti)
|
|
/// </summary>
|
|
public string[] istPathProgrName;
|
|
/// <summary>
|
|
/// vettore dei PartId dei path ISTANTANEI (nuovi/letti)
|
|
/// </summary>
|
|
public string[] istPathPartId;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del num pezzi fatti x PartId
|
|
/// </summary>
|
|
public uint[] istPathPartCount;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del work time x VacPump
|
|
/// </summary>
|
|
public uint[] istVacPumpWrkTime;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del numero impieghi VacAct
|
|
/// </summary>
|
|
public uint[] istVacActCount;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del Lubro
|
|
/// </summary>
|
|
public uint[] istLubroCount;
|
|
/// <summary>
|
|
/// Vettore ISTANTANEO dei contatori del numero cambi utensili x UnOp
|
|
/// </summary>
|
|
public uint[] istNumCambiUt;
|
|
|
|
|
|
/// <summary>
|
|
/// data-ora ultimo controllo movimento assi
|
|
/// </summary>
|
|
public DateTime lastChekAccumTimeAxis;
|
|
|
|
/// <summary>
|
|
/// posizione precedente assi per calcolo distanze...
|
|
/// </summary>
|
|
public double[] prevPosAxis;
|
|
/// <summary>
|
|
/// direzione precedente assi per calcolo inversioni...
|
|
/// </summary>
|
|
public int[] prevDirAxis;
|
|
|
|
|
|
/// <summary>
|
|
/// adapter globale
|
|
/// </summary>
|
|
public Adapter mAdapter = new Adapter();
|
|
/// <summary>
|
|
/// Form chiamante
|
|
/// </summary>
|
|
protected MainForm parentForm;
|
|
/// <summary>
|
|
/// Conf adapter corrente
|
|
/// </summary>
|
|
public AdapterConf currAdpConf;
|
|
|
|
#region altri oggetti
|
|
|
|
// 16 bit di strobe (4 word da 32 bit di flags...)
|
|
public byte[] Strobes = new byte[16];
|
|
// 16 bit di strobe in risposta (4 word da 32 bit di flags...)
|
|
public byte[] Acknowl = new byte[16];
|
|
|
|
// 1024 bit di strobe degli allarmi attivi (32 word da 4byte/32 bit di flags...)
|
|
public byte[] AlarmFlags;
|
|
|
|
/// <summary>
|
|
/// Oggetto elenco allarmi
|
|
/// </summary>
|
|
public allarme[] elencoAllarmi;
|
|
|
|
public Dictionary<string, string> elencoSubMode;
|
|
|
|
/// <summary>
|
|
/// Prima word di strobe da array flag completo
|
|
/// </summary>
|
|
public StFlag32 STRB_DW0
|
|
{
|
|
get
|
|
{
|
|
//byte[] answ = new byte[4];
|
|
//answ = (byte[])Strobes.Skip(0).Take(4);
|
|
return (StFlag32)BitConverter.ToUInt32(Strobes, 0);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Seconda word di strobe da array flag completo
|
|
/// </summary>
|
|
public StFlag32 STRB_DW1
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Strobes, 4);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Terza word di strobe da array flag completo
|
|
/// </summary>
|
|
public StFlag32 STRB_DW2
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Strobes, 8);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Quarta word di strobe da array flag completo
|
|
/// </summary>
|
|
public StFlag32 STRB_DW3
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Strobes, 12);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Prima word di ACKnowledgment da array flag completo
|
|
/// </summary>
|
|
public StFlag32 ACK_DW0
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Acknowl, 0);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Seconda word di ACKnowledgment da array flag completo
|
|
/// </summary>
|
|
public StFlag32 ACK_DW1
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Acknowl, 4);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Terza word di ACKnowledgment da array flag completo
|
|
/// </summary>
|
|
public StFlag32 ACK_DW2
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Acknowl, 8);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Quarta word di ACKnowledgment da array flag completo
|
|
/// </summary>
|
|
public StFlag32 ACK_DW3
|
|
{
|
|
get
|
|
{
|
|
return (StFlag32)BitConverter.ToUInt32(Acknowl, 12);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Strobe mask PLC
|
|
/// </summary>
|
|
public Strobe STROBE_PLC = 0;
|
|
/// <summary>
|
|
/// Strobe mask adapter
|
|
/// </summary>
|
|
public Strobe STROBE_ADP = 0;
|
|
/// <summary>
|
|
/// Status flag
|
|
/// </summary>
|
|
public StatusBitMap STATUS_FLAG = 0;
|
|
/// <summary>
|
|
/// Variabili stato macchina principali
|
|
/// </summary>
|
|
public StFlag8 ST_MACCH = 0;
|
|
|
|
public List<string> codaM = new List<string>();
|
|
public List<string> codaS = new List<string>();
|
|
public List<string> codaT = new List<string>();
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
/// <summary>
|
|
/// Asset Changed - cambio asset
|
|
/// </summary>
|
|
public Event mAssetChg = new Event("MTC_asset_chg");
|
|
/// <summary>
|
|
/// Asset Removed - cambio asset
|
|
/// </summary>
|
|
public Event mAssetRem = new Event("MTC_asset_rem");
|
|
|
|
/// <summary>
|
|
/// D.D1.AVAIL - disponibilità
|
|
/// </summary>
|
|
public Event mAvail = new Event("AVAIL");
|
|
/// <summary>
|
|
/// XX.XX.STOP - stop per pressione emergenze
|
|
/// </summary>
|
|
public Event mEStop = new Event("E_STOP");
|
|
/// <summary>
|
|
/// STATUS "logico" adapter macchina (ON/OFF)
|
|
/// </summary>
|
|
public Event mStatus = new Event("STATUS");
|
|
/// <summary>
|
|
/// Minuti accensione globale macchina
|
|
/// </summary>
|
|
public Sample mAccTime = new Sample("ACC_TIME");
|
|
/// <summary>
|
|
/// Minuti funzionamento globale macchina (IN LAVORO)
|
|
/// </summary>
|
|
public Sample mAccTimeWork = new Sample("ACC_TIME_WORK");
|
|
/// <summary>
|
|
/// Orologio
|
|
/// </summary>
|
|
public Sample mClock = new Sample("CLOCK");
|
|
/// <summary>
|
|
/// Status macchina accesa/spenta
|
|
/// </summary>
|
|
public Event mPower = new Event("POWER");
|
|
/// <summary>
|
|
/// ID operatore?!?
|
|
/// </summary>
|
|
public Event mOperator = new Event("OperatorId");
|
|
|
|
/// <summary>
|
|
/// modalità funzionale
|
|
/// </summary>
|
|
public MTConnect.Message mFunctionalMode = new MTConnect.Message("FUNCT_MODE");
|
|
/// <summary>
|
|
/// Azioni operatore (Start/Stop/reset)
|
|
/// </summary>
|
|
public MTConnect.Message mUserAction = new MTConnect.Message("USER_ACTION");
|
|
/// <summary>
|
|
/// Testing macchina
|
|
/// </summary>
|
|
public MTConnect.Message mTestingData = new MTConnect.Message("TESTING_DATA");
|
|
/// <summary>
|
|
/// Stato protezioni (0/1, off/on)
|
|
/// </summary>
|
|
public Event mProtectionStatus = new Event("PROTECTION_STATUS");
|
|
/// <summary>
|
|
/// Strobe rilevati ma non qualificati
|
|
/// </summary>
|
|
public MTConnect.Message mUnkStrobe = new MTConnect.Message("UNK_STROBE");
|
|
/// <summary>
|
|
/// Status rilevati ma non qualificati
|
|
/// </summary>
|
|
public MTConnect.Message mUnkStatus = new MTConnect.Message("UNK_STATUS");
|
|
|
|
#endregion
|
|
|
|
#region Conditions
|
|
|
|
// vettori vari: allarmi sistema, PLC, CNC ed allarmi HMI
|
|
//public Condition mAlarmSystem = new Condition("System");
|
|
public Condition mAlarmCNC = new Condition("CNC");
|
|
public Condition mAlarmPLC = new Condition("PLC");
|
|
//public Condition mAlarmHMI = new Condition("HMI");
|
|
//public Condition mAlarmGeneral = new Condition("General");
|
|
|
|
#endregion
|
|
|
|
#region Messages
|
|
|
|
public MTConnect.Message mMessage = new MTConnect.Message("MESSAGE");
|
|
|
|
#endregion
|
|
|
|
#region oggetti complessi/completi
|
|
|
|
|
|
public VacuumPomp[] vettVacPump;
|
|
public VacuumAct[] vettVacAct;
|
|
public Lubro[] vettLubro;
|
|
public Cooler[] vettCooler;
|
|
public Press[] vettPress;
|
|
public Tempe[] vettTempe;
|
|
public Path[] vettPath;
|
|
public UnOp[] vettUnOp;
|
|
public Axis[] vettAxis;
|
|
|
|
#endregion
|
|
|
|
public event EventHandler eh_refreshed;
|
|
|
|
/// <summary>
|
|
/// inizializzo l'oggetto sulla form SULLA BASE DEL FILE DI CONFIGURAZIONE letto
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="adpConf"></param>
|
|
public AdapterGeneric(MainForm caller, AdapterConf adpConf)
|
|
{
|
|
lg = LogManager.GetCurrentClassLogger();
|
|
lg.Info("Avvio AdapterGeneric");
|
|
|
|
procIotMem = utils.CRB("procIotMem");
|
|
|
|
currAdpConf = adpConf;
|
|
|
|
// salvo al form chiamante
|
|
parentForm = caller;
|
|
|
|
// item disponibilità
|
|
mAdapter.AddDataItem(mAvail);
|
|
mAvail.Value = "AVAILABLE";
|
|
mMessage.Value = "";
|
|
|
|
// assets
|
|
mAdapter.AddDataItem(mAssetChg);
|
|
mAdapter.AddDataItem(mAssetRem);
|
|
mAssetChg.Value = "";
|
|
mAssetRem.Value = "";
|
|
|
|
// status, clock, emergency stop
|
|
mAdapter.AddDataItem(mStatus);
|
|
mAdapter.AddDataItem(mAccTime);
|
|
mAdapter.AddDataItem(mAccTimeWork);
|
|
mAdapter.AddDataItem(mClock);
|
|
mAdapter.AddDataItem(mPower);
|
|
mAdapter.AddDataItem(mEStop);
|
|
|
|
// programma e produzione
|
|
mAdapter.AddDataItem(mOperator);
|
|
|
|
// modalità esecutiva e funzionale
|
|
mFunctionalMode.Value = "";
|
|
mAdapter.AddDataItem(mFunctionalMode);
|
|
|
|
|
|
// testing e autodiagnostica
|
|
mAdapter.AddDataItem(mTestingData);
|
|
|
|
// stato protezioni
|
|
mAdapter.AddDataItem(mProtectionStatus);
|
|
|
|
// strobe/status non riconosciuti
|
|
mAdapter.AddDataItem(mUnkStatus);
|
|
mAdapter.AddDataItem(mUnkStrobe);
|
|
|
|
// Pompe vuoto
|
|
vettVacPump = new VacuumPomp[adpConf.nVacuumPump];
|
|
for (int i = 0; i < adpConf.nVacuumPump; i++)
|
|
{
|
|
vettVacPump[i] = new VacuumPomp(adpConf.VacuumPump[i]);
|
|
mAdapter.AddDataItem(vettVacPump[i].mVacPumpStatus);
|
|
mAdapter.AddDataItem(vettVacPump[i].mVacPumpWrkTime);
|
|
}
|
|
// Attuatori vuoto
|
|
vettVacAct = new VacuumAct[adpConf.nVacuumAct];
|
|
for (int i = 0; i < adpConf.nVacuumAct; i++)
|
|
{
|
|
vettVacAct[i] = new VacuumAct(adpConf.VacuumAct[i]);
|
|
//mAdapter.AddDataItem(vettVacAct[i].mVacActAlias);
|
|
mAdapter.AddDataItem(vettVacAct[i].mVacActCount);
|
|
}
|
|
// Lubrorefrigeranti
|
|
vettLubro = new Lubro[adpConf.nLubro];
|
|
for (int i = 0; i < adpConf.nLubro; i++)
|
|
{
|
|
vettLubro[i] = new Lubro(adpConf.Lubro[i]);
|
|
//mAdapter.AddDataItem(vettLubro[i].mLubroAlias);
|
|
mAdapter.AddDataItem(vettLubro[i].mLubroNum);
|
|
mAdapter.AddDataItem(vettLubro[i].mLubroStatus);
|
|
}
|
|
// Cooler
|
|
vettCooler = new Cooler[adpConf.nCooler];
|
|
for (int i = 0; i < adpConf.nCooler; i++)
|
|
{
|
|
vettCooler[i] = new Cooler(adpConf.Cooler[i]);
|
|
//mAdapter.AddDataItem(vettCooler[i].mCoolAlias);
|
|
mAdapter.AddDataItem(vettCooler[i].mCoolStatus);
|
|
}
|
|
// Press
|
|
vettPress = new Press[adpConf.nPress];
|
|
for (int i = 0; i < adpConf.nPress; i++)
|
|
{
|
|
vettPress[i] = new Press(adpConf.Press[i]);
|
|
//mAdapter.AddDataItem(vettPress[i].mPressAlias);
|
|
mAdapter.AddDataItem(vettPress[i].mPressValIst);
|
|
}
|
|
// Temp
|
|
vettTempe = new Tempe[adpConf.nTemp];
|
|
for (int i = 0; i < adpConf.nTemp; i++)
|
|
{
|
|
vettTempe[i] = new Tempe(adpConf.Temp[i]);
|
|
//mAdapter.AddDataItem(vettTempe[i].mTempAlias);
|
|
mAdapter.AddDataItem(vettTempe[i].mTempValIst);
|
|
}
|
|
// Path
|
|
vettPath = new Path[adpConf.nPath];
|
|
for (int i = 0; i < adpConf.nPath; i++)
|
|
{
|
|
vettPath[i] = new Path(adpConf.Path[i]);
|
|
mAdapter.AddDataItem(vettPath[i].mPathAlias);
|
|
mAdapter.AddDataItem(vettPath[i].mPathFeed);
|
|
mAdapter.AddDataItem(vettPath[i].mPathFeedOver);
|
|
mAdapter.AddDataItem(vettPath[i].mPathRapidOver);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActX);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActY);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActZ);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActI);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActJ);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPosActK);
|
|
// aggiunta x revisione 2016.05.05
|
|
mAdapter.AddDataItem(vettPath[i].mPathType);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPartId);
|
|
mAdapter.AddDataItem(vettPath[i].mPathPartCount);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCodM);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCodS);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCodT);
|
|
mAdapter.AddDataItem(vettPath[i].mPathRunMode);
|
|
mAdapter.AddDataItem(vettPath[i].mPathExeMode);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCurrProg);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCurrProgRowNum);
|
|
mAdapter.AddDataItem(vettPath[i].mPathActiveAxes);
|
|
mAdapter.AddDataItem(vettPath[i].mPathCodG_Act);
|
|
mAdapter.AddDataItem(vettPath[i].mPathSubMode);
|
|
// aggiungo condizioni allarme...
|
|
mAdapter.AddDataItem(vettPath[i].mPathAlarmCNC);
|
|
mAdapter.AddDataItem(vettPath[i].mPathAlarmPLC);
|
|
// altre aggiunte
|
|
}
|
|
// UnOp
|
|
vettUnOp = new UnOp[adpConf.nUnOp];
|
|
for (int i = 0; i < adpConf.nUnOp; i++)
|
|
{
|
|
vettUnOp[i] = new UnOp(adpConf.UnOp[i]);
|
|
//mAdapter.AddDataItem(vettUnOp[i].mUnOpAlias);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpToolId);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpNumCU);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpStatus);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpVitaRes);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpVitaResType);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpSpeed);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpSpeedOverr);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpLoad);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpAccTime);
|
|
mAdapter.AddDataItem(vettUnOp[i].mUnOpKRev);
|
|
}
|
|
// Assi
|
|
vettAxis = new Axis[adpConf.nAxis];
|
|
for (int i = 0; i < adpConf.nAxis; i++)
|
|
{
|
|
vettAxis[i] = new Axis(adpConf.Axis[i]);
|
|
//mAdapter.AddDataItem(vettAxis[i].mAxAlias);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxMainProc);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxIsMaster);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxMastId);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxType);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxDir);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxLoad);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxPosAct);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxPosTgt);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxFeedAct);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxFeedOver);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxAccelAct);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxAccTime);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxBattery);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxDistDone);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxInvDDone);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxAlarmCNC);
|
|
mAdapter.AddDataItem(vettAxis[i].mAxAlarmPLC);
|
|
}
|
|
|
|
|
|
|
|
// messaggi ulteriori
|
|
mAdapter.AddDataItem(mMessage);
|
|
|
|
// allarmi "base"
|
|
//mAdapter.AddDataItem(mAlarmSystem);
|
|
mAdapter.AddDataItem(mAlarmCNC);
|
|
mAdapter.AddDataItem(mAlarmPLC);
|
|
//mAdapter.AddDataItem(mAlarmHMI);
|
|
//mAdapter.AddDataItem(mAlarmGeneral);
|
|
|
|
|
|
|
|
// azioni utente
|
|
mAdapter.AddDataItem(mUserAction);
|
|
|
|
// concluso!
|
|
lg.Info("Istanziata classe AdapterGeneric");
|
|
}
|
|
/// <summary>
|
|
/// caricamento allarmi da file
|
|
/// </summary>
|
|
protected void loadAllarmi()
|
|
{
|
|
if (utils.CRB("verbose")) lg.Info("Inizio caricamento vettore allarmi");
|
|
int totRighe = 0;
|
|
string fileName = string.Format(@"{0}\{1}", utils.confDir, utils.CRS("AlarmList"));
|
|
string linea;
|
|
totRighe = File.ReadLines(fileName).Count();
|
|
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
|
|
elencoAllarmi = new allarme[File.ReadLines(fileName).Count()];
|
|
// carica da file...
|
|
System.IO.StreamReader file = new System.IO.StreamReader(fileName);
|
|
// leggo 1 linea alla volta...
|
|
int rumRiga = 0;
|
|
while ((linea = file.ReadLine()) != null)
|
|
{
|
|
// SE non è un commento...
|
|
if (linea.Substring(0, 1) != "#")
|
|
{
|
|
//elencoAllarmi[rumRiga] = decodeAlarmLine(linea, ':');
|
|
elencoAllarmi[rumRiga] = decodeAlarmLine(linea, utils.CRC("testCharSep"));
|
|
rumRiga++;
|
|
}
|
|
}
|
|
// chiudo file
|
|
file.Close();
|
|
// ora trimmo vettore al solo numero VERO degli allarmi caricati...
|
|
Array.Resize<allarme>(ref elencoAllarmi, rumRiga);
|
|
|
|
// inizializzo a zero il vettore allarmi...
|
|
int numByte = (int)Math.Ceiling(Convert.ToDecimal(rumRiga) / 8);
|
|
// 2016.07.20: dimensione AlarmFlags è la MAX tra quella del numero allarmi ed il numero allarmi standard dalla memoria...
|
|
if (numByte < 32) numByte = 32;
|
|
AlarmFlags = new byte[numByte];
|
|
if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore allarmi: {0} allarmi caricati!", rumRiga));
|
|
}
|
|
/// <summary>
|
|
/// Caricamento altri file necessari epr adapter all'avvio
|
|
/// </summary>
|
|
protected virtual void loadOtherFile()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// caricamento allarmi da file
|
|
/// </summary>
|
|
protected void loadSubMode()
|
|
{
|
|
if (utils.CRB("verbose")) lg.Info("Inizio caricamento vettore SubMode");
|
|
int totRighe = 0;
|
|
string fileName = string.Format(@"{0}\{1}", utils.confDir, utils.CRS("SubModeListFilePath"));
|
|
string linea;
|
|
totRighe = File.ReadLines(fileName).Count();
|
|
// inizializzo
|
|
elencoSubMode = new Dictionary<string, string>();
|
|
// carica da file...
|
|
StreamReader file = new StreamReader(fileName);
|
|
// leggo 1 linea alla volta...
|
|
string[] valori;
|
|
while ((linea = file.ReadLine()) != null)
|
|
{
|
|
// SE non è un commento...
|
|
if (linea.Substring(0, 1) != "#")
|
|
{
|
|
valori = linea.Split(':');
|
|
elencoSubMode.Add(valori[0], valori[1]);
|
|
}
|
|
}
|
|
// chiudo file
|
|
file.Close();
|
|
if (utils.CRB("verbose")) lg.Info("Fine caricamento vettore SubMode");
|
|
}
|
|
/// <summary>
|
|
/// Decodifica file allarme
|
|
/// </summary>
|
|
/// <param name="linea"></param>
|
|
/// <param name="separator"></param>
|
|
/// <returns></returns>
|
|
protected allarme decodeAlarmLine(string linea, char separator)
|
|
{
|
|
string[] valori = linea.Split(separator);
|
|
return new allarme(valori[0], valori[1], valori[2], valori[3]);
|
|
}
|
|
/// <summary>
|
|
/// Decodifica file datiProdSCM
|
|
/// </summary>
|
|
/// <param name="linea"></param>
|
|
/// <param name="separator"></param>
|
|
/// <returns></returns>
|
|
protected datiProdSCM decodeScmProdLine(string linea, char separator)
|
|
{
|
|
string[] valori = linea.Split(separator);
|
|
datiProdSCM answ = null;
|
|
if (valori.Length == 23)
|
|
{
|
|
answ = new MTC_Adapter.datiProdSCM(valori);
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Decodifica file allarme
|
|
/// </summary>
|
|
/// <param name="linea"></param>
|
|
/// <param name="separator"></param>
|
|
/// <param name="memPre">tipo memoria (R/D/...)</param>
|
|
/// <param name="baseAddr">indirizzo di partenza memoria</param>
|
|
/// <param name="memSize">dimensione singolo slot in byte</param>
|
|
/// <returns></returns>
|
|
protected otherData decodeOtherData(string linea, char separator, string memPre, int baseAddr, int memSize)
|
|
{
|
|
string[] valori = linea.Split(separator);
|
|
int shift = 0;
|
|
try
|
|
{
|
|
shift = Convert.ToInt32(valori[0]) - 1;
|
|
}
|
|
catch
|
|
{ }
|
|
string memAddr = string.Format("{0}{1}", memPre, baseAddr + shift * memSize);
|
|
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
|
|
}
|
|
/// <summary>
|
|
/// Decodifica file MAP
|
|
/// </summary>
|
|
/// <param name="linea"></param>
|
|
/// <param name="separator"></param>
|
|
/// <param name="memPre">tipo memoria (R/D/...)</param>
|
|
/// <param name="baseAddr">indirizzo di partenza memoria</param>
|
|
/// <param name="memSize">dimensione singolo slot in byte</param>
|
|
/// <param name="numRiga">numero riga x calcolo indice bit</param>
|
|
/// <returns></returns>
|
|
protected otherData decodeBitData(string linea, char separator, string memPre, int baseAddr, int memSize, int numRiga)
|
|
{
|
|
string[] valori = linea.Split(separator);
|
|
int shift = 0;
|
|
try
|
|
{
|
|
shift = Convert.ToInt32(valori[0]) - 1;
|
|
}
|
|
catch
|
|
{ }
|
|
int resto = 0;
|
|
Math.DivRem(numRiga, 8, out resto);
|
|
string memAddr = string.Format("{0}{1}.{2}", memPre, baseAddr + shift * memSize, resto);
|
|
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
|
|
}
|
|
|
|
#region metodi adapter
|
|
|
|
public void loadPersData()
|
|
{
|
|
// nuova lettura valori da file persistenza...
|
|
contOreMaccOn = getStoredValDouble("ACC_TIME");
|
|
contOreMaccLav = getStoredValDouble("ACC_TIME_WORK");
|
|
|
|
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
|
{
|
|
contGiriElettrom[i] = getStoredValUInt(string.Format("UnOp_{0:00}_AccTime", i + 1));
|
|
currNumCambiUt[i] = getStoredValUInt(string.Format("UnOp_{0:00}_NumCU", i + 1));
|
|
}
|
|
|
|
for (int i = 0; i < currAdpConf.nAxis; i++)
|
|
{
|
|
contDistMovAssi[i] = getStoredValUInt(string.Format("Axis_{0:00}_DistDone", i + 1));
|
|
contNumInvAssi[i] = getStoredValUInt(string.Format("Axis_{0:00}_InvDDone", i + 1));
|
|
contAccTimeAssi[i] = getStoredValDouble(string.Format("Axis_{0:00}_AccTime", i + 1));
|
|
}
|
|
|
|
for (int i = 0; i < currAdpConf.nVacuumPump; i++)
|
|
{
|
|
currVacPumpWrkTime[i] = getStoredValUInt(string.Format("VacPump_{0:00}_WrkTime", i + 1));
|
|
}
|
|
|
|
for (int i = 0; i < currAdpConf.nVacuumAct; i++)
|
|
{
|
|
currVacActCount[i] = getStoredValUInt(string.Format("VacAct_{0:00}_Count", i + 1));
|
|
}
|
|
|
|
for (int i = 0; i < currAdpConf.nLubro; i++)
|
|
{
|
|
currLubroCount[i] = getStoredValUInt(string.Format("Lubro_{0:00}_Count", i + 1));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Avvia l'adapter sulla porta richiesta
|
|
/// </summary>
|
|
/// <param name="port"></param>
|
|
public virtual void startAdapter(int port)
|
|
{
|
|
lg.Info("Starting adapter...");
|
|
adpRunning = true;
|
|
dtAvvioAdp = DateTime.Now;
|
|
// inizializzo vettori di utility..
|
|
loadAllarmi();
|
|
loadSubMode();
|
|
loadOtherFile();
|
|
|
|
// salvo porta!
|
|
mAdapter.Port = port;
|
|
adpPortNum = port;
|
|
// avvio!
|
|
mAdapter.Start();
|
|
|
|
// setto status a ON
|
|
mStatus.Value = "ON";
|
|
|
|
// resetto running flag...
|
|
adpCommAct = false;
|
|
|
|
// carico valori da adapter x i conteggi
|
|
contOreMaccOn = currAdpConf.ContOreMaccOn;
|
|
contOreMaccLav = currAdpConf.ContOreMaccLav;
|
|
contGiriElettrom = new uint[currAdpConf.nUnOp];
|
|
istGiriElettrom = new uint[currAdpConf.nUnOp];
|
|
currNumCambiUt = new uint[currAdpConf.nUnOp];
|
|
istNumCambiUt = new uint[currAdpConf.nUnOp];
|
|
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.UnOp[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riContRpm = listaDR.Find(x => x.Key == string.Format("UnOp_{0:00}_AccTime", i + 1));
|
|
DataRefItem<string, string> riContNumCU = listaDR.Find(x => x.Key == string.Format("UnOp_{0:00}_NumCU", i + 1));
|
|
// recupero valore giri...
|
|
UInt32 contTotGiri = Convert.ToUInt32(riContRpm.Value);
|
|
// recupero valore num cambi ut...
|
|
UInt32 contNumCU = Convert.ToUInt32(riContNumCU.Value);
|
|
// salvo valore letto
|
|
contGiriElettrom[i] = contTotGiri;
|
|
currNumCambiUt[i] = contNumCU;
|
|
}
|
|
// imposto num assi e leggo valori salvati...
|
|
contDistMovAssi = new double[currAdpConf.nAxis];
|
|
istDistMovAssi = new double[currAdpConf.nAxis];
|
|
contNumInvAssi = new uint[currAdpConf.nAxis];
|
|
istAccTimeAssi = new double[currAdpConf.nAxis];
|
|
contAccTimeAssi = new double[currAdpConf.nAxis];
|
|
istNumInvAssi = new uint[currAdpConf.nAxis];
|
|
lastChekAccumTimeAxis = DateTime.Now;
|
|
for (int i = 0; i < currAdpConf.nAxis; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.Axis[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riContDist = listaDR.Find(x => x.Key == string.Format("Axis_{0:00}_DistDone", i + 1));
|
|
DataRefItem<string, string> riNumInv = listaDR.Find(x => x.Key == string.Format("Axis_{0:00}_Invers", i + 1));
|
|
DataRefItem<string, string> riAccTime = listaDR.Find(x => x.Key == string.Format("Axis_{0:00}_AccTime", i + 1));
|
|
// recupero valori...
|
|
contDistMovAssi[i] = Convert.ToUInt32(riContDist.Value);
|
|
contNumInvAssi[i] = Convert.ToUInt32(riNumInv.Value);
|
|
contAccTimeAssi[i] = Convert.ToDouble(riAccTime.Value);
|
|
vettAxis[i].mAxAlarmCNC.Normal();
|
|
vettAxis[i].mAxAlarmPLC.Normal();
|
|
|
|
}
|
|
currPathPartId = new string[currAdpConf.nPath];
|
|
istPathPartId = new string[currAdpConf.nPath];
|
|
currPathProgrName = new string[currAdpConf.nPath];
|
|
istPathProgrName = new string[currAdpConf.nPath];
|
|
currPathPartCount = new uint[currAdpConf.nPath];
|
|
istPathPartCount = new uint[currAdpConf.nPath];
|
|
for (int i = 0; i < currAdpConf.nPath; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.Path[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riPathProgr = listaDR.Find(x => x.Key == string.Format("Path_{0:00}_PartId", i + 1));
|
|
DataRefItem<string, string> riPathPzTot = listaDR.Find(x => x.Key == string.Format("Path_{0:00}_PZ_TOT", i + 1));
|
|
// recupero valori...
|
|
currPathPartId[i] = riPathProgr.Value;
|
|
currPathPartCount[i] = Convert.ToUInt32(riPathPzTot.Value);
|
|
currPathProgrName[i] = "";
|
|
vettPath[i].mPathAlarmCNC.Normal();
|
|
vettPath[i].mPathAlarmPLC.Normal();
|
|
}
|
|
currVacPumpWrkTime = new uint[currAdpConf.nVacuumPump];
|
|
istVacPumpWrkTime = new uint[currAdpConf.nVacuumPump];
|
|
for (int i = 0; i < currAdpConf.nVacuumPump; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.VacuumPump[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riVacPumpWrk = listaDR.Find(x => x.Key == string.Format("VacPump_{0:00}_WrkTime", i + 1));
|
|
// recupero valori...
|
|
currVacPumpWrkTime[i] = Convert.ToUInt32(riVacPumpWrk.Value);
|
|
}
|
|
currVacActCount = new uint[currAdpConf.nVacuumAct];
|
|
istVacActCount = new uint[currAdpConf.nVacuumAct];
|
|
for (int i = 0; i < currAdpConf.nVacuumAct; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.VacuumAct[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riVacActCount = listaDR.Find(x => x.Key == string.Format("VacAct_{0:00}_Count", i + 1));
|
|
// recupero valori...
|
|
currVacActCount[i] = Convert.ToUInt32(riVacActCount.Value);
|
|
}
|
|
currLubroCount = new uint[currAdpConf.nLubro];
|
|
istLubroCount = new uint[currAdpConf.nLubro];
|
|
for (int i = 0; i < currAdpConf.nLubro; i++)
|
|
{
|
|
// leggo tutti i dati...
|
|
List<DataRefItem<string, string>> listaDR = currAdpConf.Lubro[i].dataRefList;
|
|
// punto all'item
|
|
DataRefItem<string, string> riLubro = listaDR.Find(x => x.Key == string.Format("Lubro_{0:00}_Count", i + 1));
|
|
// recupero valori...
|
|
currLubroCount[i] = Convert.ToUInt32(riLubro.Value);
|
|
}
|
|
|
|
//mAlarmSystem.Normal();
|
|
mAlarmCNC.Normal();
|
|
mAlarmPLC.Normal();
|
|
//mAlarmGeneral.Normal();
|
|
adpTryRestart = true;
|
|
parentForm.displayTaskAndWait("Adapter Started!");
|
|
}
|
|
/// <summary>
|
|
/// Effettua refresh del vettore privato degli allarmi attivi
|
|
/// </summary>
|
|
/// <param name="Alarm2Refresh">flag mask degli allarmi da aggiornare</param>
|
|
/// <param name="giveAck">boolean: se si debba tornare ACK</param>
|
|
public virtual void refreshAlarmState(StFlag32 Alarm2Refresh, bool giveAck)
|
|
{
|
|
// carico lo stato di tutti gli allarmi... forzo a 1 il flag degli allarmi
|
|
}
|
|
|
|
/// <summary>
|
|
/// ferma l'adapter...
|
|
/// </summary>
|
|
/// <param name="tryRestart">indica se si debba tentare di riavviare l'adapter (con caduta connessione viene fermato in automatico)</param>
|
|
public void stopAdapter(bool tryRestart)
|
|
{
|
|
parentForm.displayTaskAndWait("Stopping adapter...");
|
|
adpTryRestart = false;
|
|
mStatus.Value = "INACTIVE";
|
|
// faccio una chiamata extra ad ogni metodo di check...
|
|
gaterAndSend(gatherCycle.HF);
|
|
gaterAndSend(gatherCycle.MF);
|
|
gaterAndSend(gatherCycle.LF);
|
|
gaterAndSend(gatherCycle.VLF);
|
|
parentForm.displayTaskAndWait("Stopping adapter - last periodic data read...");
|
|
|
|
// chiudo la connessione all'adapter...
|
|
tryDisconnect();
|
|
// Stop everything...
|
|
try
|
|
{
|
|
mAdapter.Stop();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error(exc, "Eccezione in chiusura Adapter");
|
|
}
|
|
dtStopAdp = DateTime.Now;
|
|
adpPortNum = mAdapter.Port;
|
|
adpTryRestart = tryRestart;
|
|
adpRunning = false;
|
|
// chiudo!
|
|
parentForm.resetProgBar();
|
|
parentForm.dataMonitor = "... not connected, waiting for data ...";
|
|
parentForm.displayTaskAndWait("Adapter Stopped.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua recupero dati ed invio valori modificati...
|
|
/// </summary>
|
|
/// <param name="ciclo"></param>
|
|
public void gaterAndSend(gatherCycle ciclo)
|
|
{
|
|
// controllo connessione/connettività
|
|
if (connectionOk)
|
|
{
|
|
// controllo non sia già in esecuzione...
|
|
if (!adpCommAct)
|
|
{
|
|
// provo ad avviare
|
|
try
|
|
{
|
|
// avvio fase raccolta dati
|
|
mAdapter.Begin();
|
|
// imposto flag adapter running..
|
|
adpCommAct = true;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
parentForm.displayTaskAndWait(string.Format("Adapter NOT STARTED!!!{0}{1}", Environment.NewLine, exc));
|
|
adpCommAct = false;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
if (adpCommAct)
|
|
{
|
|
// try / catch generale altrimenti segno che è disconnesso...
|
|
try
|
|
{
|
|
// processing degli strobes di allarme (da ULTIMA rappresentazione vettore dell'ADP)
|
|
processAlarm();
|
|
|
|
// verifico se processare tutto "in un colpo solo"
|
|
if (procIotMem)
|
|
{
|
|
processAllMemory();
|
|
// ciclo lento x log...
|
|
if (ciclo == gatherCycle.LF)
|
|
{
|
|
// eventuale log!
|
|
if (utils.CRB("recTime")) logTimeResults();
|
|
}
|
|
// ciclo lentissimo
|
|
else if (ciclo == gatherCycle.VLF)
|
|
{
|
|
lg.Info("Richiesta lettura completa allarmi attivi");
|
|
// faccio comunque rilettura completa allarmi...
|
|
forceAlarmCheck();
|
|
}
|
|
}
|
|
// oppure in "modalità classica" con multistep...
|
|
else
|
|
{
|
|
// ciclo HF: recupero update status & strobes vari
|
|
if (ciclo == gatherCycle.HF)
|
|
{
|
|
// parte che eseguo SEMPRE: RECUPERO stato di tutti gli strobe/status e degli ack attualmente noti
|
|
getStrobeAndAckStatus();
|
|
|
|
// faccio refresh degli allarmi segnalati (da strobe su vettore locale)
|
|
refreshAlarmState(STRB_DW0, true);
|
|
// acquisizione degli status
|
|
processStatus();
|
|
// processing degli strobes
|
|
processStrobe();
|
|
}
|
|
else if (ciclo == gatherCycle.MF)
|
|
{
|
|
// leggo parametri a media freq (dati globali, path, assi, Unità Operatrice)
|
|
getGlobalData();
|
|
getUnOp();
|
|
getPath();
|
|
getAxis();
|
|
}
|
|
// ciclo lento
|
|
else if (ciclo == gatherCycle.LF)
|
|
{
|
|
// leggo EVENTUALI parametri da config file
|
|
getConfigParam();
|
|
///acquisisco dati su programma in esecuzione e dati generali (stato, orologio, power...)
|
|
getSlowChangingData();
|
|
|
|
// eventuale log!
|
|
if (utils.CRB("recTime")) logTimeResults();
|
|
}
|
|
// ciclo lentissimo
|
|
else if (ciclo == gatherCycle.VLF)
|
|
{
|
|
lg.Info("Richiesta lettura completa allarmi attivi");
|
|
// faccio comunque rilettura completa allarmi...
|
|
forceAlarmCheck();
|
|
}
|
|
}
|
|
|
|
// processo e svuoto eventuali code di invio per Codici M/S/T
|
|
trySendCodMST();
|
|
|
|
// INVIO dati variati!
|
|
mAdapter.SendChanged();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
// segnalo eccezione e indico disconnesso...
|
|
lg.Error(exc, "Errore in gestione ciclo principale ADP, fermo adapter");
|
|
parentForm.fermaAdapter(true);
|
|
}
|
|
// tolgo flag running
|
|
adpCommAct = false;
|
|
}
|
|
else
|
|
{
|
|
lg.Info("ADP not running...");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// log ADP running
|
|
lg.Error("Non eseguo chiamata: ADP ancora in running");
|
|
// se è bloccato da oltre maxSec lo sblocco...
|
|
if (DateTime.Now.Subtract(adpStartRun).TotalSeconds > utils.CRI("maxAdapterLockSec"))
|
|
{
|
|
// tolgo flag running
|
|
adpCommAct = false;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// log connessione KO
|
|
lg.Error("CicloMF - Connessione non disponibile, provo a riconnettere");
|
|
// provo a riconnettere SE abilitato tryRestart...
|
|
if (adpTryRestart && !connectionOk)
|
|
{
|
|
//// aspetto un tempo di wait adatto
|
|
//Thread.Sleep(utils.CRI("waitRecMSec"));
|
|
tryConnect();
|
|
}
|
|
}
|
|
if (eh_refreshed != null)
|
|
{
|
|
eh_refreshed(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupero dati globali (e comuni)
|
|
/// </summary>
|
|
public virtual void getGlobalData()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// riporta il log di tutti i dati di results temporali registrati
|
|
/// </summary>
|
|
public void logTimeResults()
|
|
{
|
|
if (TimingData.results.Count > 0)
|
|
{
|
|
lg.Info("{0}--------------- START TIMING DATA ---------------", Environment.NewLine);
|
|
int globNumCall = 0;
|
|
TimeSpan globAvgMsec = new TimeSpan(0);
|
|
foreach (TimeRec item in TimingData.results)
|
|
{
|
|
lg.Info("Chiamate {0}: effettuate {1}, tempo medio {2:N2} msec", item.codCall, item.numCall, item.avgMsec);
|
|
globNumCall += item.numCall;
|
|
globAvgMsec += item.totMsec;
|
|
}
|
|
// riporto conteggio medio al secondo...
|
|
lg.Info("Chiamate GLOBALI: {0}, periodo: {1:N2} minuti.cent, tempo medio {2:N2} msec, impegno MEDIO del canale {3:P3}", globNumCall, DateTime.Now.Subtract(dtAvvioAdp).TotalMinutes, globAvgMsec.TotalMilliseconds / globNumCall, globAvgMsec.TotalSeconds / DateTime.Now.Subtract(dtAvvioAdp).TotalSeconds);
|
|
lg.Info("{0}--------------- STOP TIMING DATA ---------------{0}", Environment.NewLine);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifico se ho dati M/S/T e li invio nel caso
|
|
/// </summary>
|
|
public virtual void trySendCodMST()
|
|
{
|
|
// !!!FARE!!! ciclo su + path
|
|
int idxPath = 1;
|
|
for (int i = 0; i < idxPath; i++)
|
|
{
|
|
// verifico SE ho codici M/S/T da inviare...
|
|
string codiceM = getNextMCode;
|
|
string codiceS = getNextSCode;
|
|
string codiceT = getNextTCode;
|
|
if (codiceM != "")
|
|
{
|
|
//vettPath[i].mPathCodM.Code = string.Format("[M{0}]", codiceM);
|
|
vettPath[i].mPathCodM.Value = string.Format("[M{0}]", codiceM);
|
|
//vettPath[i].mPathCodM.ForceChanged();
|
|
mMessage.Code = string.Format("[M{0}]", codiceM);
|
|
mMessage.Value = string.Format("[M{0}]", codiceM);
|
|
}
|
|
if (codiceS != "")
|
|
{
|
|
vettPath[i].mPathCodS.Value = string.Format("[S{0}]", codiceS);
|
|
//vettPath[i].mPathCodS.ForceChanged();
|
|
mMessage.Code = string.Format("[S{0}]", codiceS);
|
|
mMessage.Value = string.Format("[S{0}]", codiceS);
|
|
}
|
|
if (codiceT != "")
|
|
{
|
|
vettPath[i].mPathCodT.Value = string.Format("[T{0}]", codiceT);
|
|
//vettPath[i].mPathCodT.ForceChanged();
|
|
mMessage.Code = string.Format("[T{0}]", codiceT);
|
|
mMessage.Value = string.Format("[T{0}]", codiceT);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Metodo base connessione...
|
|
/// </summary>
|
|
public virtual void tryConnect()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// Metodo base disconnessione...
|
|
/// </summary>
|
|
public virtual void tryDisconnect()
|
|
{
|
|
|
|
}
|
|
protected bool _connOk = false;
|
|
/// <summary>
|
|
/// Salva verifica stato connessione OK
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual bool connectionOk
|
|
{
|
|
get
|
|
{
|
|
return _connOk;
|
|
}
|
|
set
|
|
{
|
|
_connOk = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua ogni log period una rilettura di TUTTI gli allarmi...
|
|
/// </summary>
|
|
public virtual void forceAlarmCheck()
|
|
{
|
|
// carico status allarmi (completo)
|
|
StFlag32 forceAlarm = (StFlag32)unchecked((int)UInt32.MaxValue);
|
|
try
|
|
{
|
|
refreshAlarmState(forceAlarm, false);
|
|
}
|
|
catch
|
|
{
|
|
lg.Error("Errore in fase di esecuzione di forceAlarmCheck");
|
|
}
|
|
if (utils.CRB("recTime")) logTimeResults();
|
|
}
|
|
/// <summary>
|
|
/// recupero dati PATH
|
|
/// </summary>
|
|
public virtual void getPath()
|
|
{
|
|
// SE presente recupero dati path
|
|
checkPath();
|
|
|
|
// dati BASE, ciclando su path
|
|
for (int i = 0; i < currAdpConf.nPath; i++)
|
|
{
|
|
vettPath[i].mPathFeed.Value = FeedRate;
|
|
vettPath[i].mPathFeedOver.Value = FeedRateOver;
|
|
vettPath[i].mPathRapidOver.Value = RapidOver;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Recupero dati Unità Operatrici / Mandrini
|
|
/// </summary>
|
|
public virtual void getUnOp()
|
|
{
|
|
// cicl su UnOp
|
|
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
|
{
|
|
vettUnOp[i].mUnOpSpeed.Value = SpeedRate;
|
|
vettUnOp[i].mUnOpSpeedOverr.Value = SpeedRateOver;
|
|
vettUnOp[i].mUnOpLoad.Value = UnOpLoad;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupero dati ASSI
|
|
/// </summary>
|
|
public virtual void getAxis()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// verifica gli status attivi
|
|
/// </summary>
|
|
public virtual void processStatus()
|
|
{
|
|
// da gestire su ogni adapter...
|
|
}
|
|
/// <summary>
|
|
/// processo tutti gli strobe attivi
|
|
/// </summary>
|
|
public virtual void processStrobe()
|
|
{
|
|
// da gestire su ogni adapter...
|
|
}
|
|
/// <summary>
|
|
/// processo il vettore LOCALE degli allarmi
|
|
/// </summary>
|
|
public virtual void processAlarm()
|
|
{
|
|
if (AlarmFlags != null)
|
|
{
|
|
// variabili helper
|
|
StFlag32 AlarmBlock = 0;
|
|
allarme currAllarm;
|
|
// controllo TUTTI i bit della variabile COMPLETA degli status allarmi: se ce ne sono di alzati DEVO processare...
|
|
for (int i = 0; i < AlarmFlags.Length / 4; i++)
|
|
{
|
|
// leggo 32bit alla volta...
|
|
AlarmBlock = (StFlag32)BitConverter.ToUInt32(AlarmFlags, i * 4);
|
|
|
|
for (int j = 0; j < 32; j++)
|
|
{
|
|
// converto! e aggiungo allarmi sollevati al corretto controller allarmi...
|
|
if (AlarmBlock.HasFlag((StFlag32)Math.Pow(2, j)))
|
|
{
|
|
// recupero allarme da oggetto in memoria...
|
|
currAllarm = elencoAllarmi[i * 32 + j];
|
|
// in base al tipo di allarme decodifico condizione...
|
|
Condition.Level livello = Condition.Level.NORMAL;
|
|
switch (currAllarm.livello)
|
|
{
|
|
case "WARNING":
|
|
livello = Condition.Level.WARNING;
|
|
break;
|
|
case "FAULT":
|
|
default:
|
|
livello = Condition.Level.FAULT;
|
|
break;
|
|
}
|
|
// in base al gruppo decido dove assegnare come CONDITION...
|
|
switch (currAllarm.gruppo)
|
|
{
|
|
case "PLC":
|
|
mAlarmPLC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
case "CNC":
|
|
default:
|
|
mAlarmCNC.Add(livello, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Classe fittizia in caso di processing GLOBALE di tutto in 1 solo colpo...
|
|
/// </summary>
|
|
public virtual void processAllMemory()
|
|
{ }
|
|
/// <summary>
|
|
/// metodo di recupero dei dati di identificativo macchina - DA CONF!!!
|
|
/// </summary>
|
|
public virtual void getConfigParam()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// dati "lenti" relativi al device
|
|
/// </summary>
|
|
public virtual void getSlowChangingData()
|
|
{
|
|
// dati da PC
|
|
mClock.Value = string.Format("{0:yyyy-MM-dd} {0:HH:mm:ss}", DateTime.Now);
|
|
// da gestire su ogni adapter...
|
|
}
|
|
/// <summary>
|
|
/// recupero di TUTTI gli strobes/status attivi
|
|
/// </summary>
|
|
public virtual void getStrobeAndAckStatus()
|
|
{
|
|
// da gestire su ogni adapter... legge tutto array STROBE!!!
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region area metodi comunicazione con PLC/CNC
|
|
|
|
public void checkPath()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// FeedRate globale
|
|
/// </summary>
|
|
public int FeedRate { get; set; }
|
|
/// <summary>
|
|
/// SpeedRate mandrino globale
|
|
/// </summary>
|
|
public int SpeedRate { get; set; }
|
|
|
|
/// <summary>
|
|
/// OVERRIDE FeedRate globale
|
|
/// </summary>
|
|
public int FeedRateOver { get; set; }
|
|
/// <summary>
|
|
/// Override dei rapidi
|
|
/// </summary>
|
|
public int RapidOver { get; set; }
|
|
/// <summary>
|
|
/// OVERRIDE SpeedRate mandrino globale
|
|
/// </summary>
|
|
public int SpeedRateOver { get; set; }
|
|
/// <summary>
|
|
/// LOAD mandrino globale
|
|
/// </summary>
|
|
public int UnOpLoad { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// recupera Vettore completo PosAct (fare override!)
|
|
/// </summary>
|
|
public virtual position PosAct
|
|
{
|
|
get
|
|
{
|
|
position answ = new position();
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera pezzi OK (fare override!)
|
|
/// </summary>
|
|
public virtual int getNumPzOk
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupera pezzi KO (fare override!)
|
|
/// </summary>
|
|
public virtual int getNumPzKo
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunge nel vettore coda codici M
|
|
/// </summary>
|
|
/// <param name="Coda"></param>
|
|
/// <param name="Codice da accodare"></param>
|
|
public void appendCodeMST(string Coda, string Codice)
|
|
{
|
|
switch (Coda)
|
|
{
|
|
case "S":
|
|
codaS.Add(Codice);
|
|
break;
|
|
case "T":
|
|
codaT.Add(Codice);
|
|
break;
|
|
case "M":
|
|
default:
|
|
codaM.Add(Codice);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera primo elemento codaM
|
|
/// </summary>
|
|
protected string getNextMCode
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (codaM.Count > 0)
|
|
{
|
|
// recupero codice M...
|
|
answ = codaM.First();
|
|
// tolgo elemento
|
|
codaM.RemoveAt(0);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupera primo elemento codaS
|
|
/// </summary>
|
|
protected string getNextSCode
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (codaS.Count > 0)
|
|
{
|
|
// recupero codice S...
|
|
answ = codaS.First();
|
|
// tolgo elemento
|
|
codaS.RemoveAt(0);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupera primo elemento codaT
|
|
/// </summary>
|
|
protected string getNextTCode
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (codaT.Count > 0)
|
|
{
|
|
// recupero codice T...
|
|
answ = codaT.First();
|
|
// tolgo elemento
|
|
codaT.RemoveAt(0);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region metodi che prevedono salvataggio valori su file XML/BIN
|
|
|
|
/// <summary>
|
|
/// Processing delle ore macchina ACCESA
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procOreMaccOn(bool needSave)
|
|
{
|
|
double delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istOreMaccOn > contOreMaccOn)
|
|
{
|
|
delta = istOreMaccOn - contOreMaccOn;
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
double contatore = updateValDoubleByIncr(0, delta, "ACC_TIME");
|
|
currAdpConf.ContOreMaccOn += delta;
|
|
// salvo valore su persistent layer
|
|
mAccTime.Value = contatore.ToString("0.000", CultureInfo.InvariantCulture);
|
|
|
|
// ...aggiorno valore riferimento...
|
|
contOreMaccOn = istOreMaccOn;
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle ore macchina IN LAVORO
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procOreMaccLav(bool needSave)
|
|
{
|
|
double delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istOreMaccLav > contOreMaccLav)
|
|
{
|
|
delta = istOreMaccLav - contOreMaccLav;
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
double contatore = updateValDoubleByIncr(0, delta, "ACC_TIME_WORK");
|
|
currAdpConf.ContOreMaccLav += delta;
|
|
// salvo valore su persistent layer
|
|
mAccTimeWork.Value = contatore.ToString("0.000", CultureInfo.InvariantCulture);
|
|
|
|
// ...aggiorno valore riferimento...
|
|
contOreMaccLav = istOreMaccLav;
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing del program nme
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procProgrName(bool needSave)
|
|
{
|
|
// controllo valore riferimento x tutti i path se sia cambiato num pz...
|
|
for (int i = 0; i < currAdpConf.nPath; i++)
|
|
{
|
|
if (istPathProgrName[i] != null)
|
|
{
|
|
if (istPathProgrName[i] != currPathProgrName[i])
|
|
{
|
|
// prendo nuovo valore programma x path!
|
|
vettPath[i].mPathCurrProg.Value = istPathProgrName[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
// ...aggiorno valore riferimento...
|
|
currPathProgrName[i] = istPathProgrName[i];
|
|
}
|
|
}
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing del particolare
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procPartId(bool needSave)
|
|
{
|
|
// controllo valore riferimento x tutti i path se sia cambiato num pz...
|
|
for (int i = 0; i < currAdpConf.nPath; i++)
|
|
{
|
|
if (istPathPartId[i] != null)
|
|
{
|
|
if (istPathPartId[i] != currPathPartId[i])
|
|
{
|
|
// aggiorno valore in Path RefList
|
|
updateValString(i, istPathPartId[i], "Path_{0:00}_PartId");
|
|
|
|
// prendo nuovo valore programma x path!
|
|
vettPath[i].mPathPartId.Value = istPathPartId[i];
|
|
// imposto a ZERO i pezzi del nuovo articolo
|
|
vettPath[i].mPathPartCount.Value = 0;
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
// ...aggiorno valore riferimento...
|
|
currPathPartId[i] = istPathPartId[i];
|
|
}
|
|
}
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing del num pz prodotti
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procPzProd(bool needSave)
|
|
{
|
|
// controllo valore riferimento x tutti i path se sia cambiato qta pezzi...
|
|
for (int i = 0; i < currAdpConf.nPath; i++)
|
|
{
|
|
// controllo valore riferimento variato...
|
|
if (istPathPartCount[i] != currPathPartCount[i])
|
|
{
|
|
if (istPathPartCount[i] > currPathPartCount[i])
|
|
{
|
|
uint delta = istPathPartCount[i] - currPathPartCount[i];
|
|
//uint contatore = updatePathRefListByIncr(i, delta, "Path_{0:00}_PZ_TOT");
|
|
uint contatore = updateValUIntByIncr(i, delta, "Path_{0:00}_PZ_TOT");
|
|
// passo valore num pz all'adapter
|
|
vettPath[i].mPathPartCount.Value = contatore;
|
|
}
|
|
else // variato x difetto... azzero!!!
|
|
{
|
|
uint newVal = istPathPartCount[i];
|
|
updateValUInt(i, newVal, "Path_{0:00}_PZ_TOT");
|
|
// passo valore num pz all'adapter
|
|
vettPath[i].mPathPartCount.Value = newVal;
|
|
}
|
|
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
// ...aggiorno valore riferimento...
|
|
currPathPartCount[i] = istPathPartCount[i];
|
|
}
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sul numero giri mandrino (totali)
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procGiriTotUnOp(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
|
{
|
|
uint delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istGiriElettrom[i] > contGiriElettrom[i])
|
|
{
|
|
delta = istGiriElettrom[i] - contGiriElettrom[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
uint contatore = updateValUIntByIncr(i, delta, "UnOp_{0:00}_AccTime");
|
|
// passo valore num giri (migliaia) all'adapter
|
|
vettUnOp[i].mUnOpAccTime.Value = contatore;
|
|
// ...aggiorno valore riferimento...
|
|
contGiriElettrom[i] = istGiriElettrom[i];
|
|
}
|
|
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sul numero cambi utensile (totali)
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procNumCU(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
|
{
|
|
uint delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istNumCambiUt[i] > currNumCambiUt[i])
|
|
{
|
|
delta = istNumCambiUt[i] - currNumCambiUt[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
uint contatore = updateValUIntByIncr(i, delta, "UnOp_{0:00}_NumCU");
|
|
// passo valore num CU all'adapter
|
|
vettUnOp[i].mUnOpNumCU.Value = contatore;
|
|
// ...aggiorno valore riferimento...
|
|
currNumCambiUt[i] = istNumCambiUt[i];
|
|
}
|
|
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sul totale m percorsi dagli assi
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procMovTotAssi(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nAxis; i++)
|
|
{
|
|
double delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istDistMovAssi[i] > contDistMovAssi[i])
|
|
{
|
|
delta = istDistMovAssi[i] - contDistMovAssi[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
double contTot = updateValDoubleByIncr(i, delta, "Axis_{0:00}_DistDone");
|
|
// passo valore totale all'adapter
|
|
vettAxis[i].mAxDistDone.Value = contTot.ToString("0.000", CultureInfo.InvariantCulture);
|
|
// ...aggiorno valore riferimento...
|
|
contDistMovAssi[i] = istDistMovAssi[i];
|
|
}
|
|
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sul totale tempo lavoro degli assi
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procAccTimeAssi(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nAxis; i++)
|
|
{
|
|
double delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istAccTimeAssi[i] > contAccTimeAssi[i])
|
|
{
|
|
delta = istAccTimeAssi[i] - contAccTimeAssi[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// salvo valore aggiuntivo x ore lavoro assi...
|
|
double oreTot = updateValDoubleByIncr(i, delta, "Axis_{0:00}_AccTime");
|
|
vettAxis[i].mAxAccTime.Value = oreTot.ToString("0.000", CultureInfo.InvariantCulture);
|
|
// ...aggiorno valore riferimento...
|
|
contAccTimeAssi[i] = istAccTimeAssi[i];
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sul totale num inversioni degli assi
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procNumInvAssi(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nAxis; i++)
|
|
{
|
|
long delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istNumInvAssi[i] > contNumInvAssi[i])
|
|
{
|
|
delta = istNumInvAssi[i] - contNumInvAssi[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
long contTot = updateValLongByIncr(i, delta, "Axis_{0:00}_InvDDone");
|
|
// passo valore totale all'adapter
|
|
vettAxis[i].mAxInvDDone.Value = contTot;
|
|
// ...aggiorno valore riferimento...
|
|
contNumInvAssi[i] = istNumInvAssi[i];
|
|
}
|
|
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sulle VacPump
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procVacPump(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nVacuumPump; i++)
|
|
{
|
|
uint delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istVacPumpWrkTime[i] > currVacPumpWrkTime[i])
|
|
{
|
|
delta = istVacPumpWrkTime[i] - currVacPumpWrkTime[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
uint contTot = updateValUIntByIncr(i, delta, "VacPump_{0:00}_WrkTime");
|
|
// passo valore totale all'adapter
|
|
vettVacPump[i].mVacPumpWrkTime.Value = contTot;
|
|
// ...aggiorno valore riferimento...
|
|
currVacPumpWrkTime[i] = istVacPumpWrkTime[i];
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sulle VacAct
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procVacAct(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nVacuumAct; i++)
|
|
{
|
|
uint delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istVacActCount[i] > currVacActCount[i])
|
|
{
|
|
delta = istVacActCount[i] - currVacActCount[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
// processo comunque sempre...
|
|
uint contTot = updateValUIntByIncr(i, delta, "VacAct_{0:00}_Count");
|
|
// passo valore totale all'adapter
|
|
vettVacAct[i].mVacActCount.Value = contTot;
|
|
// ...aggiorno valore riferimento...
|
|
currVacActCount[i] = istVacActCount[i];
|
|
}
|
|
return needSave;
|
|
}
|
|
/// <summary>
|
|
/// Processing delle variabili sui componenti Lubro
|
|
/// </summary>
|
|
/// <param name="needSave"></param>
|
|
/// <returns></returns>
|
|
public bool procLubro(bool needSave)
|
|
{
|
|
for (int i = 0; i < currAdpConf.nLubro; i++)
|
|
{
|
|
uint delta = 0;
|
|
// controllo valore riferimento...
|
|
if (istLubroCount[i] > currLubroCount[i])
|
|
{
|
|
delta = istLubroCount[i] - currLubroCount[i];
|
|
// segnalo necessità salvataggio!
|
|
needSave = true;
|
|
}
|
|
//processo comunque sempre...
|
|
uint contTot = updateValUIntByIncr(i, delta, "Lubro_{0:00}_Count");
|
|
// passo valore totale all'adapter
|
|
vettLubro[i].mLubroNum.Value = contTot;
|
|
// ...aggiorno valore riferimento...
|
|
currLubroCount[i] = istLubroCount[i];
|
|
}
|
|
return needSave;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region layer persistenza dati
|
|
|
|
/// <summary>
|
|
/// Dizionario di persistenza per i valori da salvare da/su file
|
|
/// </summary>
|
|
public Dictionary<string, string> persistenceLayer;
|
|
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...)
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private string getStoredVal(string keyVal)
|
|
{
|
|
string value;
|
|
if (!persistenceLayer.TryGetValue(keyVal, out value))
|
|
{
|
|
persistenceLayer.Add(keyVal, "0");
|
|
}
|
|
return value;
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come UINT
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private uint getStoredValUInt(string keyVal)
|
|
{
|
|
return Convert.ToUInt32(getStoredVal(keyVal));
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come INT
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private long getStoredValLong(string keyVal)
|
|
{
|
|
return Convert.ToInt64(getStoredVal(keyVal));
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come double
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private double getStoredValDouble(string keyVal)
|
|
{
|
|
return Convert.ToDouble(getStoredVal(keyVal));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in SOSTITUZIONE
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="newVal"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private void updateValString(int i, string newVal, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = newVal;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in SOSTITUZIONE e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="newVal"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private void updateValUInt(int i, uint newVal, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = newVal.ToString();
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private uint updateValUIntByIncr(int i, uint delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
uint contAct = getStoredValUInt(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private long updateValLongByIncr(int i, long delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
long contAct = getStoredValLong(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private double updateValDoubleByIncr(int i, double delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
double contAct = getStoredValDouble(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|