diff --git a/MTC_Sim/.vs/MTC_Sim/v14/.suo b/MTC_Sim/.vs/MTC_Sim/v14/.suo
index 3f5a7b4..b72db5b 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/App.config b/MTC_Sim/MTC_Sim/App.config
index dbf9012..501f876 100644
--- a/MTC_Sim/MTC_Sim/App.config
+++ b/MTC_Sim/MTC_Sim/App.config
@@ -9,6 +9,7 @@
+
diff --git a/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs b/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
index 5dd9739..a8605af 100644
--- a/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
+++ b/MTC_Sim/MTC_Sim/CMS_MachineSim.Designer.cs
@@ -59,6 +59,7 @@
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.something = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.dump = new System.Windows.Forms.Button();
this.stop = new System.Windows.Forms.Button();
this.start = new System.Windows.Forms.Button();
this.port = new System.Windows.Forms.TextBox();
@@ -89,27 +90,36 @@
this.program = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.groupBox7 = new System.Windows.Forms.GroupBox();
+ this.label16 = new System.Windows.Forms.Label();
+ this.D1_UUID = new System.Windows.Forms.TextBox();
+ this.label15 = new System.Windows.Forms.Label();
+ this.D1_ID = new System.Windows.Forms.TextBox();
this.label14 = new System.Windows.Forms.Label();
this.D1_NAME = new System.Windows.Forms.TextBox();
this.estop = new System.Windows.Forms.CheckBox();
- this.label15 = new System.Windows.Forms.Label();
- this.D1_ID = new System.Windows.Forms.TextBox();
- this.label16 = new System.Windows.Forms.Label();
- this.D1_UUID = new System.Windows.Forms.TextBox();
- this.dump = new System.Windows.Forms.Button();
this.groupBox8 = new System.Windows.Forms.GroupBox();
this.groupBox9 = new System.Windows.Forms.GroupBox();
+ this.OPERATOR_ID = new System.Windows.Forms.TextBox();
+ this.label19 = new System.Windows.Forms.Label();
this.PROG_ROW_NUM = new System.Windows.Forms.TextBox();
this.label17 = new System.Windows.Forms.Label();
this.groupBox10 = new System.Windows.Forms.GroupBox();
this.enableDataSim = new System.Windows.Forms.CheckBox();
this.groupBox11 = new System.Windows.Forms.GroupBox();
- this.STATUS_PLC_ADP = new System.Windows.Forms.TextBox();
- this.lblPLC_ADP = new System.Windows.Forms.Label();
this.STATUS_ADP_PLC = new System.Windows.Forms.TextBox();
this.label18 = new System.Windows.Forms.Label();
- this.OPERATOR_ID = new System.Windows.Forms.TextBox();
- this.label19 = new System.Windows.Forms.Label();
+ this.STATUS_PLC_ADP = new System.Windows.Forms.TextBox();
+ this.lblPLC_ADP = new System.Windows.Forms.Label();
+ this.groupBox12 = new System.Windows.Forms.GroupBox();
+ this.lblCodaT = new System.Windows.Forms.Label();
+ this.addCodT = new System.Windows.Forms.TextBox();
+ this.label24 = new System.Windows.Forms.Label();
+ this.lblCodaS = new System.Windows.Forms.Label();
+ this.addCodS = new System.Windows.Forms.TextBox();
+ this.label22 = new System.Windows.Forms.Label();
+ this.lblCodaM = new System.Windows.Forms.Label();
+ this.addCodM = new System.Windows.Forms.TextBox();
+ this.label20 = new System.Windows.Forms.Label();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.commonVariables)).BeginInit();
@@ -124,6 +134,7 @@
this.groupBox9.SuspendLayout();
this.groupBox10.SuspendLayout();
this.groupBox11.SuspendLayout();
+ this.groupBox12.SuspendLayout();
this.SuspendLayout();
//
// flazBat
@@ -307,7 +318,7 @@
"TEARDOWN",
"MAINTENANCE",
"PROCESS_DEVELOPMENT"});
- this.functionalMode.Location = new System.Drawing.Point(102, 273);
+ this.functionalMode.Location = new System.Drawing.Point(655, 313);
this.functionalMode.Name = "functionalMode";
this.functionalMode.Size = new System.Drawing.Size(121, 21);
this.functionalMode.TabIndex = 47;
@@ -316,7 +327,7 @@
// label12
//
this.label12.AutoSize = true;
- this.label12.Location = new System.Drawing.Point(13, 276);
+ this.label12.Location = new System.Drawing.Point(566, 316);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(86, 13);
this.label12.TabIndex = 46;
@@ -402,6 +413,16 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server Info";
//
+ // dump
+ //
+ this.dump.Location = new System.Drawing.Point(298, 15);
+ this.dump.Name = "dump";
+ this.dump.Size = new System.Drawing.Size(75, 23);
+ this.dump.TabIndex = 4;
+ this.dump.Text = "Show Dump";
+ this.dump.UseVisualStyleBackColor = true;
+ this.dump.Click += new System.EventHandler(this.dump_Click);
+ //
// stop
//
this.stop.Location = new System.Drawing.Point(202, 15);
@@ -710,6 +731,38 @@
this.groupBox7.TabStop = false;
this.groupBox7.Text = "Macchina";
//
+ // label16
+ //
+ this.label16.AutoSize = true;
+ this.label16.Location = new System.Drawing.Point(193, 53);
+ this.label16.Name = "label16";
+ this.label16.Size = new System.Drawing.Size(34, 13);
+ this.label16.TabIndex = 59;
+ this.label16.Text = "UUID";
+ //
+ // D1_UUID
+ //
+ this.D1_UUID.Location = new System.Drawing.Point(234, 50);
+ this.D1_UUID.Name = "D1_UUID";
+ this.D1_UUID.Size = new System.Drawing.Size(140, 20);
+ this.D1_UUID.TabIndex = 58;
+ //
+ // label15
+ //
+ this.label15.AutoSize = true;
+ this.label15.Location = new System.Drawing.Point(10, 53);
+ this.label15.Name = "label15";
+ this.label15.Size = new System.Drawing.Size(18, 13);
+ this.label15.TabIndex = 57;
+ this.label15.Text = "ID";
+ //
+ // D1_ID
+ //
+ this.D1_ID.Location = new System.Drawing.Point(51, 50);
+ this.D1_ID.Name = "D1_ID";
+ this.D1_ID.Size = new System.Drawing.Size(124, 20);
+ this.D1_ID.TabIndex = 56;
+ //
// label14
//
this.label14.AutoSize = true;
@@ -737,48 +790,6 @@
this.estop.Text = "Emergency Stop";
this.estop.UseVisualStyleBackColor = true;
//
- // label15
- //
- this.label15.AutoSize = true;
- this.label15.Location = new System.Drawing.Point(10, 53);
- this.label15.Name = "label15";
- this.label15.Size = new System.Drawing.Size(18, 13);
- this.label15.TabIndex = 57;
- this.label15.Text = "ID";
- //
- // D1_ID
- //
- this.D1_ID.Location = new System.Drawing.Point(51, 50);
- this.D1_ID.Name = "D1_ID";
- this.D1_ID.Size = new System.Drawing.Size(124, 20);
- this.D1_ID.TabIndex = 56;
- //
- // label16
- //
- this.label16.AutoSize = true;
- this.label16.Location = new System.Drawing.Point(193, 53);
- this.label16.Name = "label16";
- this.label16.Size = new System.Drawing.Size(34, 13);
- this.label16.TabIndex = 59;
- this.label16.Text = "UUID";
- //
- // D1_UUID
- //
- this.D1_UUID.Location = new System.Drawing.Point(234, 50);
- this.D1_UUID.Name = "D1_UUID";
- this.D1_UUID.Size = new System.Drawing.Size(140, 20);
- this.D1_UUID.TabIndex = 58;
- //
- // dump
- //
- this.dump.Location = new System.Drawing.Point(298, 15);
- this.dump.Name = "dump";
- this.dump.Size = new System.Drawing.Size(75, 23);
- this.dump.TabIndex = 4;
- this.dump.Text = "Show Dump";
- this.dump.UseVisualStyleBackColor = true;
- this.dump.Click += new System.EventHandler(this.dump_Click);
- //
// groupBox8
//
this.groupBox8.Controls.Add(this.estop);
@@ -806,6 +817,22 @@
this.groupBox9.TabStop = false;
this.groupBox9.Text = "Produzione";
//
+ // OPERATOR_ID
+ //
+ this.OPERATOR_ID.Location = new System.Drawing.Point(273, 45);
+ this.OPERATOR_ID.Name = "OPERATOR_ID";
+ this.OPERATOR_ID.Size = new System.Drawing.Size(100, 20);
+ this.OPERATOR_ID.TabIndex = 53;
+ //
+ // label19
+ //
+ this.label19.AutoSize = true;
+ this.label19.Location = new System.Drawing.Point(222, 48);
+ this.label19.Name = "label19";
+ this.label19.Size = new System.Drawing.Size(45, 13);
+ this.label19.TabIndex = 52;
+ this.label19.Text = "ID oper.";
+ //
// PROG_ROW_NUM
//
this.PROG_ROW_NUM.Location = new System.Drawing.Point(313, 19);
@@ -856,22 +883,6 @@
this.groupBox11.TabStop = false;
this.groupBox11.Text = "Strobes";
//
- // STATUS_PLC_ADP
- //
- this.STATUS_PLC_ADP.Location = new System.Drawing.Point(85, 19);
- this.STATUS_PLC_ADP.Name = "STATUS_PLC_ADP";
- this.STATUS_PLC_ADP.Size = new System.Drawing.Size(286, 20);
- this.STATUS_PLC_ADP.TabIndex = 53;
- //
- // lblPLC_ADP
- //
- this.lblPLC_ADP.AutoSize = true;
- this.lblPLC_ADP.Location = new System.Drawing.Point(15, 22);
- this.lblPLC_ADP.Name = "lblPLC_ADP";
- this.lblPLC_ADP.Size = new System.Drawing.Size(64, 13);
- this.lblPLC_ADP.TabIndex = 52;
- this.lblPLC_ADP.Text = "PLC -> ADP";
- //
// STATUS_ADP_PLC
//
this.STATUS_ADP_PLC.Location = new System.Drawing.Point(85, 45);
@@ -888,28 +899,127 @@
this.label18.TabIndex = 54;
this.label18.Text = "ADP -> PLC";
//
- // OPERATOR_ID
+ // STATUS_PLC_ADP
//
- this.OPERATOR_ID.Location = new System.Drawing.Point(273, 45);
- this.OPERATOR_ID.Name = "OPERATOR_ID";
- this.OPERATOR_ID.Size = new System.Drawing.Size(100, 20);
- this.OPERATOR_ID.TabIndex = 53;
+ this.STATUS_PLC_ADP.Location = new System.Drawing.Point(85, 19);
+ this.STATUS_PLC_ADP.Name = "STATUS_PLC_ADP";
+ this.STATUS_PLC_ADP.Size = new System.Drawing.Size(286, 20);
+ this.STATUS_PLC_ADP.TabIndex = 53;
//
- // label19
+ // lblPLC_ADP
//
- this.label19.AutoSize = true;
- this.label19.Location = new System.Drawing.Point(222, 48);
- this.label19.Name = "label19";
- this.label19.Size = new System.Drawing.Size(45, 13);
- this.label19.TabIndex = 52;
- this.label19.Text = "ID oper.";
- this.label19.Click += new System.EventHandler(this.label19_Click);
+ this.lblPLC_ADP.AutoSize = true;
+ this.lblPLC_ADP.Location = new System.Drawing.Point(15, 22);
+ this.lblPLC_ADP.Name = "lblPLC_ADP";
+ this.lblPLC_ADP.Size = new System.Drawing.Size(64, 13);
+ this.lblPLC_ADP.TabIndex = 52;
+ this.lblPLC_ADP.Text = "PLC -> ADP";
+ //
+ // groupBox12
+ //
+ this.groupBox12.Controls.Add(this.lblCodaT);
+ this.groupBox12.Controls.Add(this.addCodT);
+ this.groupBox12.Controls.Add(this.label24);
+ this.groupBox12.Controls.Add(this.lblCodaS);
+ this.groupBox12.Controls.Add(this.addCodS);
+ this.groupBox12.Controls.Add(this.label22);
+ this.groupBox12.Controls.Add(this.lblCodaM);
+ this.groupBox12.Controls.Add(this.addCodM);
+ this.groupBox12.Controls.Add(this.label20);
+ this.groupBox12.Location = new System.Drawing.Point(12, 228);
+ this.groupBox12.Name = "groupBox12";
+ this.groupBox12.Size = new System.Drawing.Size(379, 100);
+ this.groupBox12.TabIndex = 58;
+ this.groupBox12.TabStop = false;
+ this.groupBox12.Text = "Codici M/S/T";
+ //
+ // lblCodaT
+ //
+ this.lblCodaT.AutoSize = true;
+ this.lblCodaT.Location = new System.Drawing.Point(117, 74);
+ this.lblCodaT.Name = "lblCodaT";
+ this.lblCodaT.Size = new System.Drawing.Size(22, 13);
+ this.lblCodaT.TabIndex = 60;
+ this.lblCodaT.Text = "[...]";
+ //
+ // addCodT
+ //
+ this.addCodT.Location = new System.Drawing.Point(51, 71);
+ this.addCodT.Name = "addCodT";
+ this.addCodT.Size = new System.Drawing.Size(60, 20);
+ this.addCodT.TabIndex = 59;
+ this.addCodT.KeyDown += new System.Windows.Forms.KeyEventHandler(this.addCodT_KeyDown);
+ this.addCodT.Leave += new System.EventHandler(this.addCodT_Leave);
+ //
+ // label24
+ //
+ this.label24.AutoSize = true;
+ this.label24.Location = new System.Drawing.Point(9, 74);
+ this.label24.Name = "label24";
+ this.label24.Size = new System.Drawing.Size(33, 13);
+ this.label24.TabIndex = 58;
+ this.label24.Text = "AddT";
+ //
+ // lblCodaS
+ //
+ this.lblCodaS.AutoSize = true;
+ this.lblCodaS.Location = new System.Drawing.Point(118, 48);
+ this.lblCodaS.Name = "lblCodaS";
+ this.lblCodaS.Size = new System.Drawing.Size(22, 13);
+ this.lblCodaS.TabIndex = 57;
+ this.lblCodaS.Text = "[...]";
+ //
+ // addCodS
+ //
+ this.addCodS.Location = new System.Drawing.Point(52, 45);
+ this.addCodS.Name = "addCodS";
+ this.addCodS.Size = new System.Drawing.Size(60, 20);
+ this.addCodS.TabIndex = 56;
+ this.addCodS.KeyDown += new System.Windows.Forms.KeyEventHandler(this.addCodS_KeyDown);
+ this.addCodS.Leave += new System.EventHandler(this.addCodS_Leave);
+ //
+ // label22
+ //
+ this.label22.AutoSize = true;
+ this.label22.Location = new System.Drawing.Point(10, 48);
+ this.label22.Name = "label22";
+ this.label22.Size = new System.Drawing.Size(33, 13);
+ this.label22.TabIndex = 55;
+ this.label22.Text = "AddS";
+ //
+ // lblCodaM
+ //
+ this.lblCodaM.AutoSize = true;
+ this.lblCodaM.Location = new System.Drawing.Point(118, 22);
+ this.lblCodaM.Name = "lblCodaM";
+ this.lblCodaM.Size = new System.Drawing.Size(22, 13);
+ this.lblCodaM.TabIndex = 54;
+ this.lblCodaM.Text = "[...]";
+ //
+ // addCodM
+ //
+ this.addCodM.Location = new System.Drawing.Point(52, 19);
+ this.addCodM.Name = "addCodM";
+ this.addCodM.Size = new System.Drawing.Size(60, 20);
+ this.addCodM.TabIndex = 53;
+ this.addCodM.KeyDown += new System.Windows.Forms.KeyEventHandler(this.addCodM_KeyDown);
+ this.addCodM.Leave += new System.EventHandler(this.addCodM_Leave);
+ //
+ // label20
+ //
+ this.label20.AutoSize = true;
+ this.label20.Location = new System.Drawing.Point(10, 22);
+ this.label20.Name = "label20";
+ this.label20.Size = new System.Drawing.Size(35, 13);
+ this.label20.TabIndex = 52;
+ this.label20.Text = "AddM";
//
// CMS_MachineSim
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(794, 733);
+ this.Controls.Add(this.groupBox12);
this.Controls.Add(this.groupBox11);
this.Controls.Add(this.groupBox10);
this.Controls.Add(this.groupBox9);
@@ -955,6 +1065,8 @@
this.groupBox10.PerformLayout();
this.groupBox11.ResumeLayout(false);
this.groupBox11.PerformLayout();
+ this.groupBox12.ResumeLayout(false);
+ this.groupBox12.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -1043,6 +1155,16 @@
private System.Windows.Forms.Label lblPLC_ADP;
private System.Windows.Forms.TextBox OPERATOR_ID;
private System.Windows.Forms.Label label19;
+ private System.Windows.Forms.GroupBox groupBox12;
+ private System.Windows.Forms.Label lblCodaT;
+ private System.Windows.Forms.TextBox addCodT;
+ private System.Windows.Forms.Label label24;
+ private System.Windows.Forms.Label lblCodaS;
+ private System.Windows.Forms.TextBox addCodS;
+ private System.Windows.Forms.Label label22;
+ private System.Windows.Forms.Label lblCodaM;
+ private System.Windows.Forms.TextBox addCodM;
+ private System.Windows.Forms.Label label20;
}
}
diff --git a/MTC_Sim/MTC_Sim/CMS_MachineSim.cs b/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
index 6c6daf1..e785522 100644
--- a/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
+++ b/MTC_Sim/MTC_Sim/CMS_MachineSim.cs
@@ -62,7 +62,11 @@ namespace MTC_Sim
///
/// CURR_PROG_ROWNUM - programma in esecuzione
///
- Event mProgRowNum = new Event("CurrPRog_RowNum");
+ Event mProgRowNum = new Event("CurrProg_RowNum");
+ ///
+ /// PartId - particolare prodotto
+ ///
+ Event mPartId = new Event("PartID");
///
/// CURR_PROG_ROWNUM - programma in esecuzione
///
@@ -78,6 +82,22 @@ namespace MTC_Sim
///
Event mExec = new Event("exec");
+ Strobe STROBE_PLC = 0;
+ Strobe STROBE_ADP = 0;
+
+ ///
+ /// M_CODE
+ ///
+ Event mCod_M = new Event("Cod_M");
+ ///
+ /// S_CODE
+ ///
+ Event mCod_S = new Event("Cod_S");
+ ///
+ /// T_CODE
+ ///
+ Event mCod_T = new Event("Cod_T");
+
Event mFunctionalMode = new Event("func");
Message mMessage = new Message("message");
@@ -116,8 +136,14 @@ namespace MTC_Sim
// programma e produzione
mAdapter.AddDataItem(mProgram);
mAdapter.AddDataItem(mProgRowNum);
+ mAdapter.AddDataItem(mPartId);
mAdapter.AddDataItem(mOperator);
+ // codici speciali M/S/T
+ mAdapter.AddDataItem(mCod_M);
+ mAdapter.AddDataItem(mCod_S);
+ mAdapter.AddDataItem(mCod_T);
+
mAdapter.AddDataItem(mMode);
mAdapter.AddDataItem(mExec);
@@ -155,6 +181,7 @@ namespace MTC_Sim
D1_UUID.Text = utils.CRS("D1_UUID");
program.Text = utils.CRS("D1_PROGRAM");
PROG_ROW_NUM.Text = "0";
+ partID.Text = utils.CRS("PartID");
OPERATOR_ID.Text = "M9999";
STATUS_PLC_ADP.Text = binaryForm(utils.CRI("STATUS_PLC_ADP"));
STATUS_ADP_PLC.Text = binaryForm(utils.CRI("STATUS_ADP_PLC"));
@@ -172,41 +199,6 @@ namespace MTC_Sim
return answ;
}
- ///
- /// simula alcuni dati generando ad esempio numeri casuali... SE abilitato
- ///
- private void simulateData()
- {
- if (enableDataSim.Checked)
- {
- DateTime adesso = DateTime.Now;
- Random rnd = new Random();
- PROG_ROW_NUM.Text = rnd.Next(1, 10000).ToString();
- // verifica se ci sia un evento strobe da recepire...
- if (STATUS_PLC_ADP.Text.IndexOf("1") >= 0)
- {
- // verifica SE sia stato recepito da adapter...
- if (STATUS_ADP_PLC.Text == STATUS_PLC_ADP.Text)
- {
- // in questo caso ripulisco da PLC...
- STATUS_PLC_ADP.Text = binaryForm(0);
- }
- }
- else
- {
- // se era ancora sollevato strobe lettura lo abbasso...
- if (STATUS_ADP_PLC.Text.IndexOf("1") >= 0)
- {
- STATUS_ADP_PLC.Text = binaryForm(0);
- }
- else
- {
- // se il numero è < 1000 (10%) imposto strobe...
- STATUS_PLC_ADP.Text = binaryForm(rnd.Next(1, 10000000));
- }
- }
- }
- }
private void start_Click(object sender, EventArgs e)
{
@@ -246,7 +238,7 @@ namespace MTC_Sim
{
mAdapter.Begin();
- // eseguoe ventuali simulazioni
+ // eseguo eventuali simulazioni x dati/flags
simulateData();
// nome
@@ -257,8 +249,15 @@ namespace MTC_Sim
// programma
mProgram.Value = program.Text;
mProgRowNum.Value = PROG_ROW_NUM.Text;
+ mPartId.Value = partID.Text;
mOperator.Value = OPERATOR_ID.Text;
+ // SE presente recupero Cod_M/S/T
+ checkCodM();
+ checkCodS();
+ checkCodT();
+
+
if (estop.Checked)
mEStop.Value = "TRIGGERED";
@@ -322,6 +321,67 @@ namespace MTC_Sim
mAdapter.SendChanged();
}
+
+ private void checkCodM()
+ {
+ if (utils.IsSetAll(STROBE_PLC, Strobe.M_CODE))
+ {
+ mCod_M.Value = getNextMCode;
+ // se il valore è "" allora alzo flag lettura...
+ if (mCod_M.Value.ToString() == "") STROBE_ADP = STROBE_ADP | Strobe.M_CODE;
+ // refresh stringhe
+ refreshCodeMST();
+ }
+ else
+ {
+ // resetto eventuali flag di lettura...
+ if (utils.IsSetAll(STROBE_ADP, Strobe.M_CODE))
+ {
+ STROBE_ADP -= Strobe.M_CODE;
+ }
+ }
+ }
+ private void checkCodS()
+ {
+ if (utils.IsSetAll(STROBE_PLC, Strobe.S_CODE))
+ {
+ mCod_S.Value = getNextSCode;
+ // se il valore è "" allora alzo flag lettura...
+ if (mCod_S.Value.ToString() == "") STROBE_ADP = STROBE_ADP | Strobe.S_CODE;
+ // refresh stringhe
+ refreshCodeMST();
+ }
+ else
+ {
+ // resetto eventuali flag di lettura...
+ if (utils.IsSetAll(STROBE_ADP, Strobe.S_CODE))
+ {
+ STROBE_ADP -= Strobe.S_CODE;
+ }
+ }
+ }
+ private void checkCodT()
+ {
+ if (utils.IsSetAll(STROBE_PLC, Strobe.T_CODE))
+ {
+ mCod_T.Value = getNextTCode;
+ // se il valore è "" allora alzo flag lettura...
+ if (mCod_T.Value.ToString() == "") STROBE_ADP = STROBE_ADP | Strobe.T_CODE;
+ // refresh stringhe
+ refreshCodeMST();
+ }
+ else
+ {
+ // resetto eventuali flag di lettura...
+ if (utils.IsSetAll(STROBE_ADP, Strobe.T_CODE))
+ {
+ STROBE_ADP -= Strobe.T_CODE;
+ }
+ }
+ }
+
+
+
private void message_Leave(object sender, EventArgs e)
{
mMessage.Value = messageText.Text;
@@ -379,9 +439,224 @@ namespace MTC_Sim
Process.Start(string.Format(@"{0}\..\..\dump\dump.exe", path));
}
- private void label19_Click(object sender, EventArgs e)
+
+ #region area metodi comunicazione con PLC/CNC
+
+ ///
+ /// recupera primo elemento codaM
+ ///
+ protected string getNextMCode
+ {
+ get
+ {
+ string answ = "";
+ if (codaM.Count > 0)
+ {
+ // accodo codice M...
+ answ = codaM.First();
+ // tolgo elemento
+ codaM.RemoveAt(0);
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// recupera primo elemento codaS
+ ///
+ protected string getNextSCode
+ {
+ get
+ {
+ string answ = "";
+ if (codaS.Count > 0)
+ {
+ // accodo codice S...
+ answ = codaS.First();
+ // tolgo elemento
+ codaS.RemoveAt(0);
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// recupera primo elemento codaT
+ ///
+ protected string getNextTCode
+ {
+ get
+ {
+ string answ = "";
+ if (codaT.Count > 0)
+ {
+ // accodo codice T...
+ answ = codaT.First();
+ // tolgo elemento
+ codaT.RemoveAt(0);
+ }
+ return answ;
+ }
+ }
+
+ #endregion
+
+
+ #region classi x simulazione valori vari
+
+ ///
+ /// simula alcuni dati generando ad esempio numeri casuali... SE abilitato
+ ///
+ private void simulateData()
+ {
+ if (enableDataSim.Checked)
+ {
+ DateTime adesso = DateTime.Now;
+ Random rnd = new Random();
+ PROG_ROW_NUM.Text = rnd.Next(1, 10000).ToString();
+ // ora controllo se ci siano eventi M/S/T x alzare flag...
+ if (codaM.Count > 0) STROBE_PLC = STROBE_PLC | Strobe.M_CODE;
+ if (codaS.Count > 0) STROBE_PLC = STROBE_PLC | Strobe.S_CODE;
+ if (codaT.Count > 0) STROBE_PLC = STROBE_PLC | Strobe.T_CODE;
+
+ // controllo se ci sia il flag di lettura di un evento M/S/T nel qual caso lo abbasso...
+ if (STROBE_ADP > 0) STROBE_PLC -= STROBE_ADP;
+
+ // aggiorno visualizzazione strobe!
+ STATUS_PLC_ADP.Text = binaryForm((int)STROBE_PLC);
+ STATUS_ADP_PLC.Text = binaryForm((int)STROBE_ADP);
+
+#if false
+ // verifica se ci sia un evento strobe da recepire...
+ if (STATUS_PLC_ADP.Text.IndexOf("1") >= 0)
+ {
+ // verifica SE sia stato recepito da adapter...
+ if (STATUS_ADP_PLC.Text == STATUS_PLC_ADP.Text)
+ {
+ // in questo caso ripulisco da PLC...
+ STATUS_PLC_ADP.Text = binaryForm(0);
+ }
+ }
+ else
+ {
+ // se era ancora sollevato strobe lettura lo abbasso...
+ if (STATUS_ADP_PLC.Text.IndexOf("1") >= 0)
+ {
+ STATUS_ADP_PLC.Text = binaryForm(0);
+ }
+ else
+ {
+ // se il numero è < 1000 (10%) imposto strobe...
+ STATUS_PLC_ADP.Text = binaryForm(rnd.Next(1, 10000000));
+ }
+ }
+#endif
+ }
+ }
+
+
+
+ protected List codaM = new List();
+ protected List codaS = new List();
+ protected List codaT = new List();
+
+ ///
+ /// aggiorna visualizzazione code...
+ ///
+ private void refreshCodeMST()
+ {
+ lblCodaM.Text = string.Join(",", codaM.ToArray());
+ lblCodaT.Text = string.Join(",", codaT.ToArray());
+ lblCodaS.Text = string.Join(",", codaS.ToArray());
+ }
+
+ private void accodaCodM()
+ {
+ if (addCodM.Text.Trim() != "")
+ {
+ codaM.Add(addCodM.Text.Trim());
+ addCodM.Text = "";
+ }
+ refreshCodeMST();
+ }
+ private void accodaCodS()
+ {
+ if (addCodS.Text.Trim() != "")
+ {
+ codaS.Add(addCodS.Text.Trim());
+ addCodS.Text = "";
+ }
+ refreshCodeMST();
+ }
+ private void accodaCodT()
+ {
+ if (addCodT.Text.Trim() != "")
+ {
+ codaT.Add(addCodT.Text.Trim());
+ addCodT.Text = "";
+ }
+ refreshCodeMST();
+ }
+
+ private void addCodM_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Enter)
+ {
+ // accodo testo
+ accodaCodM();
+ }
+ else if (e.KeyCode == Keys.Escape)
+ {
+ // svuoto!
+ addCodM.Text = "";
+ }
+ }
+ private void addCodM_Leave(object sender, EventArgs e)
+ {
+ accodaCodM();
+ }
+
+ private void addCodS_KeyDown(object sender, KeyEventArgs e)
{
+ if (e.KeyCode == Keys.Enter)
+ {
+ // accodo testo
+ accodaCodS();
+ }
+ else if (e.KeyCode == Keys.Escape)
+ {
+ // svuoto!
+ addCodS.Text = "";
+ }
}
+
+ private void addCodS_Leave(object sender, EventArgs e)
+ {
+ accodaCodS();
+ }
+
+
+ private void addCodT_KeyDown(object sender, KeyEventArgs e)
+ {
+
+ if (e.KeyCode == Keys.Enter)
+ {
+ // accodo testo
+ accodaCodT();
+ }
+ else if (e.KeyCode == Keys.Escape)
+ {
+ // svuoto!
+ addCodT.Text = "";
+ }
+ }
+ private void addCodT_Leave(object sender, EventArgs e)
+ {
+ accodaCodT();
+ }
+
+
+ #endregion
}
}
diff --git a/MTC_Sim/MTC_Sim/utils.cs b/MTC_Sim/MTC_Sim/utils.cs
index e6ed6fe..6c8b081 100644
--- a/MTC_Sim/MTC_Sim/utils.cs
+++ b/MTC_Sim/MTC_Sim/utils.cs
@@ -42,7 +42,69 @@ namespace MTC_Sim
{ }
return answ;
}
+ ///
+ /// 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(Strobe value, Strobe 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(Strobe value, Strobe flag)
+ {
+ return ((value & flag) != 0);
+ }
}
+ ///
+ /// Strobe: contiene il set di strobe di comunicazione
+ ///
+ /// rif: http://stackoverflow.com/questions/17209054/parse-bits-in-a-byte-to-enum
+ ///
+ [Flags]
+ public enum Strobe : int
+ {
+ NONE = 0,
+ M_CODE = 1 << 0,
+ S_CODE = 1 << 1,
+ T_CODE = 1 << 2,
+ SP04 = 1 << 3,
+ SP05 = 1 << 4,
+ SP06 = 1 << 5,
+ SP07 = 1 << 6,
+ SP08 = 1 << 8,
+ SP09 = 1 << 9,
+ SP10 = 1 << 10,
+ SP11 = 1 << 11,
+ SP12 = 1 << 12,
+ SP13 = 1 << 13,
+ SP14 = 1 << 14,
+ SP15 = 1 << 15,
+ SP16 = 1 << 16,
+ SP17 = 1 << 17,
+ SP18 = 1 << 18,
+ SP19 = 1 << 19,
+ SP20 = 1 << 20,
+ SP21 = 1 << 21,
+ SP22 = 1 << 22,
+ SP23 = 1 << 23,
+ SP24 = 1 << 24,
+ SP25 = 1 << 25,
+ SP26 = 1 << 26,
+ SP27 = 1 << 27,
+ SP28 = 1 << 28,
+ SP29 = 1 << 29,
+ SP30 = 1 << 30,
+ SP31 = 1 << 31,
+ SP32 = 1 << 32
+ }
}