# NI digital read task

> Read the digital input lines of an NI device into channels.

An NI digital read task reads the digital input lines of one NI device into channels. Each line gives 0 or 1. For example, it can record limit switches on `port0/line0` and `port0/line1` of a USB-6343.

Before you start, you need a [configured device](https://docs.synnaxlabs.com/reference/hardware/ni/configure-device).

## Ports and lines

NI devices group digital lines into ports. Each channel reads one line, set by its port and line numbers. The device manual lists the ports and lines.

The Driver reads the lines on the computer clock, at the **Sample rate**. See [timing](https://docs.synnaxlabs.com/reference/hardware/tasks#timing).

The Console gives the digital read tasks of a device one index channel, and only one writer can hold an index channel. So only one of these tasks can run on a device at a time, even when the tasks use different lines. A second task stops right after it starts, with an error that names the running task. Tasks from a client library have this limit only when they share an index channel.

## Create an NI digital read task

**Console**

1. In the devices toolbar, right-click the device and select **Create digital read task**.
2. Set **Sample rate** and **Stream rate**.
3. The task starts with one channel. To add more, click **Add channel**, or click a free line in the map above the channel list. See [ports](https://docs.synnaxlabs.com/reference/hardware/tasks#ports).
4. In the channel list, enter the **Port** and the **Line** of each channel.
5. Click (**Start**).

The Console creates the channels. For a device with the identifier `dev1`, port 0, line 1 gives `dev1_di_0_1`, with the index channel `dev1_di_time`.

[](https://synnax.nyc3.cdn.digitaloceanspaces.com/docs/hardware/ni/digital-read-task/8f1d9adb49c8-dark.mp4#t=0.001)

**Python**

Python does not create channels. Create them first.

```python
import synnax as sy
from synnax import ni

dev = client.devices.retrieve(key="<device key>")
time = client.channels.create(
    name="dev1_di_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
limit = client.channels.create(
    name="limit_switch", index=time.key, data_type=sy.DataType.UINT8
)

task = ni.DigitalReadTask(
    name="Limit switches",
    device=dev.key,
    sample_rate=100,
    stream_rate=10,
    channels=[ni.DIChannel(port=0, line=1, channel=limit.key)],
)
client.tasks.configure(task)
task.start()
```

**TypeScript**

TypeScript does not create channels. Create them first.

```typescript
import { ni } from "@synnaxlabs/client";

const dev = await client.devices.retrieve({ key: "<device key>" });
const time = await client.channels.create({
  name: "dev1_di_time",
  isIndex: true,
  dataType: "timestamp",
});
const limit = await client.channels.create({
  name: "limit_switch",
  index: time.key,
  dataType: "uint8",
});

const task = await client.tasks.create({
  name: "Limit switches",
  rack: dev.rack,
  type: "ni_digital_read",
  config: ni.digitalReadConfigZ.parse({
    device: dev.key,
    sampleRate: 100,
    streamRate: 10,
    channels: [{ port: 0, line: 1, channel: limit.key }],
  }),
});
await task.start();
```

## Task options

| Console label | Python field           | Default | Notes                                                                                               |
| ------------- | ---------------------- | ------- | --------------------------------------------------------------------------------------------------- |
| Device        | `device`               |         | The key of the device.                                                                              |
| Sample rate   | `sample_rate`          | 10 Hz   | Up to 1,000,000 Hz in the Console.                                                                  |
| Stream rate   | `stream_rate`          | 5 Hz    | Up to 20,000 Hz. See [read tasks](https://docs.synnaxlabs.com/reference/hardware/tasks#read-tasks). |
| Data saving   | `data_saving_disabled` | On      | See [data saving](https://docs.synnaxlabs.com/reference/hardware/tasks#data-saving).                |
| Auto start    | `auto_start`           | Off     | Starts the task each time the Driver starts.                                                        |

## Channel reference

Each channel has a `channel`, the Synnax channel that records the value as `uint8`. The table shows the Console label of each setting, with its Python field under it.

| Setting     | Default | Notes                 |
| ----------- | ------- | --------------------- |
| Port `port` | `0`     | The port.             |
| Line `line` | `0`     | The line in the port. |

## Troubleshooting

* [Another channel uses port0/line0](https://docs.synnaxlabs.com/reference/hardware/ni/digital-read-task#another-channel-uses-port0-line0)

  * Cause

    Two enabled channels use the same line.

  * Fix

    Change the **Port** or the **Line** of one of the channels, or disable one of them.

* [The device has no digital input port0](https://docs.synnaxlabs.com/reference/hardware/ni/digital-read-task#the-device-has-no-digital-input-port0)

  * Cause

    The channel uses a port that the device does not have, or a port that cannot read input.

  * Fix

    Change the **Port** of the channel. The line map above the channel list shows the ports of the device.

* [port0 has 8 lines, numbered 0 to 7](https://docs.synnaxlabs.com/reference/hardware/ni/digital-read-task#port0-has-8-lines-numbered-0-to-7)

  * Cause

    The **Line** of the channel is past the last line of its port.

  * Fix

    Change the **Line** to a number in the range of the message.

* [... has no control authority - it is currently held by ...](https://docs.synnaxlabs.com/reference/hardware/ni/digital-read-task#has-no-control-authority-it-is-currently-held-by)

  * Cause

    Another running task writes to the same index channel. The error names that task.

  * Fix

    Stop the other task, or move its channels into this task.

For other problems, see [Configure an NI device](https://docs.synnaxlabs.com/reference/hardware/ni/configure-device#troubleshooting) and [Troubleshoot hardware](https://docs.synnaxlabs.com/reference/hardware/troubleshooting).
