Reference

Reading

LeCroyTRC.readtrc — Function
readtrc(file) -> TRCWaveform
readtrc(io::IO) -> TRCWaveform

Read a LeCroy waveform from a file name or from any stream. A stream is read forward only, from its current position to the end of the record, so records that follow one another (a sequence of WF? ALL replies, say) are read by calling readtrc again. Anything before WAVEDESC in the first 64 bytes (a #9… block header, a C1:WF ALL, echo) is skipped.

Each call opens its own file, so any number of calls, nested or from several tasks at once, may read the same path. Tasks may also share one open IOStream: each call holds its lock for a whole record, so each task reads whole records. A buffer or pipe must not be read by two tasks at once, as with any read in Julia.

memory is a byte budget for the samples: a record whose data arrays would take more is refused with an ArgumentError before any of them is read. trcread and trcblocks read such a record in parts. The default is the machine's memory, Sys.total_memory(), not Sys.free_memory(): macOS counts only pages nothing uses as free, and would refuse ordinary files.

Throws LeCroyTRC.FormatError for input that is not a LeCroy waveform or does not hold what its descriptor declares.

source
LeCroyTRC.trcinfo — Function
trcinfo(file) -> TRCInfo
trcinfo(io::IO) -> TRCInfo

The descriptor of a LeCroy waveform, with its user text and time arrays, without reading the samples. On a stream, leaves the position at the first sample.

source
LeCroyTRC.trcmap — Function
trcmap(file) -> TRCWaveform
trcmap(io::IOStream) -> TRCWaveform

readtrc, with the samples mapped from the file rather than read: data1 and data2 are read-only arrays over it, the operating system reads only the pages that are touched, and a record of any size opens at once. A stream is left at the end of the record, as readtrc leaves it; the arrays stay valid after the file is closed.

The arrays read the file as it is when they are indexed. While the waveform is alive, do not let anything change the file: on Windows it cannot be deleted or truncated (a file moved over it leaves the arrays on the old contents); elsewhere a truncated file makes indexing past its new end crash the process. For a file that may still be written to, use readtrc.

source
LeCroyTRC.trcread — Function
trcread(file, r) -> Vector{Int8} or Vector{Int16}
trcread(io::IO, r)

The codes r (1-based) of DATAARRAY1, without reading the others: a window of a long trace. For a sequence capture, r indexes every segment one after another, as data1 does. Scale them with volts(info, codes) and place them with times(info, r), info being trcinfo(file).

A file or buffer skips to the window; any other stream reads its way there. A stream is left after the window, inside the record.

source
LeCroyTRC.trcblocks — Function
trcblocks(f, file; blocksize = 2^20, memory = nothing) -> number of codes
trcblocks(f, io::IO; ...)

Read DATAARRAY1 in blocks of blocksize codes and call f(codes, offset) on each, offset being the 0-based index of codes[1]: a pass over a long trace in bounded memory. codes is one buffer, reused from block to block: copy it to keep a block. The last block is shorter, never padded. memory is a byte budget for that buffer, which then holds at most memory ÷ sizeof(code) codes. Scale a block with volts!(out, info, codes).

f may resize codes (the next block is read at its own length all the same), and may read the same file through a path of its own. It must not read from or move the stream trcblocks reads: on a file or buffer, that is an ArgumentError rather than misread blocks. An IOStream stays locked while f runs, so f must not wait for another task that reads it.

source
LeCroyTRC.FormatError — Type
LeCroyTRC.FormatError(msg)

The input is not a LeCroy waveform, or its descriptor promises data the input does not hold (a truncated file, inconsistent block lengths, an unknown sample format).

source

Types

LeCroyTRC.TRCWaveform — Type
TRCWaveform{T}

A LeCroy waveform: its TRCInfo in info, and the samples as stored, T being Int8 (byte) or Int16 (word). data1 is DATAARRAY1 (every segment, one after another); data2 is DATAARRAY2, empty unless the record carries one (the floor of an extrema record, the imaginary part of a complex one, the min/max pairs of peak detect).

They are Vector{T}s, or read-only arrays over the mapped file for trcmap; the second type parameter is their type.

source
LeCroyTRC.TRCInfo — Type
TRCInfo

The descriptor of a LeCroy waveform, with the blocks that travel with it. Fields carry the template's names in lower case, with their template types, except where decoding makes them more useful:

  • comm_type is :byte or :word, comm_order :little (LOFIRST) or :big;
  • wave_descriptor ... res_array3 are block lengths in bytes;
  • trigger_time is a DateTime (to the millisecond; nothing if the scope stored an impossible date) and trigger_seconds the seconds field at full precision;
  • record_type, processing_done, vert_coupling, wave_source are Symbols named as in the template (:enum_N for a value the template does not list);
  • timebase is in s/div and fixed_vert_gain in V/div (nothing for EXTERNAL or an unlisted value); bandwidth_limit is a Bool;
  • usertext is the USERTEXT block, trigger_times/trigger_offsets the TRIGTIME array (sequence captures: seconds from the first trigger to each one, and from each trigger to its segment's first point), ris_offsets the RIS_TIME array.
source

Scaling and axes

LeCroyTRC.volts — Function
volts(w::TRCWaveform, array = 1) -> Vector{Float64}
volts(T, w::TRCWaveform, array = 1) -> Vector{T}
volts([T,] info::TRCInfo, codes)

The samples of DATAARRAY1 (or array = 2: DATAARRAY2) scaled as the template says, VERTICAL_GAIN * code - VERTICAL_OFFSET. The unit is w.info.vertunit: volts for a channel, whatever the scope says for a math or FFT trace. With info, scales codes read in parts by trcread or trcblocks.

T = Float32 holds any 16-bit code exactly and halves the memory. Most of the time of a long trace goes into the fresh output array itself; volts! reuses one.

source
LeCroyTRC.volts! — Function
volts!(out, w::TRCWaveform, array = 1) -> out
volts!(out, info::TRCInfo, codes) -> out

volts into out, which must have the array's length: for many captures of one length, a buffer allocated once.

source
LeCroyTRC.times — Function
times(w::TRCWaveform) -> AbstractRange
times(w::TRCWaveform, k) -> AbstractRange
times(info::TRCInfo, r) -> AbstractRange

The horizontal axis of a single sweep: HORIZ_OFFSET + i * HORIZ_INTERVAL, in w.info.horunit (seconds for a time-domain trace). For segment k of a sequence capture, the time of each point from that segment's own trigger (add w.info.trigger_times[k] for the time from the first trigger). With info, the times of points r of a single sweep, for codes read by trcread: times(w)[r].

Throws ArgumentError for a sequence without k, a sequence without a TRIGTIME array, and records transferred with a FIRSTPOINT or SPARSINGFACTOR that makes their points a subset of the acquisition.

source

Sequence captures

LeCroyTRC.nsegments — Function
nsegments(w::TRCWaveform) -> Int
nsegments(info::TRCInfo) -> Int

The number of segments: 1 for a single sweep, SUBARRAYCOUNT for a sequence capture. Throws LeCroyTRC.FormatError if the TRIGTIME array and SUBARRAYCOUNT disagree.

source
LeCroyTRC.segments — Function
segments(w::TRCWaveform, v = w.data1) -> Matrix

v (the codes, or anything of the same length such as volts(w), or of data2's length) with one column per segment. A reshape: no copy.

source

With Unitful

LeCroyTRC.units — Function
LeCroyTRC.units(w::TRCWaveform) -> (horizontal = unit, vertical = unit)
LeCroyTRC.units(info::TRCInfo)

The Unitful units of w.info.horunit and w.info.vertunit, so that times(w) * h and volts(w) * v are quantities. LeCroy writes seconds as "S", which is read as seconds, not siemens, also inside a compound such as "V*S"; an empty string is NoUnits. The rest goes to Unitful.uparse, and a string it does not read as a unit is an ArgumentError. Needs using Unitful, which loads its methods.

source