DigitalIn¶
- class picodaq.adc.DigitalIn(line: int | None = None, lines: ArrayLike | None = None, rate: Frequency | None = None, port: str | None = None, serno: str | None = None)¶
Main interface for acquiring digital data
You must specify either a single line or a list of lines to record from. There are some restrictions on the selection. The lines must be consecutive and specified in order. The total number of lines must be 1, 2, or 4 (i.e., not 3).
The rate may be specified in Hz or kHz. When using multiple streams, the rates must all be the same and only need to be specified on the first-opened stream.
The port specifies which serial port to open. Use
picodaq.devices()to retrieve the list of available ports.If you do not specify a port, the most recently opened device is used, or the first device on the system if none was opened before.
- chunkscans() int¶
Quantum of data transfer
- Returns:
The number of scans in a standard chunk
This is the number of scans that would be returned by the low-level
readchunk()method. The high-levelread()method is most efficient if requested quantities are an integer multiple of this number.This number is only available when the stream is open.
- close()¶
Close the stream
The underlying device is automatically closed once the last stream is closed.
- continuous()¶
Select continuous recording mode
This cancels a previous
episodic(...)call. You normally do not need to call this, as continuous recording is the default.
- episodic(duration: Time | None = None, period: Time | None = None, count: int | None = None)¶
Select episodic recording mode
- Parameters:
duration – Duration of each episode
period – start-to-start time between episodes
count – number of episodes before automatically stopping
The period is measured start-to-start and is optional if triggering is enabled, in which cases it specifies the minimum period.
The count parameter, if given, specifies that the recording will stop automatically after that number of episodes have been recorded. Otherwise, it continues until the user stops the recording.
The specified duration of each episode may be internally lengthened slightly so that it constitutes an even number of USB transfer chunks.
In episodic mode, the timing of any stimuli is modified such that there is one train per episode and the defined inter-train intervals are ignored. The timing between start of the episode and the first pulse of a stimulus is determined by the delay parameter on the stimulus.
See also
continuous.
- immediate()¶
Disable triggering
This cancels a preceding
trigger(...)call, so recording commences immediately uponstart(). You normally do not have to call this, as immediate start is the default operation.
- open()¶
Open the stream
This automatically opens the underlying picoDAQ device. If more than one stream is associated with a single device, each stream must be individually opened and the device remains open as long as any streams are open.
Often,
with ... assyntax is more convenient than callingopen()yourself. If you do callopen()yourself, you must match it withclose().
- read(amount: Time | int | None = None, raw: bool = False, times: bool = False) np.ndarray¶
High-level method for reading data
- Parameters:
amount – Amount of data to be read, either in units of time, or as an integer number of samples.
raw – Whether to return raw data from the device or convert them to more convenient units.
times – Whether to return a vector of time stamps
- Returns:
- data — A numpy array containing the data, either a vector
or a T × C array.
- times — A corresponding vector of time stamps, in seconds
since start of run; only if the times flag is set in the function call.
If no amount is specified at all, a single chunk is read in continuous mode, or a full episode in episodic mode.
If raw is given, the result is a vector of bytes with the lines interleaved. Otherwise, the result is a T-vector or T × C array of zeros and ones, one value per sample.
Digital data must always be read in multiples of 8 scans divided by the number of lines. Requested amounts are rounded down to meet this criterion.
- readall(raw: bool = False, times: bool = False) ndarray¶
Read all data accumulated during
run().- Parameters:
raw – Whether to return raw data from the device or convert them to more convenient units.
times – Whether to return a vector of time stamps.
- Returns:
data — A numpy array containing the data.
- times — A corresponding vector of time stamps, in seconds
since start of run; only if the times flag is set in the function call.
Used after calling
run()onAnalogOutorDigitalOutto retrieve all the data recorded during the run. In continuous mode, returns a T-vector or T × C array. In episodic mode, returns an N × L or N × L × C array, where N is the number of episodes and L is the number of scans per episode.Example of reading just the data:
data = di.readall()
Example of reading timestamps along with the data:
data, times = di.readall(times=True)
The returned times are always a simple vector which applies equally to all lines (and to all episodes).
- readchunk(_maxn=None) ndarray¶
Read a single chunk of data
- Parameters:
_maxn – Maximum number of scans to read. The use of this parameter is not recommended.
- Returns:
A numpy array containing the data
The result is always a vector of interleaved bytes.
Almost always,
read()is more convenient in user code.
- start()¶
Start data acquisition
You typically do not have to call this directly, as
read()calls it for you. If more than one stream is associated with a single PicoDAQ device, callingstart()on one stream suffices to start all of them.The streams must be open before being started.
- stop()¶
Stop data acquisition
You typically do not have to call this directly, as
close()(or the end of awith ... asblock) calls it for you.If more than one stream is associated with a single PicoDAQ device, calling
stop()on one stream suffices to stop all of them.
- trigger(source: int, polarity: int)¶
Define triggering
- Parameters:
source – the digital line to monitor
polarity – edge on which to trigger
The recording (whether continuous or episodic) is not actually started until the given trigger condition is met. The source parameter (0, 1, 2, or 3) specifies a digital channel. The polarity parameter specifies whether the system triggers on rising edge (polarity > 0) or on falling edge (polarity < 0).
See also
immediate.
- verify(force=False)¶
Confirm whether recording parameters are OK
- Parameters:
force – Re-verify unconditionally
- Returns:
True if OK, else false.
You typically don’t have to call this, as
start()andread()call it for you if you don’t. To reduce the latency between when you first callread()and when the first sample is acquired, you can call this ahead of time, but the difference is unlikely to be more than a millisecond.The device keeps track of parameter changes since last call to verify and returns without doing work if there have been none. The force parameter causes unconditional re-verification.