Some Zaber devices feature I/O capabilities that are represented in the library by
DeviceIO
class.
You can find an instance of
DeviceIO
under 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
get_channels_info
method.
In the example below, the device is queried for information on available channels, and the number of channels available for each type is printed.
Python
C#
C++
JavaScript
MATLAB
Java
MATLAB (legacy)
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;DeviceIOInfoioInfo= 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());
ioInfo = device.IO.getChannelsInfo();
fprintf('Number of analog outputs: %d.\n', ioInfo.NumberAnalogOutputs);
fprintf('Number of analog inputs: %d.\n', ioInfo.NumberAnalogInputs);
fprintf('Number of digital outputs: %d.\n', ioInfo.NumberDigitalOutputs);
fprintf('Number of digital inputs: %d.\n', ioInfo.NumberDigitalInputs);
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.
When reading 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. When writing digital channel types, a value of OFF sets the channel open or low, a value of ON sets the channel closed or high, a value of TOGGLE switches the state of the channel, and a value of KEEP does not modify the state of the channel.
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.
Python
C#
C++
JavaScript
MATLAB
Java
MATLAB (legacy)
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);
booleandigitalInput1= 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);
digitalInput1 = device.IO.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.
Python
C#
C++
JavaScript
MATLAB
Java
MATLAB (legacy)
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');
analogInputs = device.IO.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 (constauto ai: analogInputs) {
std::cout << ai << " ";
}
std::cout << std::endl;
This example shows how to set analog output channel 1 to 1.5 V.
Python
C#
C++
JavaScript
MATLAB
Java
MATLAB (legacy)
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.IO.setAnalogOutput(1, 1.5);
device.getIO().setAnalogOutput(1, 1.5);
This example shows how to set digital output channel 2 to ON. Digital output actions can be ON, OFF, TOGGLE, or KEEP. Note that some languages will require a specific import for the DigitalOutputAction enum.
This example shows how to set the values of all four digital output channels such that only the first two channels are turned ON and the other channels are unchanged with KEEP. Note that some languages will require a specific import for the DigitalOutputAction enum.
As of firmware 7.37, Zaber devices support scheduling a digital output action for a set time in the future. For example, here's how to set digital output channel 1 to ON immediately, and schedule it to set to OFF in 1 second, creating a 1s pulse. Note that some languages will require a specific import for the DigitalOutputAction enum.