diff --git a/MTC_Sim/.vs/MTC_Sim/v14/.suo b/MTC_Sim/.vs/MTC_Sim/v14/.suo
index 72bc86b..6ec97de 100644
Binary files a/MTC_Sim/.vs/MTC_Sim/v14/.suo and b/MTC_Sim/.vs/MTC_Sim/v14/.suo differ
diff --git a/MTC_Sim/MTC_Sim/AdapterGeneric.cs b/MTC_Sim/MTC_Sim/AdapterGeneric.cs
index e96d8eb..1e5b8a0 100644
--- a/MTC_Sim/MTC_Sim/AdapterGeneric.cs
+++ b/MTC_Sim/MTC_Sim/AdapterGeneric.cs
@@ -429,8 +429,18 @@ namespace MTC_Sim
#region altri oggetti
+ ///
+ /// Strobe mask PLC
+ ///
public Strobe STROBE_PLC = 0;
+ ///
+ /// Strobe mask adapter
+ ///
public Strobe STROBE_ADP = 0;
+ ///
+ /// Status flag
+ ///
+ public StatusFlag STATUS_FLAG = 0;
public List codaM = new List();
@@ -601,7 +611,7 @@ namespace MTC_Sim
mAdapter.AddDataItem(mMode);
mAdapter.AddDataItem(mExec);
mAdapter.AddDataItem(mFunctionalMode);
-
+
// Pompe vuoto
vettVacPump = new VacuumPomp[adpConf.nVacuumPump];
for (int i = 0; i < adpConf.nVacuumPump; i++)
@@ -745,38 +755,49 @@ namespace MTC_Sim
}
///
- /// effettua recupero dati ed invio valori modificati...
+ /// effettua recupero dati ed invio valori modificati...
///
- public void gaterAndSend()
+ ///
+ public void gaterAndSend(gatherCycle ciclo)
{
- // !!!FARE!!!: ripensare se riscrivere con un timer rapido ed un insieme di task preimpostati a scadenza... (al posto di altri timers...)
-
-
// avvio fase raccolta dati
mAdapter.Begin();
- // leggo parametri da config file
- getConfigParam();
-
- ///acquisisco dati su programma in esecuzione e dati generali (stato, orologio, power...)
- getCurrProgramData();
-
- // fix codici M/S/T
- getCodMST();
-
- getProduzione();
-
- // fix dati x ulteriori (allarmi, modalità RUN/EXEC, ...)
+ // parte che eseguo SEMPRE: strobe/status
+ // dati stato macchina (allarmi, modalità RUN/EXEC, ...)
getCurrMode();
- getPath();
-
- getUnOp();
-
- getAxis();
-
+ // gestione allarmi
getAlarms();
+ if (ciclo == gatherCycle.HF)
+ {
+
+ // gestisco strobe...
+
+ // di conseguenza leggo valori variati
+
+ // fix codici M/S/T
+ getCodMST();
+ }
+ else if (ciclo == gatherCycle.MF)
+ {
+ // leggo parametri a media freq (path, assi)
+ getPath();
+
+ getUnOp();
+
+ getAxis();
+ }
+ else
+ {
+ // leggo parametri da config file
+ getConfigParam();
+ // bassa freq leggo altri valori...
+ getProduzione();
+ ///acquisisco dati su programma in esecuzione e dati generali (stato, orologio, power...)
+ getCurrProgramData();
+ }
// INVIO dati variati!
mAdapter.SendChanged();
@@ -802,7 +823,7 @@ namespace MTC_Sim
///
public virtual void getAxis()
{
-
+
}
private void getProduzione()
diff --git a/MTC_Sim/MTC_Sim/App.config b/MTC_Sim/MTC_Sim/App.config
index 9730627..54dc877 100644
--- a/MTC_Sim/MTC_Sim/App.config
+++ b/MTC_Sim/MTC_Sim/App.config
@@ -5,10 +5,10 @@
-
+
-
-
+
+
@@ -17,6 +17,7 @@
+
diff --git a/MTC_Sim/MTC_Sim/Appunti.txt b/MTC_Sim/MTC_Sim/Appunti.txt
index 0a435d9..a0d38d5 100644
--- a/MTC_Sim/MTC_Sim/Appunti.txt
+++ b/MTC_Sim/MTC_Sim/Appunti.txt
@@ -1,9 +1,12 @@
-
+#fix simulation:
+- meno frequente modifiche produzione...
+- posizione attuale/sim meno "ballerina"
# modifica threading
- thread molto veloci
- eseguo SEMPRE lettura degli STROBE
- leggo strobe valori speciali
- leggo strobe stato + allarmi
+
- quando ho lettura minimal/normal/full leggo altri dati OLTRE a strobe
- gestione 3 contatori
- ho dei contatori a count down x task di HF/MF/LF di ripetizione
diff --git a/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs b/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
index 0fad300..0eae262 100644
--- a/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
+++ b/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
@@ -195,6 +195,9 @@
this.lblCodaM = new System.Windows.Forms.Label();
this.addCodM = new System.Windows.Forms.TextBox();
this.label20 = new System.Windows.Forms.Label();
+ this.groupBox6 = new System.Windows.Forms.GroupBox();
+ this.STATUS_FLAGS = new System.Windows.Forms.TextBox();
+ this.label48 = new System.Windows.Forms.Label();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PosAct)).BeginInit();
this.groupBox3.SuspendLayout();
@@ -216,6 +219,7 @@
this.groupBox10.SuspendLayout();
this.groupBox8.SuspendLayout();
this.groupBox12.SuspendLayout();
+ this.groupBox6.SuspendLayout();
this.SuspendLayout();
//
// PlcErr_02
@@ -1184,6 +1188,7 @@
// tpStatus
//
this.tpStatus.BackColor = System.Drawing.Color.WhiteSmoke;
+ this.tpStatus.Controls.Add(this.groupBox6);
this.tpStatus.Controls.Add(this.groupBox1);
this.tpStatus.Controls.Add(this.groupBox11);
this.tpStatus.Location = new System.Drawing.Point(4, 22);
@@ -1830,6 +1835,34 @@
this.label20.TabIndex = 52;
this.label20.Text = "AddM";
//
+ // groupBox6
+ //
+ this.groupBox6.Controls.Add(this.STATUS_FLAGS);
+ this.groupBox6.Controls.Add(this.label48);
+ this.groupBox6.Location = new System.Drawing.Point(1, 207);
+ this.groupBox6.Name = "groupBox6";
+ this.groupBox6.Size = new System.Drawing.Size(773, 75);
+ this.groupBox6.TabIndex = 58;
+ this.groupBox6.TabStop = false;
+ this.groupBox6.Text = "Status & Alarms";
+ //
+ // STATUS_FLAGS
+ //
+ this.STATUS_FLAGS.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.STATUS_FLAGS.Location = new System.Drawing.Point(85, 11);
+ this.STATUS_FLAGS.Name = "STATUS_FLAGS";
+ this.STATUS_FLAGS.Size = new System.Drawing.Size(363, 29);
+ this.STATUS_FLAGS.TabIndex = 53;
+ //
+ // label48
+ //
+ this.label48.AutoSize = true;
+ this.label48.Location = new System.Drawing.Point(15, 19);
+ this.label48.Name = "label48";
+ this.label48.Size = new System.Drawing.Size(32, 13);
+ this.label48.TabIndex = 52;
+ this.label48.Text = "Flags";
+ //
// CMS_MachineSim
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1880,6 +1913,8 @@
this.groupBox8.PerformLayout();
this.groupBox12.ResumeLayout(false);
this.groupBox12.PerformLayout();
+ this.groupBox6.ResumeLayout(false);
+ this.groupBox6.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -2053,6 +2088,9 @@
private System.Windows.Forms.Label D1_NAME;
private System.Windows.Forms.Label D1_UUID;
private System.Windows.Forms.Label D1_ID;
+ private System.Windows.Forms.GroupBox groupBox6;
+ private System.Windows.Forms.TextBox STATUS_FLAGS;
+ private System.Windows.Forms.Label label48;
}
}
diff --git a/MTC_Sim/MTC_Sim/CMS_MachineSim.cs b/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
index 332d29a..d0c58e8 100644
--- a/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
+++ b/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
@@ -139,6 +139,7 @@ namespace MTC_Sim
STATUS_PLC_ADP.Text = utils.binaryForm(utils.CRI("STATUS_PLC_ADP"));
STATUS_ADP_PLC.Text = utils.binaryForm(utils.CRI("STATUS_ADP_PLC"));
+ STATUS_FLAGS.Text = utils.binaryForm(utils.CRI("STATUS_FLAGS"));
MainProgrBar.Minimum = 0;
MainProgrBar.Maximum = 100;
@@ -231,14 +232,21 @@ namespace MTC_Sim
// inizio a riportare che sto eseguendo..
MainProgrBar.PerformStep();
+ // eseguo eventuali simulazioni x dati/flags
+ simulateData();
+ MainProgrBar.PerformStep();
+
// check esecuzione FastTask
checkFastTask();
+ MainProgrBar.PerformStep();
// check esecuzione NormTask
checkNormTask();
+ MainProgrBar.PerformStep();
// check esecuzione SlowTask
checkSlowTask();
+ MainProgrBar.PerformStep();
// se è arrivato a MAX resetto...
if (MainProgrBar.Value >= MainProgrBar.Maximum)
@@ -254,9 +262,13 @@ namespace MTC_Sim
{
slowCount = 0;
+
+ // avvio fase raccolta dati e invio con adapter
+ agObj.gaterAndSend(gatherCycle.LF);
+ MainProgrBar.PerformStep();
+
// refresh stringhe code M/S/T
refreshCodeMST();
- MainProgrBar.PerformStep();
}
}
@@ -270,7 +282,7 @@ namespace MTC_Sim
normCount = 0;
// avvio fase raccolta dati e invio con adapter
- agObj.gaterAndSend();
+ agObj.gaterAndSend(gatherCycle.MF);
MainProgrBar.PerformStep();
}
}
@@ -283,15 +295,10 @@ namespace MTC_Sim
if (fastCount <= 0)
{
fastCount = 0;
+
+ // avvio fase raccolta dati e invio con adapter
+ agObj.gaterAndSend(gatherCycle.HF);
- // recupero info x strobe
-
- // recupero info x status
-
- // recupero info x allarmi...
-
- // eseguo eventuali simulazioni x dati/flags
- simulateData();
MainProgrBar.PerformStep();
}
}
@@ -303,9 +310,7 @@ namespace MTC_Sim
agObj.mMessage.ForceChanged();
agObj.mAdapter.SendChanged();
}
-
-
-
+
// apro eseguibile dump
private void dump_Click(object sender, EventArgs e)
{
@@ -319,11 +324,7 @@ namespace MTC_Sim
Process.Start(string.Format(@"{0}\dump\dump.exe", path));
}
}
-
-
-
-
-
+
#region classi x simulazione valori vari
///
@@ -335,6 +336,7 @@ namespace MTC_Sim
{
DateTime adesso = DateTime.Now;
Random rnd = new Random();
+ // 10% casi cambia riga
if (rnd.Next(0, 100) > 90)
{
PROG_ROW_NUM.Text = rnd.Next(1, 10000).ToString();
@@ -344,8 +346,8 @@ namespace MTC_Sim
if (agObj.codaS.Count > 0) agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.S_CODE;
if (agObj.codaT.Count > 0) agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.T_CODE;
- // aggiungo 1 pz al totale nel 33% dei casi (-->TC circa 3 x tick)...
- if (rnd.Next(0, 100) > 67)
+ // aggiungo 1 pz al totale nel 0.3% dei casi (-->TC circa 333 x tick)...
+ if (rnd.Next(0, 1000) > 997)
{
pzOk++;
agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.PZ_OK;
@@ -368,17 +370,74 @@ namespace MTC_Sim
}
- // cambio power nel 25% dei casi...
- if (rnd.Next(0, 100) > 75)
+ // cambio power nel 15% dei casi...
+ if (rnd.Next(0, 100) > 85)
{
Power += rnd.Next(-10, 10);
}
- // aggiungo 1 min AccTime nel 1.6% dei casi
- if (rnd.Next(0, 1000) > 984)
+ // aggiungo 1 min AccTime nel 0.1% dei casi
+ if (rnd.Next(0, 1000) > 999)
{
AccTime++;
}
+ // toggle 1 allarme sys nello 0.5% dei casi
+ if (rnd.Next(0, 1000) > 995)
+ {
+ int codAlarm = rnd.Next(1, 3);
+ switch (codAlarm)
+ {
+ case 1:
+ SysErr_01.Checked = !SysErr_01.Checked;
+ break;
+ case 2:
+ SysErr_02.Checked = !SysErr_02.Checked;
+ break;
+ default:
+ SysErr_03.Checked = !SysErr_03.Checked;
+ break;
+ }
+ agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.AL01;
+ }
+ // toggle 1 allarme PLC nello 0.4% dei casi
+ if (rnd.Next(0, 1000) > 996)
+ {
+ int codAlarm = rnd.Next(1, 3);
+ switch (codAlarm)
+ {
+ case 1:
+ PlcErr_01.Checked = !PlcErr_01.Checked;
+ break;
+ case 2:
+ PlcErr_02.Checked = !PlcErr_02.Checked;
+ break;
+ default:
+ PlcErr_03.Checked = !PlcErr_03.Checked;
+ break;
+ }
+ agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.AL02;
+ }
+ // toggle 1 allarme CNC nello 0.3% dei casi
+ if (rnd.Next(0, 1000) > 997)
+ {
+ int codAlarm = rnd.Next(1, 3);
+ switch (codAlarm)
+ {
+ case 1:
+ CncErr_01.Checked = !CncErr_01.Checked;
+ break;
+ case 2:
+ CncErr_02.Checked = !CncErr_02.Checked;
+ break;
+ default:
+ CncErr_03.Checked = !CncErr_03.Checked;
+ break;
+ }
+ agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.AL03;
+ }
+
+
+
// controllo se ci sia il flag di lettura di un evento M/S/T nel qual caso lo abbasso...
if (utils.IsSetAll(agObj.STROBE_ADP, Strobe.M_CODE))
{
@@ -418,6 +477,7 @@ namespace MTC_Sim
// aggiorno visualizzazione strobe!
STATUS_PLC_ADP.Text = utils.binaryForm((int)agObj.STROBE_PLC);
STATUS_ADP_PLC.Text = utils.binaryForm((int)agObj.STROBE_ADP);
+ STATUS_FLAGS.Text = utils.binaryForm((int)agObj.STATUS_FLAG);
}
}
@@ -653,6 +713,21 @@ namespace MTC_Sim
answ.pzKo = pzKo;
answ.pzTot = pzOk + pzKo;
+ // parto vuoto con statusFlag...
+ agObj.STATUS_FLAG = 0;
+ // aggiorno status flag in base a valori...
+ if (answ.EmrStop) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.ESTOP;
+ if (automatic.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.RM_AUTO;
+ else if (mdi.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.RM_MDI;
+ else if (edit.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.RM_EDIT;
+ else agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.RM_MANUAL;
+
+ if (running.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.EM_RUN;
+ else if (feedhold.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.EM_FEEDHOLD;
+ else if (stopped.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.EM_STOP;
+ else if (ready.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.EM_READY;
+ if(answ.FuncMode!= "1") agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusFlag.HM;
+
// ritorno oggetto!
return answ;
}
@@ -882,7 +957,7 @@ namespace MTC_Sim
answ.AxisType = AxisType;
answ.AxisDir = AxDir.Text;
answ.AxisLoad = AxLoad.Value;
- answ.AxisPosAct = AxPosition.Value + rnd.Next(-2, 2);
+ answ.AxisPosAct = AxPosition.Value;// + rnd.Next(-2, 2);
answ.AxisPosTgt = AxPosition.Value;
answ.AxisFeedAct = AxFeedAct.Value;
answ.AxisFeedOver = AxFeedOver.Value;
diff --git a/MTC_Sim/MTC_Sim/CMS_MachineSim.resx b/MTC_Sim/MTC_Sim/CMS_MachineSim.resx
index 707fc60..d24e7d7 100644
--- a/MTC_Sim/MTC_Sim/CMS_MachineSim.resx
+++ b/MTC_Sim/MTC_Sim/CMS_MachineSim.resx
@@ -138,24 +138,6 @@
True
-
- True
-
-
- True
-
-
- True
-
-
- True
-
-
- True
-
-
- True
-
104, 17
diff --git a/MTC_Sim/MTC_Sim/utils.cs b/MTC_Sim/MTC_Sim/utils.cs
index 37be44d..9b56eb2 100644
--- a/MTC_Sim/MTC_Sim/utils.cs
+++ b/MTC_Sim/MTC_Sim/utils.cs
@@ -64,6 +64,26 @@ namespace MTC_Sim
return ((value & flag) != 0);
}
///
+ /// verifica se un dato bit sia alzato (come flag di strobe)
+ ///
+ /// valore da testare
+ /// valore cercato, può essere un singolo valore o un insieme in modalità AND
+ ///
+ public static bool IsSetAll(StatusFlag value, StatusFlag flag)
+ {
+ return ((value & flag) == flag);
+ }
+ ///
+ /// verifica se un dato bit sia alzato (come flag di strobe)
+ ///
+ /// valore da testare
+ /// valore cercato, può essere un singolo valore o un insieme in modalità OR
+ ///
+ public static bool IsSetAny(StatusFlag value, StatusFlag flag)
+ {
+ return ((value & flag) != 0);
+ }
+ ///
/// formatta un numero in forma binaria 0/1
///
///
@@ -103,7 +123,9 @@ namespace MTC_Sim
///
ND
}
-
+ ///
+ /// Sorgente dati (per modalità recupero sw)
+ ///
public enum fonteDati
{
///
@@ -124,20 +146,20 @@ namespace MTC_Sim
Random
}
- public enum dataReadType
+ public enum gatherCycle
{
///
- /// lettura dati rapida e breve (minimo)
+ /// lettura dati ad alta frequenza
///
- minimal,
+ HF,
///
- /// lettura dati standard ma nON completa
+ /// lettura dati standard
///
- normal,
+ MF,
///
- /// lettura dati COMPLETA
+ /// lettura dati bassa freq
///
- full
+ LF
}
///
@@ -279,16 +301,16 @@ namespace MTC_Sim
public enum StatusFlag : int
{
NONE = 0,
- ST01 = 1 << 0,
- ST02 = 1 << 1,
- ST03 = 1 << 2,
- ST04 = 1 << 3,
- ST05 = 1 << 4,
- ST06 = 1 << 5,
- ST07 = 1 << 6,
- ST08 = 1 << 7,
- ST09 = 1 << 8,
- ST10 = 1 << 9,
+ ESTOP = 1 << 0,
+ RM_AUTO = 1 << 1,
+ RM_MANUAL = 1 << 2,
+ RM_MDI = 1 << 3,
+ RM_EDIT = 1 << 4,
+ EM_RUN = 1 << 5,
+ EM_READY = 1 << 6,
+ EM_STOP = 1 << 7,
+ EM_FEEDHOLD = 1 << 8,
+ HM = 1 << 9,
ST11 = 1 << 10,
ST12 = 1 << 11,
ST13 = 1 << 12,