Search code examples
c++zaber

How do I open the serial port to a Zaber device?


I have a Zaber linear stage for which I'm developing a C++ backend, to integrate it in my framework.

I have installed the Zaber API by following the instructions from the Zaber webpage. The installer actually generates the dll, lib, and headers necessary for my backend, and I'm confident that my CMake configuration is correct, because I can instantiate objects from the Zaber API.

So now, I am trying in my framework to go through their first code example:

// I commented out the following block:
//     - enableDeviceDbStore() is supposed to allow the library to cache
//       information from the online database
//     - I don't need the online db
//     - when I call it, it throws a "string too long" exception.
// try
// {
//     zaber::motion::Library::enableDeviceDbStore(".");
// }
// catch (std::exception& e)
// {
//     LogError << e.what();
// }

try
{
    _connection = zaber::motion::ascii::Connection::openSerialPort("COM6");
    // this also throws a "string too long" exception
}
catch (std::exception& e)
{
    std::cout << e.what() << std::endl;
}

std::vector<zaber::motion::ascii::Device> deviceList;
try
{
    deviceList = _connection.detectDevices(false);
    // this throws a "Connection has been closed" exception
}
catch (std::exception& e)
{
    std::count << e.what() << std::endl;
}
std::count << "Found " << deviceList.size() << " devices." << std::endl;

The problem is, when I use the Zaber Launcher (their UI that allows to control a connected stage), the port is "COM6", and I have made sure to close the connection on the Zaber Launcher before trying to connect with my framework.

I have also tried to launch their pre-configured C++ code example (VS17 solution), with the same problems arising (except their example doesn't catch exceptions, so it just crashes).

None of my exception matches their troubleshooting section.

I don't know how to proceed from here, or how to interpret the "string too long" error message, considering that I'm sure of my connection port.


Solution

  • Zaber provides the dll files for both debug and release target types, and I initially ignored it, using the release dll files for my debug configuration.

    Correcting my CMakeLists and using the correct dll for the correct target types solved my problem (I can control my stage).