Controlling Signal Recovery Lock-ins over TCP/IP
Signal Recovery makes great lock-ins. For my first project as a graduate student I did a lot of shopping around, and eventually ended up purchasing three 7265’s. They have a GPIB interface (or RS232 for the desperate), and while it’s nearly 50 years old at this point it still works fine (and we have tons of GPIB cards around the lab).
Their newer lock-ins, like the 7270, have taken the understandable move of switching to Ethernet and USB control. They provide some software, good documentation for the commands, and an ActiveX control, but no easily-accessible sample code and relatively little information in the manual on how to actually talk to it. (Also they didn’t answer any of my support emails). Luckily, the Ethernet control is super-easy in Qt, as the following example shows.
A few notes to start: make sure to add QT += webkit
to your project file. You probably want to make sure the lock-in gets a static IP, and may need to set up port forwarding if you need to access it from outside of the subnet. The QHostAddress stuff might seem a bit redundant below, but it’s because of the way Qt handles multiple socket types transparently.
#ifndef LOCKIN7270_H #define LOCKIN7270_H #include <stdlib.h> #include <QtWidgets> #include <QtNetwork/QtNetwork> #include <QtCore> class Lockin7270 { public: QString ip_address_string; QHostAddress host_address; Lockin7270(); ~Lockin7270(); void start(QString ip_string, int this_port); double get_x1(); double get_x2(); QTcpSocket *socket; int port; private: QString read_response(); void send_command(QString command); void socketError(QAbstractSocket::SocketError); }; #endif // LOCKIN7270_H
#include "lockin7270.h" #include <QtDebug> #include <stdlib.h> #include <QtWidgets> #include <QtNetwork/QtNetwork> #include <QtCore> Lockin7270::Lockin7270(){} Lockin7270::~Lockin7270() { socket->close(); } void Lockin7270::start(QString ip_string, int this_port) { ip_address_string = ip_string; port = this_port; socket = new QTcpSocket(0); host_address.setAddress(ip_address_string); } void Lockin7270::send_command(QString command) { socket->connectToHost(host_address,port,QTcpSocket::ReadWrite); socket->waitForConnected(20); QByteArray buffer; buffer.append(command); socket->write(buffer); socket->flush(); } QString Lockin7270::read_response() { QString response = "Error: no lines"; socket->waitForReadyRead(20); while (socket->canReadLine()) { QByteArray ba = socket->readLine(); if(strcmp(ba.constData(), "\0")==0) { socket->disconnectFromHost(); break; } response.clear(); response.append(ba); } socket->disconnectFromHost(); return response; } double Lockin7270::get_x1(){ send_command("X1.\0"); QString response = read_response(); response.chop(1); //Remove termination double result = response.toDouble(); return result; } double Lockin7270::get_x2(){ send_command("X2.\0"); QString response = read_response(); response.chop(1); double result = response.toDouble(); return result; } void Lockin7270::socketError(QAbstractSocket::SocketError ) { qDebug()<<"error" ; }