private void boolControl_CheckedChanged(object sender, EventArgs e) { // The user is setting a Bool attribute try { if (!updatingControls && tree.SelectedNode != null && tree.SelectedNode.Tag is ImaqdxBoolAttribute) { ImaqdxBoolAttribute attribute = (ImaqdxBoolAttribute)tree.SelectedNode.Tag; attribute.Value = boolControl.Checked; } } catch (Exception error) { MessageBox.Show(error.ToString(), "NI-IMAQdx Error"); } }
private void UpdateItem(ImaqdxAttribute attribute) { attributeInfo.Clear(); // If we are not displaying any attribute, switch to the empty tab // and return if (attribute == null) { tabControl.SelectedIndex = tabControl.TabPages.IndexOf(emptyPage); return; } // Show some useful generic information about the attribute attributeInfo.Text += "Name: " + attribute.Name + "\r\n"; attributeInfo.Text += "Display Name: " + attribute.DisplayName + "\r\n"; attributeInfo.Text += "Description: " + attribute.Description + "\r\n"; attributeInfo.Text += "ToolTip: " + attribute.Tooltip + "\r\n"; attributeInfo.Text += "Units: " + attribute.Units + "\r\n"; attributeInfo.Text += "Type: " + attribute.Type.ToString() + "\r\n"; attributeInfo.Text += "Access: " + (attribute.Readable ? "R" : "") + (attribute.Writable ? "W" : "") + "\r\n"; attributeInfo.Text += "Visibility: " + attribute.Visibility.ToString() + "\r\n"; // Now we need to go through each of the basic types that need different // controls populated. We use different tabs to contain the different // controls to easily hide the ones not in use. While the base ImaqdxAttribute // class will let you access the attribute in a basic fashion, to get all the // functionality we need to cast it to a more specific type if (attribute is ImaqdxEnumAttribute) { // This is an enumeration so switch to the Enum page ImaqdxEnumAttribute enumAttribute = (ImaqdxEnumAttribute)attribute; tabControl.SelectedIndex = tabControl.TabPages.IndexOf(enumPage); // Update the combobox with all the available enumerations enumItemsBox.Items.Clear(); enumItemsBox.Items.AddRange(enumAttribute.GetSupportedValues()); // If the attribute is readable, set the currently active value if (enumAttribute.Readable) { enumItemsBox.SelectedItem = enumAttribute.Value; } // If the attribute is writable, enable the control enumItemsBox.Enabled = enumAttribute.Writable; } else if (attribute is ImaqdxNumericAttribute) { // This is a numeric attribute so switch to the Numeric page // Note that there are several different numeric types but we can treat // them more or less the same. The numeric attribute type uses the "decimal" // type which can contain most reasonable values of all the different types // (UInt32, Int64, Double) ImaqdxNumericAttribute numericAttribute = (ImaqdxNumericAttribute)attribute; tabControl.SelectedIndex = tabControl.TabPages.IndexOf(numericPage); rangeLabel.Text = "Min: " + numericAttribute.Minimum.ToString() + "\r\n"; rangeLabel.Text += "Max: " + numericAttribute.Maximum.ToString() + "\r\n"; rangeLabel.Text += "Increment: " + numericAttribute.Increment.ToString(); numericControl.Minimum = (decimal)numericAttribute.Minimum; numericControl.Maximum = (decimal)numericAttribute.Maximum; numericControl.Increment = (decimal)numericAttribute.Increment; // We'll only show decimal places if it is a double attribute. All the rest // are integer types numericControl.DecimalPlaces = numericAttribute is ImaqdxDoubleAttribute ? 5 : 0; // If the attribute is readable, set the currently active value if (numericAttribute.Readable) { numericControl.Value = (decimal)numericAttribute.Value; } // If the attribute is writable, enable the control numericControl.Enabled = numericAttribute.Writable; } else if (attribute is ImaqdxStringAttribute) { // This is a string attribute so switch to the String page ImaqdxStringAttribute stringAttribute = (ImaqdxStringAttribute)attribute; tabControl.SelectedIndex = tabControl.TabPages.IndexOf(stringPage); stringControl.Clear(); // If the attribute is readable, set the currently active value if (stringAttribute.Readable) { stringControl.Text = stringAttribute.Value; } // If the attribute is writable, enable the control stringControl.Enabled = stringSetButton.Enabled = stringAttribute.Writable; } else if (attribute is ImaqdxBoolAttribute) { // This is a bool attribute so switch to the Bool page ImaqdxBoolAttribute boolAttribute = (ImaqdxBoolAttribute)attribute; tabControl.SelectedIndex = tabControl.TabPages.IndexOf(boolPage); // If the attribute is readable, set the currently active value if (boolAttribute.Readable) { boolControl.Checked = boolAttribute.Value; } // If the attribute is writable, enable the control boolControl.Enabled = boolAttribute.Writable; } else if (attribute is ImaqdxCommandAttribute) { // This is a command attribute so switch to the Command page ImaqdxCommandAttribute commandAttribute = (ImaqdxCommandAttribute)attribute; tabControl.SelectedIndex = tabControl.TabPages.IndexOf(commandPage); // If the attribute is writable, enable the control commandControl.Enabled = commandAttribute.Writable; } }