Skip to content

Commit 581c4f8

Browse files
authored
examples: Add README.md files and address Ryan's feedback on the VISA example (#210)
* nivisa_dmm_measurement: Enable simulation by default Signed-off-by: Brad Keryan <brad.keryan@ni.com> * examples: Add README.md files Signed-off-by: Brad Keryan <brad.keryan@ni.com> * README.md: Add VISA example, change example list to bulleted Signed-off-by: Brad Keryan <brad.keryan@ni.com> * examples: Update description of session managment & gRPC device server usage Signed-off-by: Brad Keryan <brad.keryan@ni.com> * sample_measurement: Fix readme title Signed-off-by: Brad Keryan <brad.keryan@ni.com> * examples: Add simulation info, except for NI-FGEN Signed-off-by: Brad Keryan <brad.keryan@ni.com> Signed-off-by: Brad Keryan <brad.keryan@ni.com>
1 parent fdc318b commit 581c4f8

12 files changed

Lines changed: 299 additions & 12 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ There are three ways to do this:
5757

5858
The `examples` directory contains the following example projects:
5959

60-
1. `sample_measurement`: Performs a loopback measurement with various data types.
61-
2. `nidaqmx_analog_input`: Performs a finite analog input measurement with NI-DAQmx.
62-
3. `nidcpower_source_dc_voltage`: Sources and measures a DC voltage with an NI SMU. Provides a Measurement UI
63-
4. `nidcpower_source_dc_voltage_with_labview_ui`: Sources and measures a DC voltage with an NI SMU. Provides a LabVIEW UI
64-
5. `nidmm_measurement`: Performs a measurement using an NI DMM.
65-
6. `nifgen_standard_function`: Generates a standard function waveform using an NI waveform generator.
66-
7. `niscope_acquire_waveform`: Acquires a waveform using an NI oscilloscope.
67-
8. `niswitch_control_relays`: Controls relays using an NI relay driver (e.g. PXI-2567).
60+
- `sample_measurement`: Performs a loopback measurement with various data types.
61+
- `nidaqmx_analog_input`: Performs a finite analog input measurement with NI-DAQmx.
62+
- `nidcpower_source_dc_voltage`: Sources and measures a DC voltage with an NI SMU. Provides a Measurement UI
63+
- `nidcpower_source_dc_voltage_with_labview_ui`: Sources and measures a DC voltage with an NI SMU. Provides a LabVIEW UI
64+
- `nidmm_measurement`: Performs a measurement using an NI DMM.
65+
- `nifgen_standard_function`: Generates a standard function waveform using an NI waveform generator.
66+
- `niscope_acquire_waveform`: Acquires a waveform using an NI oscilloscope.
67+
- `niswitch_control_relays`: Controls relays using an NI relay driver (e.g. PXI-2567).
68+
- `nivisa_dmm_measurement`: Performs a DMM measurement using NI-VISA and an NI Instrument Simulator v2.0.
69+
70+
For more details about a specific example, see the `README.md` file included with the example.
6871

6972
### Setting up the Example Measurements
7073

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## NI-DAQmx Analog Input Measurement
2+
3+
This is a MeasurementLink example that performs a finite analog input
4+
measurement with NI-DAQmx.
5+
6+
### Features
7+
8+
- Uses the `nidaqmx-python` package to access NI-DAQmx from Python
9+
- Demonstrates how to cancel a running measurement using the driver API's
10+
asynchronous abort/cancel function
11+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
12+
- Not pin-aware
13+
- Does not use the MeasurementLink session management service or NI gRPC Device Server
14+
15+
### Required Driver Software
16+
17+
- NI-DAQmx
18+
19+
### Required Hardware
20+
21+
This example requires a DAQmx device that supports AI voltage measurements (e.g.
22+
PCIe-6363 or other X Series device).
23+
24+
To simulate a DAQmx device in software: open `NI MAX`, right-click `Devices and Interfaces`,
25+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## NI-DCPower Source DC Voltage
2+
3+
This is a MeasurementLink example that sources and measures a DC voltage with an NI SMU.
4+
5+
### Features
6+
7+
- Uses the `nidcpower` package to access NI-DCPower from Python
8+
- Demonstrates how to cancel a running measurement by breaking a long wait into
9+
multiple short waits
10+
- Pin-aware, supporting one session and multiple pins
11+
- Sources the same DC voltage level on all selected pin/site combinations
12+
- Measures the DC voltage and current for each selected pin/site combination
13+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
14+
- Includes a TestStand sequence showing how to configure the pin map, register
15+
instrument sessions with the session management service, and run a measurement
16+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
17+
measurement services when running measurements from TestStand
18+
19+
### Required Driver Software
20+
21+
- NI-DCPower
22+
23+
### Required Hardware
24+
25+
This example requires an NI SMU that is supported by NI-DCPower (e.g. PXIe-4141).
26+
27+
To simulate an NI SMU in software: open `NI MAX`, right-click `Devices and Interfaces`,
28+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
29+
SMUs are in the `Power Supplies` category.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## NI-DCPower Source DC Voltage with LabVIEW UI
2+
3+
This is a MeasurementLink example that sources and measures a DC voltage with an NI SMU, with a LabVIEW UI.
4+
5+
### Features
6+
7+
- Uses the `nidcpower` package to access NI-DCPower from Python
8+
- Demonstrates how to use a LabVIEW UI for a Python service
9+
- Demonstrates how to cancel a running measurement by breaking a long wait into
10+
multiple short waits
11+
- Pin-aware, supporting one session, multiple pins, and multiple selected sites
12+
- Sources the same DC voltage level on all selected pin/site combinations
13+
- Measures the DC voltage and current for each selected pin/site combination
14+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
15+
- Includes a TestStand sequence showing how to configure the pin map, register
16+
instrument sessions with the session management service, and run a measurement
17+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
18+
measurement services when running measurements from TestStand
19+
20+
### Required Driver Software
21+
22+
- NI-DCPower
23+
24+
### Required Hardware
25+
26+
This example requires an NI SMU that is supported by NI-DCPower (e.g. PXIe-4141).
27+
28+
To simulate an NI SMU in software: open `NI MAX`, right-click `Devices and Interfaces`,
29+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
30+
SMUs are in the `Power Supplies` category.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## NI-DMM Measurement
2+
3+
This is a MeasurementLink example that performs a measurement using an NI DMM.
4+
5+
### Features
6+
7+
- Uses the `nidmm` package to access NI-DMM from Python
8+
- Pin-aware, supporting one session, one pin, and one selected site
9+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
10+
- Includes a TestStand sequence showing how to configure the pin map, register
11+
instrument sessions with the session management service, and run a measurement
12+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
13+
measurement services when running measurements from TestStand
14+
15+
### Required Driver Software
16+
17+
- NI-DMM
18+
19+
### Required Hardware
20+
21+
This example requires an NI DMM (e.g. PXI-4072).
22+
23+
To simulate an NI DMM in software: open `NI MAX`, right-click `Devices and Interfaces`,
24+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
25+
DMMs are in the `Digital Multimeters` category.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## NI-FGEN Standard Function
2+
3+
This is a MeasurementLink example that generates a standard function waveform
4+
using an NI waveform generator.
5+
6+
### Features
7+
8+
- Uses the `nifgen` package to access NI-FGEN from Python
9+
- Demonstrates how to cancel a running measurement by breaking a long wait into
10+
multiple short waits
11+
- Pin-aware, supporting multiple sessions, multiple pins, and multiple selected sites
12+
- Outputs the same waveform configuration on all selected pin/site combinations
13+
- Does not synchronize waveforms
14+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
15+
- Includes a TestStand sequence showing how to configure the pin map, register
16+
instrument sessions with the session management service, and run a measurement
17+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
18+
measurement services when running measurements from TestStand
19+
20+
### Required Driver Software
21+
22+
- NI-FGEN
23+
24+
### Required Hardware
25+
26+
This example requires an NI waveform generator (e.g. PXIe-5423 (2CH)).
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## NI-SCOPE Acquire Waveform
2+
3+
This is a MeasurementLink example that acquires a waveform using an NI oscilloscope.
4+
5+
### Features
6+
7+
- Uses the `niscope` package to access NI-SCOPE from Python
8+
- Demonstrates how to cancel a running measurement while polling measurement status
9+
- Pin-aware, supporting one session, multiple pins, and one selected site
10+
- Acquires from up to 4 pins
11+
- Trigger source demonstrates mapping a specific pin to a channel
12+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
13+
- Includes a TestStand sequence showing how to configure the pin map, register
14+
instrument sessions with the session management service, and run a measurement
15+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
16+
measurement services when running measurements from TestStand
17+
18+
### Required Driver Software
19+
20+
- NI-SCOPE
21+
22+
### Required Hardware
23+
24+
This example requires an NI oscilloscope (e.g. PXIe-5162 (4CH)).
25+
26+
To simulate an NI oscilloscope in software: open `NI MAX`, right-click `Devices and Interfaces`,
27+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
28+
Oscilloscopes are in the `High Speed Digitizers` category.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## NI-Switch Control Relays
2+
3+
This is a MeasurementLink example that controls relays using an NI relay driver
4+
(e.g. PXI-2567).
5+
6+
### Features
7+
8+
- Uses the `niswitch` package to access NI-SWITCH from Python
9+
- Pin-aware, supporting multiple sessions, multiple pins, and multiple selected sites
10+
- Performs the same operation (open/close relay) on all selected pin/site combinations
11+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
12+
- Includes a TestStand sequence showing how to configure the pin map, register
13+
instrument sessions with the session management service, and run a measurement
14+
- Uses the NI gRPC Device Server to allow sharing instrument sessions with other
15+
measurement services when running measurements from TestStand
16+
17+
### Required Driver Software
18+
19+
- NI-SWITCH
20+
21+
### Required Hardware
22+
23+
This example requires an NI relay driver (e.g. PXI-2567).
24+
25+
To simulate an NI relay driver in software: open `NI MAX`, right-click `Devices and Interfaces`,
26+
select `Create New...`, and select `Simulated NI-DAQmx Device or Modular Instrument`.
27+
Relay drivers are in the `Switches` category.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## NI-VISA DMM Measurement
2+
3+
This is a MeasurementLink example that performs a DMM measurement using NI-VISA
4+
and an NI Instrument Simulator v2.0.
5+
6+
### Features
7+
8+
- Uses the open-source `PyVISA` package to access NI-VISA from Python
9+
- Uses the open-source `PyVISA-sim` package to simulate instruments in software
10+
- Pin-aware, supporting a custom instrument type and a single session/pin/site
11+
- Includes InstrumentStudio and MeasurementLink UI Editor project files
12+
- Includes a TestStand sequence showing how to configure the pin map, register
13+
instrument resources with the session management service, and run a measurement
14+
- Demonstrates how to share instrument resources with other measurement services
15+
when running measurements from TestStand, without using NI gRPC Device Server
16+
17+
### Required Driver Software
18+
19+
- NI-488.2 and/or NI-Serial
20+
- NI-VISA
21+
- Optional: NI Instrument Simulator software
22+
23+
Note: there is no Python instrument driver for the NI Instrument Simulator, so
24+
this example directly performs low-level, device-specific commands and queries.
25+
26+
### Required Hardware
27+
28+
By default, this example does not require hardware; it uses PyVISA-sim to
29+
simulate the instrument in software.
30+
[`NIInstrumentSimulatorV2_0.yaml`](./NIInstrumentSimulatorV2_0.yaml) defines the
31+
behavior of the simulated instrument.
32+
33+
To use NI Instrument Simulator hardware:
34+
- Disable software simulation by setting `USE_SIMULATION = False` in both
35+
[`measurement.py`](./measurement.py) and
36+
[`teststand_fixture.py`](./teststand_fixture.py).
37+
- Connect the NI Instrument Simulator over GPIB or serial.
38+
- By default, the pin map included with this example uses the resource name
39+
`GPIB0::3::INSTR`, which matches the NI Instrument Simulator's factory default
40+
settings when connected via GPIB.
41+
- If this doesn't match your configuration, edit
42+
[`NIVisaDmmMeasurement.pinmap`](./NIVisaDmmMeasurement.pinmap) and replace
43+
`GPIB0::3::INSTR` with the desired resource name (e.g. `ASRL1::INSTR`).
44+
- To modify the NI Instrument Simulator configuration (e.g. GPIB address,
45+
serial configuration), use the `Instrument Simulator Wizard` included with
46+
the NI Instrument Simulator software.
47+
48+
### Session Management
49+
50+
This example has a slightly different approach to session management than the
51+
examples for NI PXI modular instruments.
52+
53+
The examples for NI PXI modular instruments use the NI gRPC Device Server to
54+
share a single driver session between multiple operating system processes. When running
55+
measurements outside of TestStand, each measurement re-initalizes the
56+
instrument. When running measurements in TestStand, the `ProcessSetup` callback
57+
initializes the instrument once per sequence execution, which avoids
58+
the overhead of re-initializing the instrument for each measurement.
59+
60+
This VISA example does not use NI gRPC Device Server. The measurement logic and
61+
TestStand code module open and close VISA driver sessions as needed in multiple
62+
operating system processes. However, the instrument initialization behavior is
63+
the same as before: outside of TestStand, each measurement re-initializes the
64+
instrument; in TestStand, the `ProcessSetup` callback initalizes the instrument
65+
once per sequence execution. This approach works for VISA because multiple
66+
processes (TestStand, multiple measurement services) can connect to the same
67+
instrument without resetting any instrument state.
68+
69+
In both cases, the `ProcessSetup` callback registers the instrument with the
70+
session management service, the measurement logic uses the session management
71+
service to reserve and unreserve the instrument, and the `ProcessCleanup`
72+
callback unregisters the instrument with the session management service. This
73+
ensures that only one measurement at a time has access to the instrument.

examples/nivisa_dmm_measurement/measurement.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"6.5": 1e-6,
4848
}
4949

50+
# To use NI Instrument Simulator v2.0 hardware, set this to False or specify
51+
# --no-use-simulation on the command line.
52+
USE_SIMULATION = True
53+
5054

5155
@measurement_service.register_measurement
5256
@measurement_service.configuration(
@@ -129,7 +133,7 @@ def measure(
129133
)
130134
@click.option(
131135
"--use-simulation/--no-use-simulation",
132-
default=False,
136+
default=USE_SIMULATION,
133137
is_flag=True,
134138
help="Use simulated instruments.",
135139
)

0 commit comments

Comments
 (0)