Communicating with Thorlabs APT motor controllers

Communicating with Thorlabs APT motor controllers

We recently added a Thorlabs DC motor controller to our scanning MOKE setup to automate the rotation of a waveplate.  Our MOKE setup software is written in c++ using Qt, and we wanted to operate the motor from within the software.  Thorlabs provides ActiveX controllers and detailed information on the communications protocol for the controller, but their sample videos on using the ActiveX controllers involve embedding the controls which we would rather not do, and communicating directly with the controller appears rather painful.  Luckily, it turned out relatively easy to generate libraries and access individual methods from within Qt.

The first step is to generate a namespace from the appropriate ActiveX control with the dumpcpp tool.  For us this was

dumpcpp MG17Motor.ocx -n APT -o APT

this generates two very long files APT.h and APT.cpp.  In our project we add the ActiveX support with

Qt += axcontainer
CONFIG += axcontainer

and in a new wrapper library we include “APT.h”.  Now all we need to do is initialize an object of type MG17Motor in APT, shown here as a member of our class

class APTAngle
    void set(double angle);
    void init();
    APT::MG17Motor motor;

Then we can initialize our rotation stage with

void APTAngle::init()

and go to positions with

void APTAngle::set(double angle)
    angle += 61.0; // offset for the half wave plate
    if (angle<360) {
Comments are closed.