Example Code

Switch State Machine

Code and Documents

Attachment

Overview

This code provides an example of how to implement a state machine with the NI-DAQmx drivers for NI Switches. The state machine is controlled by the action the user enables.

Description

This state machine allows the user to connect and disconnect switch channels manually while the VI is running. The Type Def'd enum used in the state machine is included (Control 1.ctl).

The following example proceeds by executing the following steps:

  1. Initializes the device.
  2. Starts the state machine in a "Wait" state.
  3. Executes the State Machine:
    1. Connects the selected channels.
    2. Disconnects the selected channels.
    3. Waits for the user to change the action type.
  4. Changes state based on button press:
    1. When button is pressed, the state is changed to the selected action.
    2. If button is not pressed, sets the current state to "Wait".
  5. Stops the VI if button is pressed or if an error occurs.
  6. Resets switches to default topology

Block Diagram

Switch State Machine VI Snippet.png

Steps to Implement or Execute Code

  1. Configure your switch device and topology on the front panel
  2. Click Run
  3. Select the switch channels that you want to modify
  4. Choose the action you want to perform from the drop down list (Connect, Disconnect or Wait)
  5. Click "Enable Action" button (OK Button). This will perform the action and go to the "Wait" state
  6. Continue to use by selecting actions and enabling them

Requirements to Run

Software

  • LabVIEW (Version 8.6 or later)
  • DAQmx Compatible with LabVIEW version

Hardware

  • Simulated or real Switch Device
Product Manager for Product Data
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors