Admin Production ni-theme
Current Publication

Programming with Numeric Controls

LabWindows/CVI

Programming with Numeric Controls

This topic describes how to complete the following tasks programmatically.

Creating Numeric Controls

Use NewCtrl to create a numeric control.

int numCtrl;

numCtrl = NewCtrl (panelHandle, CTRL_NUMERIC_LS, "Numeric Control", 40, 40);

Setting and Obtaining the Value of a Numeric Control

Use SetCtrlVal to set a numeric control to a particular value.

SetCtrlVal (panelHandle, PANEL_NUMERIC, 75.0);

Use GetCtrlVal to obtain the current value of a numeric control.

double currentValue;

GetCtrlVal (panelHandle, PANEL_NUMERIC, &currentValue);
SetCtrlVal (panelHandle, PANEL_NUMERIC_2, currentValue);

Specifying Minimum and Maximum Values

Use SetCtrlAttribute with ATTR_MAX_VALUE and ATTR_MIN_VALUE to specify the minimum and maximum values of a numeric control.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_MAX_VALUE, 20.0);
SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_MIN_VALUE, -20.0);

Specifying the Numerical Format

Use SetCtrlAttribute with ATTR_FORMAT to specify the numerical format of the control.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_FORMAT, VAL_DECIMAL_FORMAT);

Specifying the Value by Which to Increment the Numeric Control

Use SetCtrlAttribute with ATTR_FORMAT to specify the value by which to increment the numeric control.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_INCR_VALUE, 5.0);

Adding Range Checking

Use SetCtrlAttribute with ATTR_CHECK_RANGE to add range checking.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_CHECK_RANGE, VAL_NOTIFY);

Showing the Radix

Use SetCtrlAttribute with ATTR_SHOW_RADIX to display the radix.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_SHOW_RADIX, 1);

Binding to a DataSocket Source

(Linux) Data binding is not supported.

Controls can have only one DataSocket connection. You must specify whether the access mode is READ mode or WRITE mode:

  • READ mode—The control gets data from the DataSocket source. In READ mode, the value of the numeric control is updated automatically when the value changes at the source.
  • WRITE mode—The control transfers data to the DataSocket source. In WRITE mode, the value at the DataSocket source is updated automatically when the value of the numeric control changes.

You must enable the DataSocket option in the Edit Installer dialog box Drivers & ComponentsDrivers & Components tab if your applications use data binding.

Binding to a DataSocket Source in the User Interface Editor

Complete the following steps to bind a network variable to a string control.

  1. In the Edit Numeric dialog box, click the DataSocket Binding button.
  2. Click the browse button to the right of the Server text box in the DataSocket Binding dialog box.
  3. Select the network variable you want to bind and click the OK button.
  4. Select whether you want to read or write data in the Connection Type option.
  5. Click the OK button.

Binding to a DataSocket Source Programmatically

Use DSBindCtrl to bind a numeric control to a DataSocket source.

HRESULT dsError;
DSHandle dsHandle;

DSBindCtrl (panelHandle, PANEL_NUMERIC, "opc://localhost/National Instruments.OPCDemo/MotorRPMSensor", VAL_DS_READ, &dsHandle, &dsError);

Use DSUnbind to disconnect the numeric control from the DataSocket source.

DSUnbind (panelHandle, PANEL_NUMERIC, &dsError);

Related Topics

Programming with Controls

Numeric Control Functions