Table Of Contents

Using the Asynchronous Custom Device Driver Template

Last Modified: June 10, 2021

Use the asynchronous custom device driver template to build the RT Driver VI for a custom device.

You can use most of the Custom Device API VIs when building an asynchronous RT Driver VI. The Asynchronous Device Properties VIs and Asynchronous Device Channels VIs configure functionality exclusive to asynchronous custom devices.

An asynchronous custom device uses a two-loop architecture, one loop for receiving commands and one for transferring data, with sections of code for initialization and cleanup before and after the loops, respectively. The template VI uses a While Loop for data transfer, but you also can use a Timed Loop.

In general, you use a While Loop if timing is not important or if you want the loop to run as fast as it can. You use a Timed Loop if you need the loop to execute deterministically or run pseudo-synchronously with the Primary Control Loop.
  1. Navigate to the labview\vi.lib\NI VeriStand\Custom Device API directory and open Asynchronous Custom Device Template.vit.
  2. Modify the following code to set up your controls and initialization for the custom device.
    Controls—The input controls are specially named controls that the VeriStand Engine will use to provide the asynchronous custom device loops with data. To function, the name of each control must match the following names.
    • Device Clock—Device Clock specifies the name of a timing source that is ticked for every iteration of the Primary Control Loop after Custom Device FIFOs have been updated.

      If you change the data loop of your custom device to a Timed Loop, you can use Device Clock as the timing source of the Timed Loop to closely synchronize your asynchronous custom device with the Primary Control Loop. Device Clock is only populated if you set the Use Device Clock input of the Set Loop Type VI to True in one of the VIs for configuring the custom device.

    • Initialization Status Notifier—You can use this optional input to send the VeriStand Engine the final status of the custom device initialization process. If this control exists on the custom device front panel, the VeriStand Engine will wait for a status update before starting up. If the custom device reports an error, that will abort the execution of the current configuration in the VeriStand Engine.
    • Device Reference—Device Reference is an auto-populated reference to the custom device. Use it to read configuration properties, get a list of channels, etc.
    • Device Outputs FIFO—The array of outputs sent to the system on the Device Outputs FIFO corresponds one-to-one to the Outputs array the Get Custom Device Channel List VI returns. By default, the VeriStand Engine reads the Device Outputs FIFO every iteration of the PCL.
    • Device Inputs FIFO—The array of inputs received from the system on the Device Inputs FIFO corresponds one-to-one to the Inputs array the Get Custom Device Channel List VI returns. The VeriStand engine pushes data to the Device Inputs FIFO every iteration of the PCL. If the FIFO is full, the new data packet will overwrite the oldest data packet.
    • Status Notifier—Notifies the engine of the last state of the custom device and indicates when the device completes execution. If you do not use this control, the device returns a default No Error value when it completes execution. By default, VeriStand does not check this error until shutdown, but you can use an output channel to send more immediate status values to the system.
    Initialization Code—The template includes initialization code to do the following:
    1. Register custom engine events.
    2. Get the number of input and output channels and set up data buffers for the RT FIFOs.
    3. Read a final error status for the asynchronous custom device.

    If you use a Timed Loop for your data loop, you can also add code here to configure the Timed Loop.

  3. Modify the following code to set up your command loop, data loop, and cleanup code for the custom device.

    Command Loop—The command loop allows you to send commands to and receive data from your custom device that you can not easily do using a DBL channel value. By using the Send Custom Device Message VI in a LabVIEW VI or calling a corresponding .NET method, you can use, for example, a custom workspace object or NI TestStand automation script to send a command to your custom device, which can then execute a response to that command.

    For example, a generic custom device for logging. If you need to change configuration data, such as the file path to which to save log files, at run time, you could create a custom workspace control to send this data to the command loop of the device, and then configure the command loop to update the configuration data when the data is received.

    The command loop contains the following three events:
    1. Message (Byte Array)—Receives and sends data as a byte array of 8-bit unsigned integer values.
    2. Message (String)—Receives and sends data as a string.
    3. Shut Down—The VeriStand Engine sends this command to indicate that the custom device should shut down.

    For an example custom device that uses Send Custom Device Message VI in a LabVIEW VI to communicate directly with the custom device, refer to the labview\examples\NI Veristand\Custom Devices\Communication Example directory.

    Data Loop—Use this loop to read input data from the Device Inputs FIFO, update the data, and send the updated data via the Device Outputs FIFO to the rest of VeriStand. The template data loop contains code that reads the input data, adds it to a random number, and writes it back to the output channels. The data loop also executes shutdown if it receives a shut down notification from the command loop.
    Cleanup Code—Use the optional Status Notifier control to publish the final error state of your device regardless of errors. If a Status Notifier control is present in the RT driver VI, VeriStand this as an indication that the device has shut down. Otherwise the VeriStand provides default status notification for the device.

Recently Viewed Topics