Triggerscope

Triggerscope4 drives an Advanced Research Consulting Triggerscope 4 over a serial port: analog DAC outputs, each with a selectable voltage range, and TTL outputs (16 of each by default), set directly (setdac, setttl) or programmed as a triggered sequence (the prog* functions, then arm). [limitation] Parts of sequence programming do not work today: progttl throws after sending its command and progarray cannot complete; their docstrings say why. Its abstract type, TRIG, describes channel groups for the shared control panel and is not an AbstractInstrument. An LCC1620 attenuator takes its drive voltage from one of its DAC channels.

Trigger controller interface

MicroscopeControl.HardwareInterfaces.TrigInterface.Output — Type
Output(label, datatype, numchannels, ranges, values, israngevariable)

One group of output channels on a TRIG device, as the control panel shows it: label (for example "DAC" or "TTL"), the channel value type datatype (Float64 volts, Bool), numchannels, the per-channel ranges, the last-commanded values, and whether the range can be changed (israngevariable).

source
MicroscopeControl.HardwareInterfaces.TrigInterface.TRIG — Type
TRIG

Abstract type for a trigger and output controller: a box with groups of output channels (analog DAC, digital TTL) and input channels, each group described by an Output or Input for the shared control panel (gui). Unlike the other device classes it is not a subtype of AbstractInstrument, though its driver, Triggerscope4, defines initialize and shutdown. A driver implements setoutputvalue, setoutputrange, getoutputvalue, getinputvalue and Base.reset. The first four are not exported (call them as TrigInterface.setoutputvalue and so on); reset extends Base.reset and is callable unqualified.

source
MicroscopeControl.gui — Method

This function builds a GUI for any implemented DAQ device based on the prior existing GUI for the NIDAQ device. GLMakie is used

There will be an equal number of dropdown menus to the number of datatypes that the DAQ device can read and write. ex: If the DAQ device has DAC and TTL outputs, there will be two dropdown menus for output and two for input.

The dropdown menus will have a number of fields equal to the number of channels that the DAQ device has for each datatype. ex: If the DAQ device has 4 DAC outputs, there will be 4 fields for the DAC output dropdown menu.

For each selected output channel, there will be a field to input the value to be written to the channel. There will be a textbox to display the value outputted to the selected channel, this will update when the value is updated.

For each selected input channel, there will be a textbox to display the value read from the channel. There will be a button to update this reading.

The GUI will have a button to start the DAQ device and a button to stop the DAQ device. ex: For the Triggerscope this will initiate serial communication and close serial communication.

source

Triggerscope 4

MicroscopeControl.HardwareImplementations.Triggerscope.Range — Type
Range

Output voltage range of one Triggerscope4 DAC channel, for setrange and the dacranges field of Triggerscope4. The integer value is the range code sent to the device, and the range decides how a voltage becomes a 16-bit DAC code (0 to 65535 spans the whole range): ZEROTOFIVE = 1 (0 to 5 V), ZEROTOTEN = 2 (0 to 10 V), PLUSMINUS5 = 3 (-5 to 5 V), PLUSMINUS10 = 4 (-10 to 10 V), PLUSMINUS2_5 = 5 (-2.5 to 2.5 V).

source
MicroscopeControl.HardwareImplementations.Triggerscope.SignalArray — Type
SignalArray(trigMode::TriggerMode, commands::Vector{CommandSignal})

A list of DAC and TTL commands plus a trigger mode, the input of progarray. Each element of commands is a CommandSignal(commandType::CommandType, channel::Int, value::Union{Float64,Bool}) (not exported). [limitation] progarray as written does not complete, so a SignalArray cannot presently be programmed onto the device through it. progdac and the other program functions can be called directly, except progttl, which throws after sending its command (see its docstring).

source
MicroscopeControl.HardwareImplementations.Triggerscope.TriggerMode — Type
TriggerMode

Trigger mode for Triggerscope sequences (the type of the trigmode field), set with trigmode. The integer value is what trigmode sends to the device: RISING = 2, FALLING = 3, CHANGE = 4. A comment in the source says trigger modes 1 and 2 are supported only by the Triggerscope 3B; that would include RISING (2), the constructor's default. This has not been checked against the device.

source
MicroscopeControl.HardwareImplementations.Triggerscope.Triggerscope4 — Type
Triggerscope4(; devicename, portname, baudrate, rwtimeout, compause, ...) -> Triggerscope4

Advanced Research Consulting Triggerscope 4: a USB serial DAC (16-bit analog outputs) and TTL controller. The keyword constructor builds the object and an unopened LibSerialPort.SerialPort for portname; it does not talk to the device. [limitation] Creating that SerialPort needs portname to be a port the operating system lists: on a machine without the default "COM3", Triggerscope4() throws a LibSerialPort error (SP_ERR_ARG), so pass a real portname. initialize opens the port (see openport) and sends the acknowledgement test, shutdown closes it.

Every command function (setdac, setttl, arm, ...) writes one ASCII command line to the port, sleeps compause, reads one response line, and returns that line as a String, except where its docstring gives a [limitation] (progttl throws after sending its command). If the write or the read throws, the port is closed and reopened and an error is raised. The response text is never parsed or checked.

Fields a caller reads or sets: portname, baudrate, rwtimeout (s, read and write timeout), compause (s, pause after each write and each read), dacranges (the range assumed per DAC channel when converting volts), dacvalues and ttlvalues, trigmode. dacvalues and ttlvalues are a cache, not a readback: the panel's setoutputvalue updates them before it writes, progdac updates dacvalues, and setdac and setttl do not touch them; a DAC code computed from an out-of-range voltage can fall outside 0 to 65535. The outputs and inputs fields feed the generic DAQ GUI.

source
MicroscopeControl.HardwareImplementations.Triggerscope.Triggerscope4 — Method
Triggerscope4(; devicename="Triggerscope4", portname="COM3", baudrate=115200, rwtimeout=10.0,
              compause=0.1, dacoutputs=16, ttloutputs=16, ttlinputs=4, dacranges=fill(PLUSMINUS10, 16),
              trigmode=RISING, ...) -> Triggerscope4

Keyword constructor of Triggerscope4; every argument has a default, so Triggerscope4(portname="COM5") is a complete call. The remaining keywords (dacresolution=16, dacvalues, ttlvalues, ttloutputranges, ttlreadings, ttlinputranges) set the matching fields; vector keywords must be vectors of the declared element type (Vector{Int}, Vector{Range}, Vector{Bool}, Vector{Tuple{Bool,Bool}}). portname is a serial port name ("COM3" is a Windows name) and must exist on the machine, or the call throws (see Triggerscope4). The constructor does not open the port and does not send dacranges to the device: the device keeps whatever ranges it has until setrange is called, so set the ranges to match dacranges before relying on voltage conversion.

source
MicroscopeControl.HardwareImplementations.Triggerscope.openport — Method
openport(scope::Triggerscope4) -> nothing

Open the serial port scope.portname at scope.baudrate, store it in scope.sp, assert DTR, set the read and write timeouts to scope.rwtimeout seconds, flush both buffers and sleep scope.compause seconds. Called by initialize; it does not check that a Triggerscope answers. A port that cannot be opened throws the LibSerialPort error.

source
MicroscopeControl.HardwareImplementations.Triggerscope.progarray — Method
progarray(scope::Triggerscope4, signalArr::SignalArray, NLoops::Int, arm::Bool)

Intended to program a SignalArray onto the device and optionally arm it: clear the device, set the trigger mode, save settings, reset, set the cycle count to NLoops, set DAC ranges from the voltages used, then send each command with progdac or progttl. [limitation] As written the function cannot complete. It first calls trigmode with an Int, which has no method (a MethodError), after clearall has already been sent; the later range-selection and programming loops also reference variables and fields that do not exist (dacChannelVals outside its loop, command.progLine).

source
MicroscopeControl.HardwareImplementations.Triggerscope.progdac — Method
progdac(scope::Triggerscope4, programline::Int, dacnum::Int, voltage::Float64) -> String

Program DAC channel dacnum to voltage volts at program line programline by sending PROG_DAC,<line>,<dac>,<code>, and return the response line. The 16-bit code comes from the range in scope.dacranges[dacnum] (see setdac); scope.dacvalues[dacnum] is set to that code. The voltage is not range-checked.

source
MicroscopeControl.HardwareImplementations.Triggerscope.progdelay — Method
progdelay(scope::Triggerscope4, programline::Int, delayms::Int) -> String

Add a delay of delayms milliseconds to program line programline by sending PROG_DEL,<line>,<ms>, and return the response line. [limitation] A source comment notes problems with this command on both the Triggerscope 4 and 3B, in both the Julia and the MATLAB implementations.

source
MicroscopeControl.HardwareImplementations.Triggerscope.progfocus — Method
progfocus(scope::Triggerscope4, startpos::Int, stepsize::Int, numsteps::Int, direction::Bool,
          priority::Bool) -> String

Send PROG_FOCUS,<startpos>,<stepsize>,<numsteps>,<direction>,<priority> (the two Bools as 0 or 1) and return the response line. All values are passed to the device unchanged; the code gives no units. The source comment refers to the vendor manual for their meaning.

source
MicroscopeControl.HardwareImplementations.Triggerscope.progttl — Method
progttl(scope::Triggerscope4, programline::Int, ttlnum::Int, ttlval::Bool)

Program TTL output ttlnum to go high or low at program line programline by sending PROG_TTL,<line>,<ttl>,<0 or 1>. [limitation] After the command is written the function assigns into scope.ttloutputs, which is an Int (the output count) rather than a vector, so the call throws a MethodError and never returns the response line; the command itself has already been sent.

source
MicroscopeControl.HardwareImplementations.Triggerscope.progwave — Method
progwave(scope::Triggerscope4, arrayindex::Bool, dacnum::Int, waveform::Int, centervolt::Float64,
         dutycycle::Int, phase::Int, trigtype::Int; programstep::Int=0) -> String

Program a waveform on DAC channel dacnum by sending PROG_WAVE,... and return the response line. A program line holds two waveforms; arrayindex (sent as 0 or 1) selects which. waveform is 1 sine, 2 sawtooth, 3 triangle, 4 square; centervolt (V) is converted to a DAC code with the channel's stored range; dutycycle is in percent and phase in degrees. trigtype and programstep are passed to the device unchanged. [limitation] A source comment says the command does not appear to function and is not in the official documentation.

source
MicroscopeControl.HardwareImplementations.Triggerscope.setdac — Method
setdac(scope::Triggerscope4, dacnum::Int, voltvalue::Float64) -> String

Set DAC channel dacnum to voltvalue volts and return the response line. The voltage is converted to a 16-bit code (0 to 65535) with the range held in scope.dacranges[dacnum] and sent as DAC<n>,<code>. [limitation] The conversion uses the range stored in the object, not one read from the device, and a voltage outside that range is not clamped or checked: the code is sent as computed.

source
MicroscopeControl.HardwareImplementations.Triggerscope.setrange — Method
setrange(scope::Triggerscope4, dacchannel::Int, range::Range) -> String

Set the output range of DAC channel dacchannel by sending RANGE<channel>,<code> (the integer value of range) and return the response line. scope.dacranges[dacchannel] is updated before the command is sent, so it changes even if the write then fails. Later voltage conversions use the new range.

source

Triggerscope internals

The channel functions the control panel calls, the serial helpers of the driver, and reset, a user command that lands here because it extends Base.reset rather than a MicroscopeControl name.

Base.reset — Method
Base.reset(trig::TRIG)

Reset the trigger/DAQ device to its default state.

Extends Base.reset (rather than a locally-exported generic) because reset is already an exported Base binding; a same-named export here would just recreate the top-level ambiguity this generic is meant to resolve.

Arguments

  • trig::TRIG: A TRIG type.
source
Base.reset — Method
reset(scope::Triggerscope4) -> String

Send RESET and return the response line. Extends Base.reset; it is not exported from the Triggerscope module for that reason.

source