Channels#
Channel module.
Contains the BaseChanProxy and AO/DOChanProxy classes
representing individual channels.
- class nistreamer.channel.BaseChanProxy(_streamer, _card_max_name, nickname=None)[source]#
Bases:
ABCThe base of channel proxy classes.
- abstract property chan_name: str#
Physical channel name.
- property nickname: str#
Human-readable channel name used in visualizations.
Nickname is set when channel is added to the card. If no nickname was specified,
chan_name()is used instead.
- abstract property dflt_val#
The default value for intervals that are not covered by instructions.
- abstract property rst_val#
The value set by
add_reset_instr()command.
- add_instr(func, t, dur, keep_val=False)[source]#
Add a finite-duration instruction.
- Parameters:
func – waveform function instance
t (
float) – start timedur (
float) – durationkeep_val (
Optional[bool]) – determines the constant value after instruction end. IfTrue, the last waveform value is kept, otherwise channel goes to default.
- Return type:
float- Returns:
Instruction duration
- Raises:
ValueError – if this instruction collides with an existing one
TypeError – if waveform function does not mach channel type (analog/digital)
Examples
>>> from nistreamer import NIStreamer, std_fn_lib >>> >>> strmr = NIStreamer() >>> ao_card = strmr.add_ao_card(max_name='Dev1', samp_rate=1e6) >>> ao_0 = ao_card.add_chan(chan_idx=0) >>> >>> ao_0.add_instr( >>> func=std_fn_lib.LinFn(slope=1, offs=2), >>> t=1.0, >>> dur=2.0, >>> keep_val=True >>> )
- add_gothis_instr(func, t)[source]#
Add an instruction with unspecified duration.
A so-called “go-this” instruction. During compilation, it will automatically fill the full interval until the next instruction start or global sequence end.
- Parameters:
func – waveform function instance
t – start time
- Returns:
Instruction duration
- Raises:
ValueError – if this instruction collides with an existing one
TypeError – if waveform function does not mach channel type (analog/digital)
Examples
>>> from nistreamer import NIStreamer, std_fn_lib >>> >>> strmr = NIStreamer() >>> ao_card = strmr.add_ao_card(max_name='Dev1', samp_rate=1e6) >>> ao_0 = ao_card.add_chan(chan_idx=0) >>> >>> ao_0.add_gothis_instr( >>> func=std_fn_lib.Sine(amp=1.0, freq=2e3), >>> t=1.0, >>> ) >>> strmr.compile(stop_time=10.0)
- last_instr_end_time()[source]#
Returns the last instruction end time or
Noneif the edit cache is empty.- Return type:
Optional[float]
- abstractmethod calc_signal(start_time=None, end_time=None, nsamps=1000)[source]#
Computes channel values for an array of time points.
This function is exposed for channel signal plotting. The
nsampstime points are distributed uniformly over the closed interval[start_time, end_time].- Parameters:
start_time (
Optional[float]) – interval start. IfNone, zero time is usedend_time (
Optional[float]) – interval end. IfNone, sequence end is usednsamps (
Optional[int]) – number of points
- Returns:
List of corresponding channel values
- Raises:
ValueError – if any parameters are invalid, if sequence is not fresh-compiled.
Notes
You may need to select a sufficiently large
nsampsand a sufficiently narrow time window to see the true waveform shape that the actual stream would produce when sampling at the hardware clock rate. Otherwise, very narrow pulses may be missed and periodic waveforms may appear distorted due to undersampling.
- abstractmethod eval_point(t)[source]#
Computes channel value at time point
t.Unlike
calc_signal(), this method does not require sequence compilation. So it can be used in sequence scripting, for instance to “measure” start values for ramps.CAUTION! The returned value is computed according to the current edit cache, and does not update with any future sequence edits. If later in the script, an instruction is added at earlier time changing the actual value at point
t, there may be a discontinuity since the ramp will use the outdated start value that was given to it.
- class nistreamer.channel.AOChanProxy(_streamer, _card_max_name, chan_idx, nickname=None)[source]#
Bases:
BaseChanProxyAnalog output channel proxy.
- property chan_name: str#
Physical channel name.
- property dflt_val: float#
The default value for intervals that are not covered by instructions.
- property rst_val: float#
The value set by
add_reset_instr()command.
- calc_signal(start_time=None, end_time=None, nsamps=1000)[source]#
Computes channel values for an array of time points.
This function is exposed for channel signal plotting. The
nsampstime points are distributed uniformly over the closed interval[start_time, end_time].- Parameters:
start_time – interval start. If
None, zero time is usedend_time – interval end. If
None, sequence end is usednsamps – number of points
- Returns:
List of corresponding channel values
- Raises:
ValueError – if any parameters are invalid, if sequence is not fresh-compiled.
Notes
You may need to select a sufficiently large
nsampsand a sufficiently narrow time window to see the true waveform shape that the actual stream would produce when sampling at the hardware clock rate. Otherwise, very narrow pulses may be missed and periodic waveforms may appear distorted due to undersampling.
- eval_point(t)[source]#
Computes channel value at time point
t.Unlike
calc_signal(), this method does not require sequence compilation. So it can be used in sequence scripting, for instance to “measure” start values for ramps.CAUTION! The returned value is computed according to the current edit cache, and does not update with any future sequence edits. If later in the script, an instruction is added at earlier time changing the actual value at point
t, there may be a discontinuity since the ramp will use the outdated start value that was given to it.- Return type:
float
- const(t, dur, val)[source]#
Constant-value pulse with a fixed duration.
- Parameters:
t (
float) – start timedur (
float) – pulse durationval (
float) – value
- Return type:
float- Returns:
Pulse duration
- Raises:
ValueError – if this instruction collides with an existing one
Notes
This method does not have the “keep value” option - the channel will transition to the default value at the end of this pulse. Use
go_const()if you want to set and keep the constant value instead.
- go_const(t, val)[source]#
Set a constant value
valat timetand keep it until further instructions.During compilation, this instruction will automatically fill the full interval until the next instruction start or global sequence end.
- sine(t, dur, amp, freq, phase=0, offs=0, keep_val=False)[source]#
Sinusoidal pulse with a fixed duration.
The waveform is parametrized as follows:
Sine(t) = amp * sin(2Pi * freq * t + phase) + offs- Parameters:
t (
float) – start timedur (
float) – pulse durationamp (
float) – amplitude (Volts)freq (
float) – linear frequency (Hz, 1/period)phase (
Optional[float]) – absolute phase (radians)offs (
Optional[float]) – constant offset (Volts)keep_val (
Optional[bool]) – ifTrue, the last value will be kept after the pulse, otherwise channel goes to default value.
- Return type:
float- Returns:
Pulse duration
dur- Raises:
ValueError – if this instruction collides with an existing one
- go_sine(t, amp, freq, phase=0, offs=0)[source]#
Sinusoidal pulse without a specified duration.
During compilation, this instruction will automatically fill the full interval until the next instruction start or global sequence end.
The waveform is parametrized as follows:
Sine(t) = amp * sin(2Pi * freq * t + phase) + offs,- Parameters:
t (
float) – start timeamp (
float) – amplitude (Volts)freq (
float) – linear frequency (Hz, 1/period)phase (
Optional[float]) – absolute phase (radians)offs (
Optional[float]) – constant offset (Volts)
- Raises:
ValueError – if this instruction collides with an existing one
- linramp(t, dur, start_val, end_val, keep_val=True)[source]#
Linear ramp.
Connects the points
(t, start_val)and(t + dur, end_val)with a linear function. Ifkeep_val=True, the end value will be kept after the pulse, otherwise channel goes to default value.- Return type:
float- Returns:
Duration
dur- Raises:
ValueError – if this instruction collides with an existing one
- sineramp(t, dur, start_val, end_val, keep_val=True)[source]#
Sinusoidal ramp.
Connects the points
(t, start_val)and(t + dur, end_val)with a half-period of a sine function such that the derivative is zero on both ends. Ifkeep_val=True, the end value will be kept after the pulse, otherwise channel goes to default value.- Return type:
float- Returns:
Duration
dur- Raises:
ValueError – if this instruction collides with an existing one
- class nistreamer.channel.DOChanProxy(_streamer, _card_max_name, port_idx, line_idx, nickname=None)[source]#
Bases:
BaseChanProxyDigital output channel proxy (an individual digital line).
- property chan_name: str#
Physical channel name.
- property dflt_val: bool#
The default value for intervals that are not covered by instructions.
- property rst_val: bool#
The value set by
add_reset_instr()command.
- property const_fns_only: bool#
Shows if the host card has the “constant functions only” mode enabled.
If enabled, all lines on this card will only accept the following four constant-valued instructions:
high(),low(),go_high(), andgo_low(). This restriction allows to accelerate the runtime sample computation and significantly reduce the risk of buffer underflow.In most cases, only constant-valued instructions are used anyway, so this mode is enabled by default. If you need to add non-constant boolean waveforms, set
const_fns_only()of the host card toFalse.
- calc_signal(start_time=None, end_time=None, nsamps=1000)[source]#
Computes channel values for an array of time points.
This function is exposed for channel signal plotting. The
nsampstime points are distributed uniformly over the closed interval[start_time, end_time].- Parameters:
start_time – interval start. If
None, zero time is usedend_time – interval end. If
None, sequence end is usednsamps – number of points
- Returns:
List of corresponding channel values
- Raises:
ValueError – if any parameters are invalid, if sequence is not fresh-compiled.
Notes
You may need to select a sufficiently large
nsampsand a sufficiently narrow time window to see the true waveform shape that the actual stream would produce when sampling at the hardware clock rate. Otherwise, very narrow pulses may be missed and periodic waveforms may appear distorted due to undersampling.
- eval_point(t)[source]#
Computes channel value at time point
t.Unlike
calc_signal(), this method does not require sequence compilation. So it can be used in sequence scripting, for instance to “measure” start values for ramps.CAUTION! The returned value is computed according to the current edit cache, and does not update with any future sequence edits. If later in the script, an instruction is added at earlier time changing the actual value at point
t, there may be a discontinuity since the ramp will use the outdated start value that was given to it.- Return type:
bool
- go_high(t)[source]#
Sets the logical high at time
tand keeps it until the next instruction start / sequence end.
- go_low(t)[source]#
Sets the logical low at time
tand keeps it until the next instruction start / sequence end.
- high(t, dur)[source]#
Logical-high pulse from time
ttot + dur.- Return type:
float- Returns:
Pulse duration
dur- Raises:
ValueError – if this instruction collides with an existing one
Notes
This method does not have the “keep value” option - the channel will transition to the default value at the end of this pulse. Use
go_high()instruction if you want to set and keep the constant value instead.
- low(t, dur)[source]#
Logical-low pulse from time
ttot + dur.- Return type:
float- Returns:
Pulse duration
dur- Raises:
ValueError – if this instruction collides with an existing one
Notes
This method does not have the “keep value” option - the channel will transition to the default value at the end of this pulse. Use
go_low()instruction if you want to set and keep the constant value instead.