//Analog Detach event handler...Clear all the fields and disable all the controls void analog_Detach(object sender, DetachEventArgs e) { Phidgets.Analog detached = (Phidgets.Analog)sender; attachedTxt.Text = detached.Attached.ToString(); nameTxt.Clear(); serialTxt.Clear(); versiontxt.Clear(); numChannelsTxt.Clear(); for (int i = 0; i < 4; i++) { ChannelBox.Controls["en" + i].Enabled = false; ChannelBox.Controls["vSlider" + i].Enabled = false; ((TextBox)ChannelBox.Controls["volt" + i]).Clear(); ((TrackBar)ChannelBox.Controls["vSlider" + i]).Value = 0; ((CheckBox)ChannelBox.Controls["en" + i]).Checked = false; } }
//Analog Attach event handler...populate the fields and controls void analog_Attach(object sender, AttachEventArgs e) { Phidgets.Analog attached = (Phidgets.Analog)sender; attachedTxt.Text = attached.Attached.ToString(); nameTxt.Text = attached.Name; serialTxt.Text = attached.SerialNumber.ToString(); versiontxt.Text = attached.Version.ToString(); numChannelsTxt.Text = attached.outputs.Count.ToString(); for (int i = 0; i < 4; i++) { ChannelBox.Controls["vSlider" + i].Enabled = true; ChannelBox.Controls["en" + i].Enabled = true; ((TrackBar)ChannelBox.Controls["vSlider" + i]).Minimum = (int)Math.Round(attached.outputs[i].VoltageMin * 100); ((TrackBar)ChannelBox.Controls["vSlider" + i]).Maximum = (int)Math.Round(attached.outputs[i].VoltageMax * 100); ((TextBox)ChannelBox.Controls["volt" + i]).Text = attached.outputs[i].Voltage.ToString("F2") + "v"; ((TrackBar)ChannelBox.Controls["vSlider" + i]).Value = (int)Math.Round(attached.outputs[i].Voltage * 100); ((CheckBox)ChannelBox.Controls["en" + i]).Checked = attached.outputs[i].Enabled; } }