USB-6451 Examples

NI installs example code with your software or driver that demonstrates the functionality of USB-6451. Use these examples to learn about the product or accelerate your own application development.

Most NI products install examples that you can access directly or from within NI software. The example experience can differ slightly across products and versions.

LabVIEW Examples

USB-6451 LabVIEW examples are located in the %ProgramFiles%\NI\LVAddons\nidaqmx\1\examples\NI-DAQmx directory.

Table 4. Common USB-6451 LabVIEW Examples
Example Name Description
Voltage (with Events) - Continuous Input Demonstrates how to continuously acquire buffered voltage measurements. It uses software events to ensure that the program does not become unresponsive while waiting for samples to become available.
Voltage - Continuous Input Demonstrates how to continuously acquire voltage measurement.
Voltage - Finite Input Demonstrates how to acquire a single buffer of voltage measurements.
Voltage - SW-Timed Input Demonstrates how to acquire a voltage based off of software timing.
Voltage - Continuous Output Demonstrates how to continuously re-generate analog output data from a buffer in your computer's memory.
Voltage - Finite Output Demonstrates how to output a voltage based on a finite amount of data from a buffer in your computer's memory.
Voltage - On Demand Output Demonstrates how to generate a user-defined voltage using the analog output.
Counter - Count Edges Demonstrates how to continuously read back the number of digital edges that have been counted by a counter input.
Counter - Read Encoder Demonstrates how to use a counter to continually monitor the angular position of an encoder.
Counter - Read Pulse Duty Cycle and Frequency (Continuous) Demonstrates how to configure a pulse measurement to acquire frequency and duty cycle based off of an external clock.
Counter - Continuous Output Demonstrates how to continuously generate digital pulses using a counter output.
Counter - Finite Output Demonstrates how to generate a finite number of digital pulses using a counter output. On some hardware, this requires the use of a second counter to generate a gate signal.
Counter - Single Pulse Output Demonstrates how to generate a single pulse using a counter output. The single pulse may be triggered once or repeatedly from an external source.
Digital - Change Detection Demonstrates how to acquire a continuous amount of digital data based off of the changes of an external signal across one or many lines on either the rising or falling edges.
Digital - Continuous Input Demonstrates how to acquire a continuous amount of digital data based off of a sample clock.
Digital - SW-Timed Input Demonstrates how to acquire the state of digital lines based off of software timing.
Digital - Continuous Output This example Demonstrates how to generate a continuous amount of digital data based off of a sample clock.
Digital - Finite Output Demonstrates how to generate a finite amount of digital data based off of a sample clock.
Digital - SW-Timed Output Demonstrates how to generate digital output data using software timing.

Python Examples in

USB-6451 Python examples are located in GitHub at github.com/ni/nidaqmx-python/tree/master/examples.

Table 5. Common USB-6451 Python Examples
Example Name Description
analog_in/cont_voltage_acq_int_clk.py Demonstrates how to acquire a continuous amount of data using the USB-6451's internal clock.
analog_in/cont_voltage_acq_int_clk_every_n_samples_event.py Demonstrates how to use Every N Samples events to acquire a continuous amount of data using the USB-6451's internal clock. The Every N Samples events indicate when data is available from NI-DAQmx.
analog_in/voltage_acq_int_clk.py Demonstrates how to acquire a finite amount of DATA using the USB-6451's internal clock.
analog_in/voltage_sample.py Demonstrates how to acquire a voltage measurement using software timing.
analog_out/cont_gen_voltage_wfm_int_clk.py Demonstrates how to output a continuous periodic waveform using an internal sample clock.
analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py Demonstrates how to use a Every N Samples events to output a continuous periodic waveform to an Analog Output Channel using an internal sample clock. The Every N Samples events indicate when the specified number of samples generation is complete.
analog_out/gen_voltage_wfm_int_clk.py Demonstrates how to output a finite number of voltage samples to an Analog Output Channel using an internal sample clock.
analog_out/voltage_update.py Demonstrates how to output a single Voltage Update (Sample) to an Analog Output Channel.
counter_in/cnt_dig_event.py Demonstrates how to count digital events on a Counter Input Channel. You can configure the Initial Count, Count Direction, and Edge.
counter_in/read_pulse_freq.py Demonstrates how to configure a pulse measurement to acquire frequency and duty cycle.
counter_out/cont_gen_dig_pulse_train.py Demonstrates how to generate a continuous digital pulse train from a Counter Output Channel. You can configure the Frequency, Duty Cycle, and Idle State.
counter_out/write_single_dig_pulse.py Demonstrates how to generate a single digital pulse from a Counter Output Channel. You can configure the Initial Delay, High Time, Low Time, and Idle State.
digital_in/acq_dig_port_int_clk.py Demonstrates how to input a finite digital pattern using the USB-6451's internal clock.
digital_in/cont_acq_dig_lines_int_clk.py Demonstrates how to acquire a continuous digital waveform using the USB-6451's internal clock.
digital_in/read_dig_lines.py Demonstrates how to read values from one or more digital input channels.
digital_in/read_dig_port.py Demonstrates how to read values from a digital input port.
digital_out/cont_gen_dig_port_int_clk.py Demonstrates how to output a continuous digital pattern using the USB-6451's clock.
digital_out/gen_dig_line_int_clk.py Demonstrates how to output a finite digital waveform using the USB-6451's internal clock.
digital_out/write_dig_lines.py Demonstrates how to write values to a digital output channel.
digital_out/write_dig_port.py Demonstrates how to write values to a digital output port.
system_properties.py Demonstrates how to use system properties in NI-DAQmx.

.NET Examples

USB-6451 examples in .NET are located in the Users\Public\Public Documents\National Instruments\NI-DAQ\Examples\... directory.

Table 6. Common USB-6451 .NET Examples
Example Name Description
Analog In\Measure Voltage\AcqMultVoltageSamples_SWTimed\CS\AcqMultVoltageSamples_SWTimed.sln Demonstrates how to acquire a finite amount of data using a software timer.
Analog In\Measure Voltage\AcqOneVoltageSample\CS\AcqOneVoltageSample.sln Demonstrates how to acquire a single reading from a constant or slowly varying signal.
Analog In\Measure Voltage\AcqVoltageSamples_IntClk\CS\AcqVoltageSamples_IntClk.sln Demonstrates how to acquire a finite amount of data using an internal clock.
Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk\CS\ContAcqVoltageSamples_IntClk.sln Demonstrates how to acquire a continuous amount of data using the USB-6451's internal clock.
Analog In\Measure Voltage\ContAcqVoltageSamples_SWTimed\CS\ContAcqVoltageSamples_SWTimed.sln Demonstrates how to acquire a continuous amount of data using a software timer.
Analog Out\Generate Voltage\ContGenVoltageWfm_IntClk\CS\ContGenVoltageWfm_IntClk.sln Demonstrates how to continuously output a periodic waveform using an internal sample clock.
Analog Out\Generate Voltage\GenMultVoltUpdates_IntClk\CS\GenMultVoltUpdates_IntClk.sln Demonstrates how to output multiple voltage updates (samples) to an analog output channel.
Analog Out\Generate Voltage\GenMultVoltUpdates_SWTimed\CS\GenMultVoltUpdates_SWTimed.sln Demonstrates how to output multiple voltage updates (samples) to an analog output channel in a software timed loop.
Analog Out\Generate Voltage\GenVoltageUpdate\CS\GenVoltageUpdate.sln Demonstrates how to output a single voltage update (sample) to an analog output channel.
Counter\Count Digital Events\CountDigEvents\CS\CountDigEvents.sln

Demonstrates how to count digital events on a Counter Input Channel. You can configure the Initial Count, Count Direction, and Edge. This example shows how to count edges on the counter's default source pin, but you could easily expand it to count edges on any PFI or internal signal.

You can also use a digital pause trigger for counting non-buffered digital events. To add a digital pause trigger to this example, configure the trigger object for the task.

Counter\Count Digital Events\CountDigEventsBuffContinuous_ExtClk\CS\CountDigEventsBuffContinuous_ExtClk.sln

Demonstrates how to count buffered digital events on a Counter Input channel. You can configure the initial count, count direction, edge, and sample clock source. Edges are counted on the counter's default input terminal, but you could easily modify it to count edges on a PFI line.

Note For buffered event counting, an external sample clock is necessary to signal when a sample should be inserted into the buffer. Specify the source terminal of the external clock in the clock source text box when you run the example.
Counter\Generate Pulse\GenDigPulse\CS\GenDigPulse.sln Demonstrates how to generate a single digital pulse from a counter output channel. You can configure the initial delay, high time, low time, and idle state in software. This example shows how to configure the pulse in terms of time, but you can easily modify it to generate a pulse in terms of frequency and duty cycle or ticks.
Counter\Generate Pulse\GenDigPulseTrain_Continuous\CS\GenDigPulseTrain_Continuous.sln Demonstrates how to generate a continuous digital pulse train from a counter output channel. You can configure the frequency, duty cycle, and idle state. This example shows how to configure the pulse in terms of frequency and duty cycle, but you can easily modify it to generate a pulse in terms of time or ticks.
Digital\Generate Values\WriteDigChan\CS\WriteDigChan.sln Demonstrates how to write values to a digital output channel.
Digital\Generate Values\WriteDigPort\CS\WriteDigPort.sln Demonstrates how to write values to a digital output port.
Digital\Read Values\ReadDigChan\CS\ReadDigChan.sln Demonstrates how to read values from one or more digital input channels.
Digital\Read Values\ReadDigPort\CS\ReadDigPort.sln Demonstrates how to read a single value from a digital port.

Browsing and Searching for Examples in NI Example Finder

Use NI Example Finder to browse and to search for examples.

You can use NI Example Finder to find examples for the following products.
  • LabVIEW
  • LabWindows/CVI
  • NI drivers accessible from LabVIEW
  • NI drivers accessible from LabWindows/CVI
  1. Launch LabVIEW or LabWindows/CVI.
  2. Open NI Example Finder.
    OptionDescription
    LabVIEW Select Help » Find Examples. from the menu bar.
    LabWindows/CVI Click Find Examples... from the Examples section of the Welcome Page.
    NI Example Finder launches.
  3. Optional: Configure NI Example Finder for LabWindows/CVI.
    1. Click Setup. Configure Example Finder opens.
    2. In Configure Example Finder, click Software, then select LabWindows/CVI, and click OK.
    NI Example Finder updates with all the examples for LabWindows/CVI.
  4. Search the example VIs for your product.
    OptionDescription
    Click the Browse tab. Choose Browse when you want to drill down through folders to find examples organized by task category.
    Tip Examples installed with NI drivers or third-party drivers are often found within the Hardware Input and Output folder. Examples installed with toolkits or modules are often found within the Toolkits and Modules folder.
    Click the Search tab. Choose Search when you want to find examples by searching for topics, products, or modules relevant to your application.
  5. To open an example, double-click the folder or the example.
    Tip You can modify an example VI to fit your application. You can also copy and paste from one or more examples into a VI that you create.