ReferenceDriverNIDigital Write Task

NI Digital Write Task

Learn how to create a digital write task for NI hardware.

The NI Digital Write Task is used for sending commands to the digital outputs of your NI cards. In this guide, we’ll walk you through the steps to create a Digital Write Task in Synnax.

Prerequisites

Before configuring the task, you’ll need to have connected and configured an NI device.

A Short Primer on Tasks

Tasks are the primary method for communicating with hardware devices in Synnax. Tasks can be used for both control and data acquisition purposes. In the context of the NI Driver, a digital write task defines a background process that writes to the digital outputs of your device based on values written to Synnax command channels.

A digital write task can be started, stopped, and re-configured at any time. We permanently store the configuration of the task in Synnax, so it’s easy to set up multiple tasks for different purposes.

How Commands Work in Synnax

Commands in Synnax require two types of channels: a command channel and state channel. Command channels signal a task to set the value of a digital output. To set a digital output to high, you would write a 1 to the command channel. To set it to low, you would write a 0.

A command channel for a digital output might be my_temp_card_do_0_1_cmd, where my_temp_card is the device identifier, do_0_1 is the port and line of the digital output, and _cmd indicates that it’s a command channel.

Command channels also have an associated index channel that stores the timestamps at which commands were sent. This channel is suffixed with _cmd_time. For the command channel my_temp_card_do_0_1_cmd, the index channel would be my_temp_card_do_0_1_cmd_time.

State channels represent the current state of the digital output. When you send a command, the corresponding digital write task will process the command and update the value in the state channel.

State channels are typically suffixed with _state. A state channel maintains the same format as its corresponding command channel, but suffixed with _state instead of _cmd.

As an example, to configure a valve in the schematic to write to a digital output, you would set the command field to the command channel of the digital output and the state field to the state channel of the digital output. Clicking the valve would send a command to the digital output, and the valve would turn solid or transparent based on the state channel.

Using two channels provides a guarantee that a particular command was acknowledged by a running task.

Open the Task Configuration Dialog

From the Devices Toolbar

To create a digital write task from the Devices Toolbar, open the Console and click on the device icon () on the left-hand side of the screen. Find the device you’d like to create the task for, right-click on it, and select “Create digital write task”.

From the Command Palette

To create a digital write task from the command palette, open the Console and click on the Search and Command Palette at the top. You can also open this palette with Ctrl+Shift+P on Windows and Cmd+Shift+P on macOS.

In command mode (enabled when the first character in the input is ”>”), type “NI”. You’ll see an option called “Create an NI Digital Write Task”. Select this option to open the digital write task configuration dialog.

From The Layout Selector

To create a digital write task from the layout selector, click on the add icon () in the top-right corner and select “NI Digital Write Task”.

Configure the Task

The first step is to select the NI device you’d like to write to the outputs of. Use the dropdown menu in the top-left corner to do so.

Next, you’ll need to add the channels you’d like to write to. Click the add icon () in the channels section. Then, click on the new channel in the list to configure it.

You’ll need to select both a digital output port and line to write to.

The state update rate determines how often the state channels in the task are updated. Set the rate higher in scenarios that require quick response times.

Start the Task

Once you’ve added all of the channels you need and have configured sampling rates, hit the “Configure” button. If there are no errors, Synnax will acknowledge the configured task and enable the Play () button in the dialog. Click this button to start the task.

Starting and stopping a task does not re-apply the task configuration. If you’ve made changes to the configuration, you’ll need to re-configure the task by hitting the “Configure” button.