public EnsorIOSocketAdaptor(ref EnsorIOController ioController) { stopWatch = new Stopwatch(); stopWatch.Start(); ensorIOController = ioController; checkReceiveFreq = 50; //Hz }
private void btnBrowse_Click(object sender, EventArgs e) { int counter = 0; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "E'nsor Config files (*.EnsConfLst)|*.EnsConfLst"; openFileDialog1.DefaultExt = "EnsConfLst"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; allowUpdateGUI = false; updateGUI.Abort(); while (updateGUI.IsAlive) {} if (openFileDialog1.ShowDialog() == DialogResult.OK) { txtbConfigFile.Text = openFileDialog1.FileName; ensorIOController = new EnsorIOController(openFileDialog1.FileName); txtbDigInputsFilter.Enabled = true; txtbDigOutputsFilter.Enabled = true; // Create panel digital outputs pnlDigOutputs.Controls.Clear(); counter = 0; foreach (DigOutput digOutput in ensorIOController.digOutputs) { Label tempLabel = new Label(); tempLabel.Name = digOutput.Symbol; tempLabel.Text = digOutput.Symbol; tempLabel.AutoSize = false; tempLabel.Location = new System.Drawing.Point(9, 4 + counter * yOffsetTextboxes); tempLabel.Size = new System.Drawing.Size(pnlDigInputs.Width-60, 14); tempLabel.DoubleClick += tempLabelOutput_DoubleClick; tempLabel.Click += tempLabelOutput_Click; tempLabel.BackColor = brushFalse; pnlDigOutputs.Controls.Add(tempLabel); counter++; } // Create panel digital inputs pnlDigInputs.Controls.Clear(); counter = 0; foreach (DigInput digInput in ensorIOController.digInputs) { Label tempLabel = new Label(); tempLabel.Name = digInput.Symbol; tempLabel.Text = digInput.Symbol; tempLabel.AutoSize = false; tempLabel.Location = new System.Drawing.Point(9, 4 + counter * yOffsetTextboxes); tempLabel.Size = new System.Drawing.Size(pnlDigInputs.Width - 60, 14); tempLabel.DoubleClick += tempLabelInput_DoubleClick; tempLabel.Click += tempLabelInput_Click; tempLabel.BackColor = brushFalse; pnlDigInputs.Controls.Add(tempLabel); counter++; } // clear all group boxes num outputs pnlNumOutputs.Controls.Clear(); counter = 0; foreach (NumOutput numOutput in ensorIOController.numOutputs) { // create groupbox GroupBox tempGroupbox = new GroupBox(); tempGroupbox.Location = new System.Drawing.Point(9, 4 + counter * yOffsetGrouboxes); tempGroupbox.Name = numOutput.Symbol; tempGroupbox.Text = numOutput.Symbol; tempGroupbox.Size = new System.Drawing.Size(258, 69); tempGroupbox.TabIndex = 2; tempGroupbox.TabStop = false; // create textbox TextBox tempTextbox = new TextBox(); tempTextbox.Location = new System.Drawing.Point(7, 20); tempTextbox.Name = numOutput.Symbol; ; tempTextbox.Size = new System.Drawing.Size(56, 20); tempTextbox.TabIndex = 1; tempTextbox.Text = numOutput.DefVal.ToString("0.###"); tempTextbox.KeyPress += tempTextboxOutput_KeyPress; tempTextbox.TextChanged += tempTextboxOutput_TextChanged; // create slider TrackBar tempTrackbar = new TrackBar(); tempTrackbar.Location = new System.Drawing.Point(69, 19); tempTrackbar.Name = numOutput.Symbol; tempTrackbar.Size = new System.Drawing.Size(183, 45); tempTrackbar.TabIndex = 0; tempTrackbar.Minimum = Math.Min((int)(numOutput.MaxVal * trackBarRescaler), (int)(numOutput.MinVal * trackBarRescaler)); tempTrackbar.Maximum = Math.Max((int)(numOutput.MaxVal * trackBarRescaler), (int)(numOutput.MinVal * trackBarRescaler)); tempTrackbar.SmallChange = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 100; tempTrackbar.LargeChange = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 10; tempTrackbar.TickFrequency = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 10; tempGroupbox.Controls.Add(tempTextbox); tempGroupbox.Controls.Add(tempTrackbar); pnlNumOutputs.Controls.Add(tempGroupbox); counter++; } // clear all group boxes num inputs pnlNumInputs.Controls.Clear(); counter = 0; foreach (NumInput numInput in ensorIOController.numInputs) { // create groupbox GroupBox tempGroupbox = new GroupBox(); tempGroupbox.Location = new System.Drawing.Point(9, 4 + counter * yOffsetGrouboxes); tempGroupbox.Name = numInput.Symbol; tempGroupbox.Text = numInput.Symbol; tempGroupbox.Size = new System.Drawing.Size(258, 69); tempGroupbox.TabIndex = 2; tempGroupbox.TabStop = false; // create textbox TextBox tempTextbox = new TextBox(); tempTextbox.Location = new System.Drawing.Point(7, 20); tempTextbox.Name = numInput.Symbol; ; tempTextbox.Size = new System.Drawing.Size(56, 20); tempTextbox.TabIndex = 1; tempTextbox.Text = numInput.CurrentVal.ToString("0.###"); tempTextbox.KeyPress += tempTextboxInput_KeyPress; tempTextbox.TextChanged += tempTextboxInput_TextChanged; // create slider TrackBar tempTrackbar = new TrackBar(); tempTrackbar.Location = new System.Drawing.Point(69, 19); tempTrackbar.Name = numInput.Symbol; tempTrackbar.Size = new System.Drawing.Size(183, 45); tempTrackbar.TabIndex = 0; tempTrackbar.Minimum = Math.Min((int)(numInput.MaxVal * trackBarRescaler), (int)(numInput.MinVal * trackBarRescaler)); tempTrackbar.Maximum = Math.Max((int)(numInput.MaxVal * trackBarRescaler), (int)(numInput.MinVal * trackBarRescaler)); ; tempTrackbar.SmallChange = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 100; tempTrackbar.LargeChange = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 10; tempTrackbar.TickFrequency = (int)(tempTrackbar.Maximum - tempTrackbar.Minimum) / 10; tempGroupbox.Controls.Add(tempTextbox); tempGroupbox.Controls.Add(tempTrackbar); pnlNumInputs.Controls.Add(tempGroupbox); counter++; } } allowUpdateGUI = true; updateGUI = new Thread(new ThreadStart(this.UpdateGui)); updateGUI.Start(); }