For the camera test bench of PLATO we developed the control of the Energetiq EQ-99 light source: switching it on and off as one more step of the test, reading its status and lamp hours, and doing it all over the network. These are the essentials.
The USB: an FTDI chip at 38400 baud
The EQ-99 controller has an FTDI chip. According to the manual, communication runs at 38400 baud, 8 data bits, no parity and 1 stop bit, with commands terminated by carriage return and line feed. With the pylibftdi library it is opened like this:
import time
import pylibftdi
source = pylibftdi.Device(mode="t", device_id="FTDI_SERIAL_NUMBER")
source.baudrate = 38400
source.ftdi_fn.ftdi_set_line_property(8, 1, 0) # 8N1
time.sleep(0.05)
source.flush(pylibftdi.FLUSH_BOTH) # empty the buffers
time.sleep(0.05)
source.ftdi_fn.ftdi_setflowctrl(0) # no flow control
def command(text):
source.write(text + "\r\n")
def query(text, wait=2.0):
command(text)
reply, deadline = "", time.monotonic() + wait
while time.monotonic() < deadline:
c = source.read(1)
if c == "\n":
return reply.strip()
reply += c
raise TimeoutError(text)
The line that matters most is the last one of the set-up: flow control must be disabled. Otherwise the source sends nothing back to the computer: queries get no reply and the instrument looks faulty, when that is all it is.
The commands used in a test
query("*IDN?") # identification
command("LDLS:OUTput 1") # switch on (0 to switch off)
query("LDLS:OUTput?") # "1" when on
query("LDLS:COND?") # condition register
query("ERRSTR?") # "0" when there are no errors
query("LDLS:LAMPTIME?") # lamp hours
After switching on, allow a stabilisation time before measuring: the test software should wait for it rather than trust the light as soon as the source reports it is on.
Bringing it onto the network
A USB cable does not reach from the source's room to the test computer, least of all with a vacuum chamber in between. The solution we built was a small computer next to the source (a Raspberry Pi) running a service that receives commands over TCP and passes them on over USB.
That way the test software talks to the source like any other network instrument, and the USB details are kept in one place. It is worth having the service greet each client with its name and version on connection: the client checks it is talking to what it expects, and a swapped device or IP is spotted straight away.
From script to test bench
Switching the source on from a script is easy. Having it switch on at the right moment of the test, coordinated with the shutter, the filter wheels and the power meter, raise an alert when it reports an error and keep track of the lamp hours is what we build, custom.