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 — Module
This builds a generic interface for Data Aquistion Devices (DAQs)
For now this will be implemented for the
MicroscopeControl.HardwareInterfaces.TrigInterface.Input — Type
Input(label, datatype, numchannels, ranges, values, israngevariable)One group of input channels on a TRIG device, with the same fields as Output; values holds the last readings.
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).
MicroscopeControl.HardwareInterfaces.TrigInterface.TRIG — Type
TRIGAbstract 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.
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.
Triggerscope 4
MicroscopeControl.HardwareImplementations.Triggerscope — Module
The driver for the Advanced Research Consulting Triggerscope 4: Triggerscope4, its direct-control and sequence commands, and the serial helpers.
MicroscopeControl.HardwareImplementations.Triggerscope.CommandType — Type
CommandTypeKind of one entry in a SignalArray: DAC (value is a voltage, Float64) or TTL (value is Bool). DAC and TTL are not exported.
MicroscopeControl.HardwareImplementations.Triggerscope.Range — Type
RangeOutput 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).
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).
MicroscopeControl.HardwareImplementations.Triggerscope.TriggerMode — Type
TriggerModeTrigger 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.
MicroscopeControl.HardwareImplementations.Triggerscope.Triggerscope4 — Type
Triggerscope4(; devicename, portname, baudrate, rwtimeout, compause, ...) -> Triggerscope4Advanced 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.
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, ...) -> Triggerscope4Keyword 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.
MicroscopeControl.HardwareImplementations.Triggerscope.acknowledgetest — Method
acknowledgetest(scope::Triggerscope4) -> StringSend the acknowledgement command * and return the device's response line, which initialize logs as the Triggerscope version. Needs an open port.
MicroscopeControl.HardwareImplementations.Triggerscope.arm — Method
arm(scope::Triggerscope4) -> StringSend ARM to arm the program written to the device (see progdac, progttl, trigmode) and return the response line.
MicroscopeControl.HardwareImplementations.Triggerscope.clearall — Method
clearall(scope::Triggerscope4) -> StringSend CLEAR_ALL, which clears the program held on the device, and return the response line.
MicroscopeControl.HardwareImplementations.Triggerscope.cleartable — Method
cleartable(scope::Triggerscope4) -> StringSend CLEARTABLE, which clears the active program table, and return the response line.
MicroscopeControl.HardwareImplementations.Triggerscope.closeport — Method
closeport(scope::Triggerscope4) -> nothingClose the serial port scope.sp. Called by shutdown.
MicroscopeControl.HardwareImplementations.Triggerscope.focus — Method
focus(scope::Triggerscope4, focusval::Int) -> StringSend FOCUS,<focusval> and return the response line. The value is passed to the device unchanged; the code gives no unit or range (the source comment says it sets the DAC assigned to focus).
MicroscopeControl.HardwareImplementations.Triggerscope.getstatus — Method
getstatus(scope::Triggerscope4) -> StringSend STAT? and return the response line, unparsed.
MicroscopeControl.HardwareImplementations.Triggerscope.openport — Method
openport(scope::Triggerscope4) -> nothingOpen 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.
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).
MicroscopeControl.HardwareImplementations.Triggerscope.progdac — Method
progdac(scope::Triggerscope4, programline::Int, dacnum::Int, voltage::Float64) -> StringProgram 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.
MicroscopeControl.HardwareImplementations.Triggerscope.progdelay — Method
progdelay(scope::Triggerscope4, programline::Int, delayms::Int) -> StringAdd 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.
MicroscopeControl.HardwareImplementations.Triggerscope.progfocus — Method
progfocus(scope::Triggerscope4, startpos::Int, stepsize::Int, numsteps::Int, direction::Bool,
priority::Bool) -> StringSend 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.
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.
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) -> StringProgram 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.
MicroscopeControl.HardwareImplementations.Triggerscope.runtest — Method
runtest(scope::Triggerscope4) -> StringSend TEST? and return the response line, unparsed. What the device does during the test is defined by the vendor, not by this code.
MicroscopeControl.HardwareImplementations.Triggerscope.savesettings — Method
savesettings(scope::Triggerscope4) -> StringSend SAVESETTINGS and return the response line. What the device stores is defined by the vendor, not by this code.
MicroscopeControl.HardwareImplementations.Triggerscope.setdac — Method
setdac(scope::Triggerscope4, dacnum::Int, voltvalue::Float64) -> StringSet 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.
MicroscopeControl.HardwareImplementations.Triggerscope.setrange — Method
setrange(scope::Triggerscope4, dacchannel::Int, range::Range) -> StringSet 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.
MicroscopeControl.HardwareImplementations.Triggerscope.setttl — Method
setttl(scope::Triggerscope4, channel::Int, ttlval::Bool) -> StringSet TTL output channel high (true) or low (false) by sending TTL<channel>,<0 or 1>, and return the response line. scope.ttlvalues is not updated.
MicroscopeControl.HardwareImplementations.Triggerscope.timecycles — Method
timecycles(scope::Triggerscope4, cycles::Int) -> StringSend TIMECYCLES,<cycles> and return the response line. The value is passed to the device unchanged; progarray passes its loop count here.
MicroscopeControl.HardwareImplementations.Triggerscope.trigmode — Method
trigmode(scope::Triggerscope4, mode::TriggerMode) -> StringSend TRIGMODE,<code> with the integer value of mode and return the response line. scope.trigmode is set to mode after the write and before the response is read.
MicroscopeControl.HardwareImplementations.Triggerscope.CHANGE — Constant
Trigger mode "change"; trigmode sends code 4. See TriggerMode.
MicroscopeControl.HardwareImplementations.Triggerscope.FALLING — Constant
Trigger mode "falling"; trigmode sends code 3. See TriggerMode.
MicroscopeControl.HardwareImplementations.Triggerscope.PLUSMINUS10 — Constant
DAC range -10 to 10 V, range code 4. See Range.
MicroscopeControl.HardwareImplementations.Triggerscope.PLUSMINUS2_5 — Constant
DAC range -2.5 to 2.5 V, range code 5. See Range.
MicroscopeControl.HardwareImplementations.Triggerscope.PLUSMINUS5 — Constant
DAC range -5 to 5 V, range code 3. See Range.
MicroscopeControl.HardwareImplementations.Triggerscope.RISING — Constant
Trigger mode "rising"; trigmode sends code 2. See TriggerMode.
MicroscopeControl.HardwareImplementations.Triggerscope.ZEROTOFIVE — Constant
DAC range 0 to 5 V, range code 1. See Range.
MicroscopeControl.HardwareImplementations.Triggerscope.ZEROTOTEN — Constant
DAC range 0 to 10 V, range code 2. See Range.
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.
MicroscopeControl.HardwareInterfaces.TrigInterface.getinputvalue — Method
TrigInterface.getinputvalue(trig::TRIG, input::Input, channel::Int)The value of channel of the input group input. Not exported. [limitation] Triggerscope4 cannot read its inputs this way: its method logs an error and returns the stored input.values[channel].
MicroscopeControl.HardwareInterfaces.TrigInterface.getoutputvalue — Method
TrigInterface.getoutputvalue(trig::TRIG, output::Output, channel::Int)The value last commanded on channel of output. Not exported.
MicroscopeControl.HardwareInterfaces.TrigInterface.setoutputrange — Method
TrigInterface.setoutputrange(trig::TRIG, output::Output, channel::Int, range)Set the output range of channel in output, for groups whose range can change (output.israngevariable). Not exported.
MicroscopeControl.HardwareInterfaces.TrigInterface.setoutputvalue — Method
TrigInterface.setoutputvalue(trig::TRIG, output::Output, channel::Int, value)Command channel of the output group output to value (volts for an analog group, Bool for a digital one) and record it in output.values. Not exported.
Base.reset — Method
reset(scope::Triggerscope4) -> StringSend RESET and return the response line. Extends Base.reset; it is not exported from the Triggerscope module for that reason.