LabJack write task
Write command channel values to the analog and digital outputs of a LabJack.
A LabJack write task writes the values of command channels to the outputs of one LabJack
device. For example, a valve on a schematic can switch DIO4, and a setpoint can drive
DAC0.
Each output has a command channel and a state channel. When you deploy the task, every output starts at 0. When you stop and start the task from the tasks toolbar or from code, the outputs go back to the last commanded values.
Before you start, you need a configured device.
Create a LabJack write task
When you create command channels with a client library, give each one its own index channel. A writer that holds several commands on one index must write all of them in every frame.
Console
Python
TypeScript
- In the devices toolbar, right-click the device and select Create write task.
- Set State update rate.
- Click Add channel. In the port list of the channel, select Analog or Digital, then select the port.
- Click (Start).
The Console creates the channels. For a device with the identifier lj1, the output
DIO4 gives the command channel lj1_DIO4_cmd with the index lj1_DIO4_cmd_time, and
the state channel lj1_DIO4_state with the index lj1_write_state_time.
Python does not create channels. Create them first.
import synnax as sy
from synnax import labjack
dev = client.devices.retrieve(key="<serial number>")
state_time = client.channels.create(
name="lj1_write_state_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
state = client.channels.create(
name="lj1_DIO4_state", index=state_time.key, data_type=sy.DataType.UINT8
)
cmd_time = client.channels.create(
name="lj1_DIO4_cmd_time", is_index=True, data_type=sy.DataType.TIMESTAMP
)
cmd = client.channels.create(
name="lj1_DIO4_cmd", index=cmd_time.key, data_type=sy.DataType.UINT8
)
task = labjack.WriteTask(
name="Valves",
device=dev.key,
channels=[
labjack.DigitalWriteChannel(
port="DIO4", cmd_channel=cmd.key, state_channel=state.key
)
],
)
client.tasks.configure(task)
task.start()Python creates the task on the embedded Driver of the Core. For a device on another Driver, use the Console or TypeScript.
TypeScript does not create channels. Create them first, as in the Python example.
import { labjack } from "@synnaxlabs/client";
const dev = await client.devices.retrieve({ key: "<serial number>" });
const task = await client.tasks.create({
name: "Valves",
rack: dev.rack,
type: "labjack_write",
config: labjack.writeConfigZ.parse({
device: dev.key,
channels: [
{
type: "digital",
port: "DIO4",
cmdChannel: cmd.key,
stateChannel: state.key,
},
],
}),
});
await task.start();Task options
Channel reference
Each channel has a cmd_channel and a state_channel. Both are required.
Troubleshooting
- Cause
A channel in code has no command channel or no state channel.
- Fix
Create both and set them on the channel.
For other problems, see Configure a LabJack device and Troubleshoot hardware.