diff --git a/IOB-UT/baseUtils.cs b/IOB-UT/baseUtils.cs index 5efaf908..2914cb01 100644 --- a/IOB-UT/baseUtils.cs +++ b/IOB-UT/baseUtils.cs @@ -1146,6 +1146,40 @@ namespace IOB_UT dataType = _dataType; } } + /// + /// Classe che contiene tutte le NUOVE informaizoni da aggiornare sulla form + /// + public class newDisplayData + { + /// + /// Dati tipo IN + /// + public string newInData { get; set; } = ""; + /// + /// Dati tipo Signal + /// + public string newSignalData { get; set; } = ""; + /// + /// Dati tipo FluxLog + /// + public string newFLogData { get; set; } = ""; + /// + /// Dati tipo UrlCall + /// + public string newUrlCallData { get; set; } = ""; + /// + /// Dati tipo LiveLog + /// + public string newLiveLogData { get; set; } = ""; + /// + /// Stato semaforo IN verso PLC + /// + public Semaforo semIn { get; set; } = Semaforo.ND; + /// + /// Stato semaforo OUT verso MES + /// + public Semaforo semOut { get; set; } = Semaforo.ND; + } /// /// StFlag8: set di 8 bit (1 word) contente semaforo di variabili @@ -1208,6 +1242,10 @@ namespace IOB_UT /// public enum Semaforo { + /// + /// Stato non definito + /// + ND, /// /// Verde /// diff --git a/IOB-WIN/AdapterForm.Designer.cs b/IOB-WIN/AdapterForm.Designer.cs index 03e4ec74..f9b72c1d 100644 --- a/IOB-WIN/AdapterForm.Designer.cs +++ b/IOB-WIN/AdapterForm.Designer.cs @@ -7,6 +7,7 @@ /// private System.ComponentModel.IContainer components = null; +#if false /// /// Clean up any resources being used. /// @@ -18,7 +19,8 @@ components.Dispose(); } base.Dispose(disposing); - } + } +#endif #region Windows Form Designer generated code @@ -61,6 +63,18 @@ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.lblLogfile = new System.Windows.Forms.Label(); this.tabPlc = new System.Windows.Forms.TabPage(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.panel3 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.lblTaskLog = new System.Windows.Forms.Label(); + this.txtValue = new System.Windows.Forms.TextBox(); + this.label23 = new System.Windows.Forms.Label(); + this.label22 = new System.Windows.Forms.Label(); + this.cmbParamValues = new System.Windows.Forms.ComboBox(); + this.btnSendPLC = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.chkEdit = new System.Windows.Forms.CheckBox(); + this.label12 = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); this.lblBitmap_03 = new System.Windows.Forms.Label(); this.lblBitmap_02 = new System.Windows.Forms.Label(); @@ -71,12 +85,6 @@ this.label18 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.label16 = new System.Windows.Forms.Label(); - this.panel3 = new System.Windows.Forms.Panel(); - this.lblTaskLog = new System.Windows.Forms.Label(); - this.btnSendPLC = new System.Windows.Forms.Button(); - this.label5 = new System.Windows.Forms.Label(); - this.chkEdit = new System.Windows.Forms.CheckBox(); - this.label12 = new System.Windows.Forms.Label(); this.tabMes = new System.Windows.Forms.TabPage(); this.panel1 = new System.Windows.Forms.Panel(); this.label21 = new System.Windows.Forms.Label(); @@ -90,12 +98,6 @@ this.label10 = new System.Windows.Forms.Label(); this.lblDataProc = new System.Windows.Forms.Label(); this.lblQueueLen = new System.Windows.Forms.Label(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.cmbParamValues = new System.Windows.Forms.ComboBox(); - this.label22 = new System.Windows.Forms.Label(); - this.txtValue = new System.Windows.Forms.TextBox(); - this.label23 = new System.Windows.Forms.Label(); - this.panel2 = new System.Windows.Forms.Panel(); this.statusStrip1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); this.tabData.SuspendLayout(); @@ -104,15 +106,15 @@ this.tabLog.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); this.tabPlc.SuspendLayout(); - this.panel4.SuspendLayout(); - this.panel3.SuspendLayout(); - this.tabMes.SuspendLayout(); - this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + this.panel3.SuspendLayout(); this.panel2.SuspendLayout(); + this.panel4.SuspendLayout(); + this.tabMes.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // gather @@ -522,6 +524,145 @@ this.tabPlc.TabIndex = 4; this.tabPlc.Text = "PLC <--> IOB"; // + // splitContainer1 + // + this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.splitContainer1.Location = new System.Drawing.Point(7, 3); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.panel3); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.panel4); + this.splitContainer1.Size = new System.Drawing.Size(940, 547); + this.splitContainer1.SplitterDistance = 469; + this.splitContainer1.TabIndex = 94; + // + // panel3 + // + this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.panel3.Controls.Add(this.panel2); + this.panel3.Controls.Add(this.txtValue); + this.panel3.Controls.Add(this.label23); + this.panel3.Controls.Add(this.label22); + this.panel3.Controls.Add(this.cmbParamValues); + this.panel3.Controls.Add(this.btnSendPLC); + this.panel3.Controls.Add(this.label5); + this.panel3.Controls.Add(this.chkEdit); + this.panel3.Controls.Add(this.label12); + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(0, 0); + this.panel3.Margin = new System.Windows.Forms.Padding(2); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(469, 547); + this.panel3.TabIndex = 91; + // + // panel2 + // + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.AutoScroll = true; + this.panel2.Controls.Add(this.lblTaskLog); + this.panel2.Location = new System.Drawing.Point(3, 212); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(459, 328); + this.panel2.TabIndex = 86; + // + // lblTaskLog + // + this.lblTaskLog.AutoSize = true; + this.lblTaskLog.Location = new System.Drawing.Point(3, 0); + this.lblTaskLog.Name = "lblTaskLog"; + this.lblTaskLog.Size = new System.Drawing.Size(16, 13); + this.lblTaskLog.TabIndex = 81; + this.lblTaskLog.Text = "..."; + // + // txtValue + // + this.txtValue.Location = new System.Drawing.Point(95, 91); + this.txtValue.Margin = new System.Windows.Forms.Padding(2); + this.txtValue.Name = "txtValue"; + this.txtValue.Size = new System.Drawing.Size(236, 20); + this.txtValue.TabIndex = 85; + // + // label23 + // + this.label23.AutoSize = true; + this.label23.Location = new System.Drawing.Point(25, 91); + this.label23.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label23.Name = "label23"; + this.label23.Size = new System.Drawing.Size(34, 13); + this.label23.TabIndex = 84; + this.label23.Text = "Value"; + // + // label22 + // + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(26, 57); + this.label22.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(55, 13); + this.label22.TabIndex = 83; + this.label22.Text = "Parameter"; + // + // cmbParamValues + // + this.cmbParamValues.FormattingEnabled = true; + this.cmbParamValues.Location = new System.Drawing.Point(95, 54); + this.cmbParamValues.Name = "cmbParamValues"; + this.cmbParamValues.Size = new System.Drawing.Size(236, 21); + this.cmbParamValues.TabIndex = 82; + // + // btnSendPLC + // + this.btnSendPLC.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnSendPLC.Location = new System.Drawing.Point(19, 132); + this.btnSendPLC.Margin = new System.Windows.Forms.Padding(2); + this.btnSendPLC.Name = "btnSendPLC"; + this.btnSendPLC.Size = new System.Drawing.Size(312, 30); + this.btnSendPLC.TabIndex = 6; + this.btnSendPLC.Text = "SEND --> PLC"; + this.btnSendPLC.UseVisualStyleBackColor = true; + this.btnSendPLC.Click += new System.EventHandler(this.BtnSendPLC_Click); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label5.Location = new System.Drawing.Point(14, 184); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(115, 25); + this.label5.TabIndex = 1; + this.label5.Text = "TASK LIST"; + // + // chkEdit + // + this.chkEdit.AutoSize = true; + this.chkEdit.Location = new System.Drawing.Point(252, 22); + this.chkEdit.Margin = new System.Windows.Forms.Padding(2); + this.chkEdit.Name = "chkEdit"; + this.chkEdit.Size = new System.Drawing.Size(79, 17); + this.chkEdit.TabIndex = 8; + this.chkEdit.Text = "SET DATA"; + this.chkEdit.UseVisualStyleBackColor = true; + this.chkEdit.Click += new System.EventHandler(this.ChkEdit_CheckedChanged); + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label12.Location = new System.Drawing.Point(14, 17); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(131, 25); + this.label12.TabIndex = 1; + this.label12.Text = "MES --> PLC"; + // // panel4 // this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; @@ -631,78 +772,6 @@ this.label16.TabIndex = 2; this.label16.Text = "PLC --> MES"; // - // panel3 - // - this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.panel3.Controls.Add(this.panel2); - this.panel3.Controls.Add(this.txtValue); - this.panel3.Controls.Add(this.label23); - this.panel3.Controls.Add(this.label22); - this.panel3.Controls.Add(this.cmbParamValues); - this.panel3.Controls.Add(this.btnSendPLC); - this.panel3.Controls.Add(this.label5); - this.panel3.Controls.Add(this.chkEdit); - this.panel3.Controls.Add(this.label12); - this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel3.Location = new System.Drawing.Point(0, 0); - this.panel3.Margin = new System.Windows.Forms.Padding(2); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(469, 547); - this.panel3.TabIndex = 91; - // - // lblTaskLog - // - this.lblTaskLog.AutoSize = true; - this.lblTaskLog.Location = new System.Drawing.Point(3, 0); - this.lblTaskLog.Name = "lblTaskLog"; - this.lblTaskLog.Size = new System.Drawing.Size(16, 13); - this.lblTaskLog.TabIndex = 81; - this.lblTaskLog.Text = "..."; - // - // btnSendPLC - // - this.btnSendPLC.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnSendPLC.Location = new System.Drawing.Point(19, 132); - this.btnSendPLC.Margin = new System.Windows.Forms.Padding(2); - this.btnSendPLC.Name = "btnSendPLC"; - this.btnSendPLC.Size = new System.Drawing.Size(312, 30); - this.btnSendPLC.TabIndex = 6; - this.btnSendPLC.Text = "SEND --> PLC"; - this.btnSendPLC.UseVisualStyleBackColor = true; - this.btnSendPLC.Click += new System.EventHandler(this.BtnSendPLC_Click); - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label5.Location = new System.Drawing.Point(14, 184); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(115, 25); - this.label5.TabIndex = 1; - this.label5.Text = "TASK LIST"; - // - // chkEdit - // - this.chkEdit.AutoSize = true; - this.chkEdit.Location = new System.Drawing.Point(252, 22); - this.chkEdit.Margin = new System.Windows.Forms.Padding(2); - this.chkEdit.Name = "chkEdit"; - this.chkEdit.Size = new System.Drawing.Size(79, 17); - this.chkEdit.TabIndex = 8; - this.chkEdit.Text = "SET DATA"; - this.chkEdit.UseVisualStyleBackColor = true; - this.chkEdit.Click += new System.EventHandler(this.ChkEdit_CheckedChanged); - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label12.Location = new System.Drawing.Point(14, 17); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(131, 25); - this.label12.TabIndex = 1; - this.label12.Text = "MES --> PLC"; - // // tabMes // this.tabMes.BackColor = System.Drawing.Color.Transparent; @@ -839,73 +908,6 @@ this.lblQueueLen.TabIndex = 83; this.lblQueueLen.Text = "###"; // - // splitContainer1 - // - this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.splitContainer1.Location = new System.Drawing.Point(7, 3); - this.splitContainer1.Name = "splitContainer1"; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.panel3); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.panel4); - this.splitContainer1.Size = new System.Drawing.Size(940, 547); - this.splitContainer1.SplitterDistance = 469; - this.splitContainer1.TabIndex = 94; - // - // cmbParamValues - // - this.cmbParamValues.FormattingEnabled = true; - this.cmbParamValues.Location = new System.Drawing.Point(95, 54); - this.cmbParamValues.Name = "cmbParamValues"; - this.cmbParamValues.Size = new System.Drawing.Size(236, 21); - this.cmbParamValues.TabIndex = 82; - // - // label22 - // - this.label22.AutoSize = true; - this.label22.Location = new System.Drawing.Point(26, 57); - this.label22.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label22.Name = "label22"; - this.label22.Size = new System.Drawing.Size(55, 13); - this.label22.TabIndex = 83; - this.label22.Text = "Parameter"; - // - // txtValue - // - this.txtValue.Location = new System.Drawing.Point(95, 91); - this.txtValue.Margin = new System.Windows.Forms.Padding(2); - this.txtValue.Name = "txtValue"; - this.txtValue.Size = new System.Drawing.Size(236, 20); - this.txtValue.TabIndex = 85; - // - // label23 - // - this.label23.AutoSize = true; - this.label23.Location = new System.Drawing.Point(25, 91); - this.label23.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label23.Name = "label23"; - this.label23.Size = new System.Drawing.Size(34, 13); - this.label23.TabIndex = 84; - this.label23.Text = "Value"; - // - // panel2 - // - this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.panel2.AutoScroll = true; - this.panel2.Controls.Add(this.lblTaskLog); - this.panel2.Location = new System.Drawing.Point(3, 212); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(459, 328); - this.panel2.TabIndex = 86; - // // AdapterForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -934,19 +936,19 @@ this.flowLayoutPanel1.ResumeLayout(false); this.flowLayoutPanel1.PerformLayout(); this.tabPlc.ResumeLayout(false); - this.panel4.ResumeLayout(false); - this.panel4.PerformLayout(); - this.panel3.ResumeLayout(false); - this.panel3.PerformLayout(); - this.tabMes.ResumeLayout(false); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); + this.panel4.ResumeLayout(false); + this.panel4.PerformLayout(); + this.tabMes.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/IOB-WIN/AdapterForm.cs b/IOB-WIN/AdapterForm.cs index be307b08..70773615 100644 --- a/IOB-WIN/AdapterForm.cs +++ b/IOB-WIN/AdapterForm.cs @@ -4,6 +4,7 @@ using NLog.Config; using NLog.Targets; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Threading; @@ -141,7 +142,9 @@ namespace IOB_WIN lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; lg.Info(txt2log); // salvo anche in logwatcher... - logWatcher = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | INFO | {txt2log}"; + newDisplayData currDispData = new newDisplayData(); + currDispData.newLiveLogData = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | INFO | {txt2log}"; + updateFormDisplay(currDispData); } /// /// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere... @@ -152,7 +155,9 @@ namespace IOB_WIN lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; lg.Error(txt2log); // salvo anche in logwatcher... - logWatcher = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | ERROR | {txt2log}"; + newDisplayData currDispData = new newDisplayData(); + currDispData.newLiveLogData = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | ERROR | {txt2log}"; + updateFormDisplay(currDispData); } @@ -503,8 +508,11 @@ namespace IOB_WIN gather.Enabled = false; iobObj.tryDisconnect(); } - sIN = Semaforo.SS; - sOUT = Semaforo.SS; + + newDisplayData currDispData = new newDisplayData(); + currDispData.semIn = Semaforo.SS; + currDispData.semOut = Semaforo.SS; + updateFormDisplay(currDispData); } /// @@ -628,6 +636,163 @@ namespace IOB_WIN #endregion + + #region Area BackGroundWorker + + + /// + /// Effettua update form una volta ricevuto OBJ che contiene le varie innovazioni... + /// + /// + public void updateFormDisplay(newDisplayData newData) + { + // ciclo x ogni oggetto x caricare le innovazioni... + if (newData != null) + { + // RealTime display + if (!string.IsNullOrWhiteSpace(newData.newInData)) + { + } + if (!string.IsNullOrWhiteSpace(newData.newSignalData)) + { + } + if (!string.IsNullOrWhiteSpace(newData.newFLogData)) + { + } + if (!string.IsNullOrWhiteSpace(newData.newUrlCallData)) + { + } + + + // LiveLog + if (!string.IsNullOrWhiteSpace(newData.newLiveLogData)) + { + logWatcher = newData.newLiveLogData; + } + // semafori + if (newData.semOut != Semaforo.ND) + { + //aggiorno comunque! + sOUT = newData.semOut; + } + if (newData.semIn != Semaforo.ND) + { + //aggiorno comunque! + sIN = newData.semIn; + } + } + } + + /// + /// Worker x azioni VERSO IL SERVER MES su thread separato + /// + private BackgroundWorker bgWorkerMES; + + // Set up the BackgroundWorker object by + // attaching event handlers. + private void InitializeBgWorkerMes() + { + bgWorkerMES.DoWork += BgWorkerMES_DoWork; + bgWorkerMES.RunWorkerCompleted += BgWorkerMES_RunWorkerCompleted; + bgWorkerMES.ProgressChanged += BgWorkerMES_ProgressChanged; + } + + private void BgWorkerMES_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + //throw new NotImplementedException(); + } + + private void BgWorkerMES_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //throw new NotImplementedException(); + } + + private void BgWorkerMES_DoWork(object sender, DoWorkEventArgs e) + { + //throw new NotImplementedException(); + } + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + // chiudo ANCHE background worker + if (bgWorkerMES != null) + { + bgWorkerMES.Dispose(); + } + } + base.Dispose(disposing); + } +#if false + + //handler for DoWork Event + private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + { + //your background process task + //. + //. + //. + //calculate progress percentage + int progPercentage = 10; + //notify the progress. backGroundWorker_ProgressChanged() will be called + backgroundWorker.ReportProgress(progPercentage); + } + //Handler for Button Click Event + private void btnDoSomeAsyncTask_Click(object sender, EventArgs e) + { + if (backgroundWorker == null) + { + //initialize backgroundworker + backgroundWorker = new BackgroundWorker(); + } + else + { + bool start = true; + //check whether operation is already in progress + if (backgroundWorker.IsBusy) + { + if (MessageBox.Show("The requested task already in progress. Abort current process continue with the fresh task?", +"Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No) + { + start = false; + } + else //cancel the current operation + { + //for this operation WorkerSupportsCancellation shoulb + backgroundWorker.CancelAsync(); + } + } + if (start) + { +#if false + //Call the hooked method backGroundWorker_DoWork() containing object sent in DoWorkEventArgs + backgroundWorker.RunWorkerAsync(objectToBeUsedInAsyncOperation); +#endif + } + } + } + //Handler for progress Changed Event + private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + //update the UI here + ((MainForm)this.Parent).advProgBar(); +#if false + progressBar.Value = e.ProgressPercentage; +#endif + } + //Handler For RunWorkerCompleted event + private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //Task to be performed after completion of background task.Like Give some message. + MessageBox.Show("Task Completed"); + } +#endif + + #endregion + + private void mLoadConf_Click(object sender, EventArgs e) { // mostro selettore file x leggere adapter.. diff --git a/IOB-WIN/GlobalSuppressions.cs b/IOB-WIN/GlobalSuppressions.cs new file mode 100644 index 00000000..73d7ef10 --- /dev/null +++ b/IOB-WIN/GlobalSuppressions.cs @@ -0,0 +1,6 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Gli identificatori non devono contenere caratteri di sottolineatura", Justification = "", Scope = "namespace", Target = "~N:IOB_WIN")] diff --git a/IOB-WIN/IOB-WIN.csproj b/IOB-WIN/IOB-WIN.csproj index 5e1a53b5..f515d365 100644 --- a/IOB-WIN/IOB-WIN.csproj +++ b/IOB-WIN/IOB-WIN.csproj @@ -1,5 +1,10 @@  + + + + + Debug @@ -135,6 +140,7 @@ VersGen.cs + @@ -486,6 +492,17 @@ + + + + + + + + + + + "$(ProjectDir)setupTgt.bat" "$(ConfigurationName)" "$(ProjectDir)" @@ -507,6 +524,11 @@ + + + + + diff --git a/IOB-WIN/IobFanuc.cs b/IOB-WIN/IobFanuc.cs index 49e87d91..40eb7b54 100644 --- a/IOB-WIN/IobFanuc.cs +++ b/IOB-WIN/IobFanuc.cs @@ -519,6 +519,8 @@ namespace IOB_WIN public override void readSemafori() { base.readSemafori(); + // init obj display + newDisplayData currDispData = new newDisplayData(); try { if (verboseLog) @@ -526,7 +528,7 @@ namespace IOB_WIN lgInfo("inizio read semafori"); } - parentForm.sIN = Semaforo.SV; + currDispData.semIn = Semaforo.SV; // inizio letture, SEMPRE DA ZERO (possibile ottimizzazione...) int memIndex = 0; // controllo area R: se ha dati (> 0 byte) --> leggo! @@ -591,7 +593,9 @@ namespace IOB_WIN { lgError(string.Format("Eccezione in readSemafori:{0}{1}", Environment.NewLine, exc)); connectionOk = false; + currDispData.semIn = Semaforo.SR; } + parentForm.updateFormDisplay(currDispData); } /// /// Effettua decodifica aree memoria alla bitmap usata x MAPO diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index 8035c164..6d0d0b31 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -497,7 +497,9 @@ namespace IOB_WIN /// protected void sendToLogWatch(string messType, string message) { - parentForm.logWatcher = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {message}"; + newDisplayData currDispData = new newDisplayData(); + currDispData.newLiveLogData = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {message}"; + parentForm.updateFormDisplay(currDispData); } /// /// Invia messaggio a logWatcher @@ -510,7 +512,9 @@ namespace IOB_WIN try { string expString = string.Format(message, args); - parentForm.logWatcher = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {expString}"; + newDisplayData currDispData = new newDisplayData(); + currDispData.newLiveLogData = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {expString}"; + parentForm.updateFormDisplay(currDispData); } catch { } @@ -527,7 +531,9 @@ namespace IOB_WIN try { string expString = string.Format(message, args); - parentForm.logWatcher = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {expString}{Environment.NewLine}{exception}"; + newDisplayData currDispData = new newDisplayData(); + currDispData.newLiveLogData = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} | {messType} | {expString}{Environment.NewLine}{exception}"; + parentForm.updateFormDisplay(currDispData); } catch { } @@ -1157,46 +1163,56 @@ namespace IOB_WIN /// private void trySendValues() { - // verifico se risponde il server... - if (checkServerAlive) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - // verifico SE posso inviare dati - if (checkIobEnabled) + // verifico se risponde il server... + if (checkServerAlive) { - // verificare come gestire il task secondario senza interferenza (chiamate update su FORM da thread secondari danno errori) - if (utils.CRB("sendDataByThread")) + // verifico SE posso inviare dati + if (checkIobEnabled) { - // invio con thread separato... - Task taskSigIN = TaskEx.Run(() => svuotaCodaSignIN()); - Task taskFlog = TaskEx.Run(() => svuotaCodaFLog()); + // verificare come gestire il task secondario senza interferenza (chiamate update su FORM da thread secondari danno errori) + if (utils.CRB("sendDataByThread")) + { + // invio con thread separato... + Task taskSigIN = TaskEx.Run(() => svuotaCodaSignIN()); + Task taskFlog = TaskEx.Run(() => svuotaCodaFLog()); + } + else + { + // gestione queue SignalIN (invio, display) + svuotaCodaSignIN(); + // gestione queue FluxLog (invio, display) + svuotaCodaFLog(); + } } else { - // gestione queue SignalIN (invio, display) - svuotaCodaSignIN(); - // gestione queue FluxLog (invio, display) - svuotaCodaFLog(); + // mostro VETO-SEND x invio... GIALLO + currDispData.semOut = Semaforo.SG; + if (periodicLog) + { + lgInfo("IOB - VETO SEND"); + } } } else { - // mostro VETO-SEND x invio... GIALLO - parentForm.sOUT = Semaforo.SG; + // mostro SERVER KO x invio... ROSSO + currDispData.semOut = Semaforo.SR; if (periodicLog) { - lgInfo("IOB - VETO SEND"); + lgInfo("IOB - SERVER NOT READY"); } } } - else + catch (Exception exc) { - // mostro SERVER KO x invio... ROSSO - parentForm.sOUT = Semaforo.SR; - if (periodicLog) - { - lgInfo("IOB - SERVER NOT READY"); - } + currDispData.semOut = Semaforo.SR; } + parentForm.updateFormDisplay(currDispData); } /// @@ -2656,23 +2672,33 @@ namespace IOB_WIN /// public virtual void readAllData() { - if (DemoIn) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - // segnalo che sono in Demo - parentForm.sIN = Semaforo.SV; - } - if (connectionOk) - { - readSemafori(); - } - else - { - lgError("Errore connessione mancante x readSemafori"); - } + if (DemoIn) + { + // segnalo che sono in Demo + currDispData.semIn = Semaforo.SV; + } + if (connectionOk) + { + readSemafori(); + } + else + { + lgError("Errore connessione mancante x readSemafori"); + } - nReadIN++; - // aggiorno valore mostrato... - displayRawData(); + nReadIN++; + // aggiorno valore mostrato... + displayRawData(); + } + catch + { + currDispData.semIn = Semaforo.SR; + } + parentForm.updateFormDisplay(currDispData); } /// /// Effettua gestioen programma: legge e mostra su display... @@ -2990,6 +3016,21 @@ namespace IOB_WIN return answ; } /// + /// + /// + /// + /// + /// + /// + public void saveValue(ref Dictionary outVal, double valore, string chiave) + { + bool scaduto = stackVal_TSVC(chiave, valore); + // recupero VC + valore = getVal_TSVC(chiave, scaduto); + if (scaduto) outVal.Add(chiave, $"{valore}"); + LastTSVC[chiave] = valore; + } + /// /// Recupera la VC x TS, svuotando lista e resettando periodo partenza /// /// Nome della VC @@ -3179,48 +3220,58 @@ namespace IOB_WIN /// public void sendDataBlock(urlType tipoUrl, List listQueueVal) { - // recupero e formatto URL dati da coda... - lastUrl = urlDataBlock(tipoUrl); - // in base al tipo di dato compongo il payload Json da inviare - string payload = jsonPayload(tipoUrl, listQueueVal); - // async a true SE FLog - bool doAsync = tipoUrl == urlType.FLog ? true : false; - // se NON sono in demo effettuo invio! - if (!DemoOut) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - // SE server alive... - if (checkServerAlive) + // recupero e formatto URL dati da coda... + lastUrl = urlDataBlock(tipoUrl); + // in base al tipo di dato compongo il payload Json da inviare + string payload = jsonPayload(tipoUrl, listQueueVal); + // async a true SE FLog + bool doAsync = tipoUrl == urlType.FLog ? true : false; + // se NON sono in demo effettuo invio! + if (!DemoOut) { - // chiamo URL! - string answ = callUrlWithPayload(lastUrl, payload, doAsync); - // loggo! - lgInfo($"[SEND payload] {listQueueVal.Count} records --> {answ}"); - // se "OK" verde, altrimenti errore --> ROSSO - if (answ == "OK") + // SE server alive... + if (checkServerAlive) { - parentForm.sOUT = Semaforo.SV; + // chiamo URL! + string answ = callUrlWithPayload(lastUrl, payload, doAsync); + // loggo! + lgInfo($"[SEND payload] {listQueueVal.Count} records --> {answ}"); + // se "OK" verde, altrimenti errore --> ROSSO + if (answ == "OK") + { + currDispData.semOut = Semaforo.SV; + } + else + { + currDispData.semOut = Semaforo.SR; + } } else { - parentForm.sOUT = Semaforo.SR; + lgInfo($"[SERVER KO] {listQueueVal.Count}"); } } else { - lgInfo($"[SERVER KO] {listQueueVal.Count}"); + currDispData.semOut = Semaforo.SV; + // loggo! + lgInfo($"{listQueueVal.Count} records --> [SIM]"); } + nSendOut += listQueueVal.Count; + // riporto cosa inviato + displayOutData(); + // aggiorno data ultimo watchdog... + lastWatchDog = DateTime.Now; } - else + catch { - parentForm.sOUT = Semaforo.SV; - // loggo! - lgInfo($"{listQueueVal.Count} records --> [SIM]"); + currDispData.semOut = Semaforo.SR; } - nSendOut += listQueueVal.Count; - // riporto cosa inviato - displayOutData(); - // aggiorno data ultimo watchdog... - lastWatchDog = DateTime.Now; + parentForm.updateFormDisplay(currDispData); } /// /// Effettua invio a MoonPro del valore richiesto @@ -3231,55 +3282,65 @@ namespace IOB_WIN /// FLog: il valore da trasmettere per il flusso indicato public void sendToMoonPro(urlType tipoUrl, string queueVal) { - // recupero e formatto URL dati da coda... - switch (tipoUrl) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - case urlType.FLog: - lastUrl = urlFLog(queueVal); - break; - case urlType.SignIN: - lastUrl = urlInput(queueVal); - break; - default: - lastUrl = ""; - break; - } - // se NON sono in demo effettuo invio! - if (!DemoOut) - { - // SE server alive... - if (checkServerAlive) + // recupero e formatto URL dati da coda... + switch (tipoUrl) { - // chiamo URL! - string answ = callUrl(lastUrl, false); - // loggo! - lgInfo(string.Format("[SEND] {0} -> {1}", queueVal, answ)); - // se "OK" verde, altrimenti errore --> ROSSO - if (answ == "OK") + case urlType.FLog: + lastUrl = urlFLog(queueVal); + break; + case urlType.SignIN: + lastUrl = urlInput(queueVal); + break; + default: + lastUrl = ""; + break; + } + // se NON sono in demo effettuo invio! + if (!DemoOut) + { + // SE server alive... + if (checkServerAlive) { - parentForm.sOUT = Semaforo.SV; + // chiamo URL! + string answ = callUrl(lastUrl, false); + // loggo! + lgInfo(string.Format("[SEND] {0} -> {1}", queueVal, answ)); + // se "OK" verde, altrimenti errore --> ROSSO + if (answ == "OK") + { + currDispData.semOut = Semaforo.SV; + } + else + { + currDispData.semOut = Semaforo.SR; + } } else { - parentForm.sOUT = Semaforo.SR; + lgInfo(string.Format("[SERVER KO] {0}", queueVal)); } } else { - lgInfo(string.Format("[SERVER KO] {0}", queueVal)); + currDispData.semOut = Semaforo.SV; + // loggo! + lgInfo(string.Format("{0} -> [SIM]", queueVal)); } + nSendOut++; + // riporto cosa inviato + displayOutData(); + // aggiorno data ultimo watchdog... + lastWatchDog = DateTime.Now; } - else + catch { - parentForm.sOUT = Semaforo.SV; - // loggo! - lgInfo(string.Format("{0} -> [SIM]", queueVal)); + currDispData.semOut = Semaforo.SR; } - nSendOut++; - // riporto cosa inviato - displayOutData(); - // aggiorno data ultimo watchdog... - lastWatchDog = DateTime.Now; + parentForm.updateFormDisplay(currDispData); } #endregion diff --git a/IOB-WIN/IobKawasaki.cs b/IOB-WIN/IobKawasaki.cs index f15fa049..95957eaf 100644 --- a/IOB-WIN/IobKawasaki.cs +++ b/IOB-WIN/IobKawasaki.cs @@ -799,21 +799,30 @@ namespace IOB_WIN public override void readSemafori() { base.readSemafori(); - if (verboseLog) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - lgInfo("inizio read semafori"); + if (verboseLog) + { + lgInfo("inizio read semafori"); + } + currDispData.semIn = Semaforo.SV; + + // effettuo TUTTE le letture + threadOk = commThreadOk; + cStatus = currBitmapStatus; + cSignals = currBitmapSignals; + lastCountCNC = pzCounter; + // decodifica e gestione + decodeToBaseBitmap(); + decodeOtherData(); } - - parentForm.sIN = Semaforo.SV; - - // effettuo TUTTE le letture - threadOk = commThreadOk; - cStatus = currBitmapStatus; - cSignals = currBitmapSignals; - lastCountCNC = pzCounter; - // decodifica e gestione - decodeToBaseBitmap(); - decodeOtherData(); + catch + { + currDispData.semIn = Semaforo.SR; + } + parentForm.updateFormDisplay(currDispData); } /// diff --git a/IOB-WIN/IobOSAI.cs b/IOB-WIN/IobOSAI.cs index 2429bf0f..e5a273f0 100644 --- a/IOB-WIN/IobOSAI.cs +++ b/IOB-WIN/IobOSAI.cs @@ -282,6 +282,8 @@ namespace IOB_WIN public override void readSemafori() { base.readSemafori(); + // init obj display + newDisplayData currDispData = new newDisplayData(); try { if (verboseLog) @@ -289,7 +291,7 @@ namespace IOB_WIN lgInfo("inizio read semafori"); } - parentForm.sIN = Semaforo.SV; + currDispData.semIn = Semaforo.SV; stopwatch.Restart(); // possiamo leggere tutto da qui che contiene tutto: status, mode, last_nc_error @@ -308,7 +310,9 @@ namespace IOB_WIN { lgError(string.Format("Eccezione in readSemafori:{0}{1}", Environment.NewLine, exc)); connectionOk = false; + currDispData.semIn = Semaforo.SR; } + parentForm.updateFormDisplay(currDispData); } /// /// Effettua decodifica aree memoria alla bitmap usata x MAPO diff --git a/IOB-WIN/IobOmron.cs b/IOB-WIN/IobOmron.cs index c03391f0..338a223a 100644 --- a/IOB-WIN/IobOmron.cs +++ b/IOB-WIN/IobOmron.cs @@ -645,23 +645,33 @@ namespace IOB_WIN public override void readSemafori() { base.readSemafori(); - if (verboseLog) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - lgInfo("inizio read semafori"); + if (verboseLog) + { + lgInfo("inizio read semafori"); + } + + currDispData.semIn = Semaforo.SV; + + + // effettuo TUTTE le letture + OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 60, out memReadCIO); + //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM); + //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR); + + + lastCountCNC = pesoRilevato; + // decodifica e gestione + decodeToBaseBitmap(); } - - parentForm.sIN = Semaforo.SV; - - - // effettuo TUTTE le letture - OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 60, out memReadCIO); - //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM); - //OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR); - - - lastCountCNC = pesoRilevato; - // decodifica e gestione - decodeToBaseBitmap(); + catch + { + currDispData.semIn = Semaforo.SR; + } + parentForm.updateFormDisplay(currDispData); } /// diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs index e1355c57..5e4d9580 100644 --- a/IOB-WIN/IobSiemens.cs +++ b/IOB-WIN/IobSiemens.cs @@ -377,7 +377,6 @@ namespace IOB_WIN lgInfo($"Init IOB, con {iobConfSer}"); } - /// /// Test connessione CNC /// @@ -810,23 +809,33 @@ namespace IOB_WIN public override void readSemafori() { base.readSemafori(); - if (verboseLog) + // init obj display + newDisplayData currDispData = new newDisplayData(); + try { - lgInfo("inizio read semafori"); - } + currDispData.semIn = Semaforo.SV; - parentForm.sIN = Semaforo.SV; - // leggo TUTTI i byte configurati... - byte[] MemBlock = new byte[parametri.memSizeRead]; - bool fatto = S7ReadBB(ref MemBlock); - Buffer.BlockCopy(MemBlock, 0, RawInput, 0, parametri.memSizeRead); - if (verboseLog) - { - lgInfo(string.Format("RawInput[0]: {0}", utils.binaryForm(RawInput[0]))); + if (verboseLog) + { + lgInfo("inizio read semafori"); + } + // leggo TUTTI i byte configurati... + byte[] MemBlock = new byte[parametri.memSizeRead]; + bool fatto = S7ReadBB(ref MemBlock); + Buffer.BlockCopy(MemBlock, 0, RawInput, 0, parametri.memSizeRead); + if (verboseLog) + { + lgInfo(string.Format("RawInput[0]: {0}", utils.binaryForm(RawInput[0]))); + } + // salvo il solo BYTE dell'input decifrando il semaforo... + decodeToBaseBitmap(); + decodeOtherData(); } - // salvo il solo BYTE dell'input decifrando il semaforo... - decodeToBaseBitmap(); - decodeOtherData(); + catch + { + currDispData.semIn = Semaforo.SR; + } + parentForm.updateFormDisplay(currDispData); } /// /// decodifica da bitmap il CURRENT MODE del controllo @@ -1015,21 +1024,6 @@ namespace IOB_WIN } return outVal; } - /// - /// - /// - /// - /// - /// - /// - private void saveValue(ref Dictionary outVal, double valore, string chiave) - { - bool scaduto = stackVal_TSVC(chiave, valore); - // recupero VC - valore = getVal_TSVC(chiave, scaduto); - if (scaduto) outVal.Add(chiave, $"{valore}"); - LastTSVC[chiave] = valore; - } #endregion } diff --git a/IOB-WIN/packages.config b/IOB-WIN/packages.config index afd5969e..3c1ecd60 100644 --- a/IOB-WIN/packages.config +++ b/IOB-WIN/packages.config @@ -5,6 +5,11 @@ + + + + +