Open a serial port

In order to send commands to the device, you first need to open a serial port.

Which port to open depends on the computer, operating system, and how the device is connected.

In the following examples, replace the placeholder port name, COM3, with name of your connection. If you are uncertain about the name of your connection, see our guide to finding the right port.

Python
C#
C++
JavaScript
MATLAB
Java
Octave
MATLAB (legacy)
with Connection.open_serial_port("COM3") as connection:
    device_list = connection.detect_devices()
    print("Found {} devices".format(len(device_list)))

    # The rest of your program goes here (indented)
using (var connection = Connection.OpenSerialPort("COM3")) {
    var deviceList = connection.DetectDevices();
    Console.WriteLine($"Found {deviceList.Length} devices.");

    // The rest of your program goes here
}
const connection = await Connection.openSerialPort('COM3');
try {
    const deviceList = await connection.detectDevices();
    console.log(`Found ${deviceList.length} devices.`);

    // The rest of your program goes here
} finally {
    // Close the port to allow Node.js to exit
    await connection.close();
}
try (Connection connection = Connection.openSerialPort("COM3")) {
    Device[] deviceList = connection.detectDevices();
    System.out.println(String.format("Found %d devices.", deviceList.length));

    // The rest of your program goes here
}
connection = Connection.openSerialPort('COM3');
try
    deviceList = connection.detectDevices();
    fprintf('Found %d devices.\n', deviceList.length);

    % The rest of your program goes here

    connection.close();
catch exception
    connection.close();
    rethrow(exception);
end
connection = Connection.openSerialPort('COM3');
try
    deviceList = connection.detectDevices();
    fprintf('Found %d devices.\n', length(deviceList));

    % The rest of your program goes here

    connection.close();
catch exception
    connection.close();
    rethrow(exception);
end
connection = javaMethod("openSerialPort", CONNECTION_CLASS, "COM3");
try
    deviceList = connection.detectDevices();
    fprintf("Found %d devices.\n", length(deviceList));

    % The rest of your program goes here

    connection.close();
catch exception
    connection.close();
    rethrow(exception);
end
Connection connection = Connection::openSerialPort("COM3");

std::vector<Device> deviceList = connection.detectDevices();
std::cout << "Found " << deviceList.size() << " devices." << std::endl;

// The rest of your program goes here

Run the code and you should see the number of detected devices in the output of the application.

If you encounter a problem during this step, check that the device is connected correctly and powered on. Also ensure that other applications, such as Zaber Console, do not have the port open by either selecting Close or exiting the application. If you encounter DeviceAddressConflictException , use the Zaber Launcher application to assign distinct addresses to your devices.

During the device identification, the library connects to the internet to retrieve information about Zaber devices. No personal or identifying information is exchanged with Zaber servers. The library stores all the information in the operating system cache folder to later allow for offline use. For more information about the behaviour see Device Database.

The example code demonstrates use of a with statement to ensure that the serial port closes after the program runs.

Continue the Getting Started guide by homing your device.

API Reference