qtspec
Qt client library for the SPEC instrument control protocol.
qtspec implements a TCP client for the SPEC server used at beamlines to control motors, scalers/counters and execute commands. The library provides a Qt based API with automatic connection management, reference counting and signal/slot notifications.
Overview
SPEC protocol uses a binary header format with magic number 0xfeedface and version 4. The client connects to ports
6510-6530 on a host, performs a hello exchange and then registers for events. Messages are built by the Message
class and sent over QTcpSocket.
The library is structured around a singleton Spec::Manager that maintains
Spec::Connection objects per host:spec_name address. Connections are kept alive by reference counting via
operator++/operator--. Public classes borrow a connection from the manager and unregister on destruction.
Components
Spec::Manager- singleton connection manager, reference counted connections, abort all connections.Spec::Connection- TCP socket handling, port scanning, hello handshake, message parsing, event dispatch.Spec::Message- builder for SPEC binary messages: register/unregister, read/send, motor and counter specific helpers.Spec::Motor- motor control with position, limits, offset, slew rate, step size, state machine Unusable/MoveStarted/Moving/Ready, signals for positionChanged, moveDone, hitLimit.Spec::Counter- scaler value monitoring and counting, countingStarted/ countingFinished signals.Spec::Command- execute arbitrary SPEC commands, asynchronous reply handling.
Build
Requires CMake 3.27+, Qt 5 or 6 Core and Network, and qtsingleton. The project uses cmake-tools for dependency resolution.
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
Install target provides headers in include/qtspec and static library
libqtspec.a.
Options:
-DSPEC_MOTOR_STANDARD_POSITION_ERROR=<value>overrides default motor position tolerance 1e-4.-DUSE_QT6=1selects Qt6 via cmake-tools.
Usage
Address format is host:spec_name. Examples:
Spec::Motor motor("192.168.1.10:spec", "m1");
connect(&motor, &Spec::Motor::positionChanged, [](auto name, double pos){
qDebug() << name << pos;
});
motor.move(10.0);
Spec::Counter counter("192.168.1.10:spec", "s1");
connect(&counter, &Spec::Counter::valueChanged, [](auto name, double v){
qDebug() << name << v;
});
counter.count(1.0);
Spec::Command cmd("192.168.1.10:spec");
connect(&cmd, &Spec::Command::finished, [](QByteArray out, Spec::Command*){
qDebug() << out;
});
cmd.run("show");
Protocol notes
Header fields are defined in qtspec/qtspec.h. Commands include Register, Unregister, ChannelRead, ChannelSend, Hello,
etc. Types are Double, String, Error, Assoc. Port scanning starts at 6510 and wraps to 6530.
License
GPL-3.0+