Skip to content

Device I/O

Some Zaber devices feature I/O capabilities, which are accessible through the library using the IO property of a device instance. I/O allows for a device to interact with external circuitry. This is useful for applications that require synchronization with other components.

Each individual I/O connection is referred to as a channel.

There are four types of channels: analog output, analog input, digital output, and digital input. A device may have none, some, or all of these channel types. There may also be multiple channels of a certain type. Information on the number and type of I/O channels on a particular device can be found using the @method GetChannelsInfo method of the @prop IO property.

In the example below, the device is queried for information on available channels, and the number of channels available for each type is printed.

const ioInfo = await device.io.getChannelsInfo();

console.log('Number of analog outputs:', ioInfo.numberAnalogOutputs);
console.log('Number of analog inputs:', ioInfo.numberAnalogInputs);
console.log('Number of digital outputs:', ioInfo.numberDigitalOutputs);
console.log('Number of digital inputs:', ioInfo.numberDigitalInputs);
io_info = device.io.get_channels_info()

print("Number of analog outputs:", io_info.number_analog_outputs)
print("Number of analog inputs:", io_info.number_analog_inputs)
print("Number of digital outputs:", io_info.number_digital_outputs)
print("Number of digital inputs:", io_info.number_digital_inputs)
var ioInfo = device.IO.GetChannelsInfo();

Console.WriteLine("Number of analog outputs: {0}", ioInfo.NumberAnalogOutputs);
Console.WriteLine("Number of analog inputs: {0}", ioInfo.NumberAnalogInputs);
Console.WriteLine("Number of digital outputs: {0}", ioInfo.NumberDigitalOutputs);
Console.WriteLine("Number of digital inputs: {0}", ioInfo.NumberDigitalInputs);
// import zaber.motion.ascii.Connection;
// import zaber.motion.ascii.Device;
// import zaber.motion.ascii.DeviceIOInfo;

DeviceIOInfo ioInfo = device.getIO().getChannelsInfo();

System.out.println("Number of analog outputs: " + ioInfo.getNumberAnalogOutputs());
System.out.println("Number of analog inputs: " + ioInfo.getNumberAnalogInputs());
System.out.println("Number of digital outputs: " + ioInfo.getNumberDigitalOutputs());
System.out.println("Number of digital inputs: " + ioInfo.getNumberDigitalInputs());
ioInfo = device.getIO().getChannelsInfo();

fprintf('Number of analog outputs: %d.\n', ioInfo.getNumberAnalogOutputs());
fprintf('Number of analog inputs: %d.\n', ioInfo.getNumberAnalogInputs());
fprintf('Number of digital outputs: %d.\n', ioInfo.getNumberDigitalOutputs());
fprintf('Number of digital inputs: %d.\n', ioInfo.getNumberDigitalInputs());
DeviceIOInfo ioInfo = device.getIO().getChannelsInfo();

std::cout << "Number of analog outputs: " << ioInfo.getNumberAnalogOutputs() << std::endl;
std::cout << "Number of analog inputs: " << ioInfo.getNumberAnalogInputs() << std::endl;
std::cout << "Number of digital outputs: " << ioInfo.getNumberDigitalOutputs() << std::endl;
std::cout << "Number of digital inputs: " << ioInfo.getNumberDigitalInputs() << std::endl;

The library allows you to read any of the channels available on a device. You may either read all channels of a particular type at once, or read only one channel of a particular type at once. You can also write to any of the output channels. Similar to reading, you may either write to all channels of a particular type at once, or write to only one channel of a particular type at once.

For digital channel types, a value of false indicates the channel is open or low (depending on the type of digital connection), while a value of true indicates that the channel is closed or high. For analog channel types, the value is the voltage present on the channel.

The next example demonstrates reading the value of digital input channel 1.

const digitalInput1 = await device.io.getDigitalInput(1);
console.log(`Value of digital input channel 1: ${digitalInput1}`);
digital_input_1 = device.io.get_digital_input(1)
print("Value of digital input channel 1:", digital_input_1)
var digitalInput1 = device.IO.GetDigitalInput(1);
Console.WriteLine("Value of digital input channel 1: {0}", digitalInput1);
boolean digitalInput1 = device.getIO().getDigitalInput(1);
System.out.println("Value of digital input channel 1: " + digitalInput1);
digitalInput1 = device.getIO().getDigitalInput(1);
fprintf('Value of digital input channel 1: %d.\n', digitalInput1);
bool digitalInput1 = device.getIO().getDigitalInput(1);
std::cout << "Value of digital input channel 1: " << digitalInput1 << std::endl;

The following example demonstrates reading and printing the values of all analog input channels.

const analogInputs = await device.io.getAllAnalogInputs();
console.log('Values of analog input channels in order:', analogInputs);
analog_inputs = device.io.get_all_analog_inputs()
print("Values of analog input channels in order:", str(analog_inputs))
var analogInputs = device.IO.GetAllAnalogInputs();
Console.WriteLine("Values of analog input channels in order: {0}", string.Join(",", analogInputs));
// import java.util.Arrays;

// add the following to the main() function:
double[] analogInputs = device.getIO().getAllAnalogInputs();
System.out.println("Values of analog input channels in order: " + Arrays.toString(analogInputs));
analogInputs = device.getIO().getAllAnalogInputs();
fprintf('Values of analog input channels in order: ');
fprintf('%d ', analogInputs);
fprintf('\n');
std::vector<double> analogInputs = device.getIO().getAllAnalogInputs();
std::cout << "Values of analog input channels in order: ";
for (const auto ai: analogInputs) {
    std::cout << ai << " ";
}
std::cout << std::endl;

This example shows how to set analog output channel 1 to 1.5 V.

await device.io.setAnalogOutput(1, 1.5);
device.io.set_analog_output(1, 1.5)
device.IO.SetAnalogOutput(1, 1.5);
device.getIO().setAnalogOutput(1, 1.5);
device.getIO().setAnalogOutput(1, 1.5);
device.getIO().setAnalogOutput(1, 1.5);

The last example shows how to set the values of all four digital output channels such that only the first two channels are closed/high.

await device.io.setAllDigitalOutputs([true, true, false, false]);
device.io.set_all_digital_outputs([True, True, False, False])
device.IO.SetAllDigitalOutputs(new bool[] { true, true, false, false });
device.getIO().setAllDigitalOutputs(new boolean[] { true, true, false, false });
device.getIO().setAllDigitalOutputs([1, 1, 0, 0]);
device.getIO().setAllDigitalOutputs({ true, true, false, false });

Reference

For full device I/O reference, please visit: