The usb2600
module: pure Python, high-level, object-oriented interface¶
High-level, object-oriented Python interface for MCCDAQ’s USB2600 data acquisition devices.
Built on top of the low-level Cython usb2600.wrapper
module.
It includes advanced functionalities for analog input and output scans of arbitrary length and synchronous analog input/output scanning.
Todo
Add support for retrigger
and burst
options
Examples: |
---|
>>> from mccdaq import usb2600
>>> daq = usb2600.USB2600() # Initialise device
>>> daq.device.blink(10) # blink LED 10 times
>>> daq.device.temperature() # read temperature
>>> daq.status # return info about AI/AO scans
Counter: |
---|
>>> daq.counter0.init() # Initialiase Counter 0
>>> daq.counter0.read() # Read number of detected edges since init()
Timer: |
---|
>>> daq.timer0.configure(frequency=1000, duty_cycle=0.25) #1 kHz, 0.25 duty cycle square waveform
>>> daq.timer0.start()
>>> daq.timer0.stop()
Analog input: |
---|
>>> v = daq.ai0.read() # Single sample from AI0
>>> v = daq.ai.read((1,4,16)) # Single sample from multiple channels
>>> aiscan = daq.AIScan((0,1,2), nsamples=1000, rate=1000) # AI scan: 1kS at 1kS/s from channels 0,1 and 2
>>> aiscan.run() # Run the scan
>>> aiscan.data # Acquired data (numpy array)
Analog output: |
---|
>>> daq.ao0(1) # Set AO0 to 1V
>>> wf = waveform.sine(10, nsamples=1000, rate=1000) # Sine waveform, 10Hz, 1kS @ 1kS/s
>>> aoscan = daq.AOScan((3,), wf) # Set up analog output of waveforms in data
>>> aoscan.run(thread=True) # run the scan in background
>>> aoscan.run(n=10) # output the waveform 10 times
>>> aoscan.run(n=0) # output the waveform forever
Synchronous analog input/output: | |
---|---|
>>> wf = waveform.helixscan(1, 10) # Create 2D waveform
>>> aio = daq.AIOScan((0,1,2), (0,1), wf) # Output waveform on AO channels 0 and 1 while acquiring on AI channels 0, 1 and 2
>>> aio.run() # start scan
>>> aio.data.plot() # visualise acquired data
Triggering analog scans: | |
---|---|
>>> daq.external_trigger.configure() # Configure external trigger
>>> daq.internal_trigger.configure(daq.dio.A7) # Configure internal trigger, source is A7
Digital input/outputs: | |
---|---|
>>> daq.dio.A.direction = 0x0F # Configure bits 7-4 as outputs, 3-0 as input on port A
>>> daq.dio.A() # Read whole port
>>> daq.dio.A(0xAA) # Set all bits on port
>>> daq.dio.A0.isoutput = True # Configure pin A0 as output
>>> daq.dio.A1.isinput = True # Configure pin A1 as input
>>> # Several methods to set an output pin
>>> daq.dio.A0(True) # pin is callable
>>> daq.dio.A0.set() # set() = HIGH
>>> daq.dio.A0.reset() # reset() = LOW
>>> daq.dio.A0.state = True # property
>>> # Several methods to read an input pin
>>> daq.dio.A1() # pin is callable
>>> daq.dio.A1.get() # method
>>> daq.dio.A1.state # property
- 2014 Guillaume Lepert, Imperial College London.
-
exception
mccdaq.usb2600.usb2600.
USB2600Error
[source]¶ Alias of
exceptions.RuntimeError
to represent USB2600 exceptions.
-
class
mccdaq.usb2600.usb2600.
USB2600
(device=None, model=2627)[source]¶ High-level interface for MCCDAQ USB-2600 series data acquisition device.
- This top-level container provides access to:
- analog inputs
ai0
,ai1
, ... are instances ofAI_Single
. ai
represents several analog input channels to be read simultaneously: seeAI_Multichannel
.- analog outputs
ao0
,ao1
, ... are instances ofAO_Single
. - digital input/output ports
dio.A
,dio.B
, ..., are instances ofDIO_Port
. Each contains 8pin0
,pin1
, etc. , instances ofDIO_Pin
. - counters
counter0
,counter1
, ... are instances ofCounter
. - timers
timer0
,timer1
, ... are instances ofTimer
.
- analog inputs
Create analog scans (AI, AO and synchronous AIO) with the methods
AIScan()
,AOScan()
andAIOScan()
.Blink the LED with
blink()
.Read the device
temperature
,serial_number
, andstatus
.Parameters: - device – a
usb2600.wrapper.USB2600_Wrapper
instance. If None, creates a new instance. - model (int) – the model of the device to look for (2623, 2627, 2633 or 2637)
-
serial_number
¶ Return the device’s serial number.
-
temperature
¶ Return the device internal temperature, in Celsius.
-
status
¶ Return the device status as a dictionary.
-
AIScan
(channels, nsamples, rate, trigger=False, retrigger=1, burst=True, packet_size=240, tf=0.5, verbose=False)[source]¶ Returns an Analog Input object (
AI_Scan
)Parameters: - channels – tuple of integers indicatings the analog input channels.
- nsamples – number of samples to acquire
- rate – sampling frequency (Hz)
- trigger – if True, start the scan on XTTLTRG.
-
AOScan
(channels, waveform, rate=None, trigger=False, retrigger=1, packet_size=240, tf=0.5, verbose=False)[source]¶ Returns an Analog Output object (see
AO_Scan
)Parameters: - channels – tuple of integers indicatings the analog output channels.
- waveform – a
Waveform
instance containing the data. Must have the same number of rows as channels - rate – sampling frequency (Hz). if not given, use that of the waveform.
- trigger – if True, start the scan on XTTLTRG.
-
AIOScan
(AIchans, AOchans, AOwaveform, rate=None, packet_size=240, tf=0.5, verbose=False)[source]¶ Return a Synchronous Analog Input/Output scan object (
AIO_Scan
).Parameters: - AIchans – tuple of integers indicatings the analog input channels.
- AOchans – tuple of integers indicatings the analog ouput channels.
- AOdata –
Waveform
object
Note
- The sampling frequency is taken from the
AOdata
waveform. - The trigger’s digital output must be connected to the external trigger input XTTLTRG.
-
class
mccdaq.usb2600.usb2600.
Timer
(device, timer)[source]¶ Each timer on the device is an instance of this class.
Parameters: -
status
(read_configuration=False)[source]¶ Check the timer status (Enable, Running).
Optionally query the current configuration (Period, Pulse width, Delay, Count) and writes to the corresponding attributes.
-
-
class
mccdaq.usb2600.usb2600.
Counter
(device, counter)[source]¶ Each counter on the device will be an instance of this class.
Parameters:
-
class
mccdaq.usb2600.usb2600.
DIO_Port
(device, port)[source]¶ Controls a DIO port.
Parameters: -
state
¶ Set or query the port state.
-
direction
¶ Query or configure the port direction (0xFF all inputs, 0x00 all ouputs, or a mixture: 0x01, etc.)
-
-
class
mccdaq.usb2600.usb2600.
DIO_Pin
(port, pin)[source]¶ Controls a single bit of a DIO port.
Parameters: -
state
¶ Set or query the pin state.
-
isinput
¶ Query whether the pin is configured as input, or configure it so by setting it to True.
-
isoutput
¶ Query whether the pin is configured as output, or configure it so by setting it to True.
-
-
class
mccdaq.usb2600.usb2600.
ExternalTrigger
(device, mode='Edge', polarity='Rising')[source]¶ Represents an external trigger (external digital output connected to XTTLTRG).
Parameters: - mode – ‘Edge’ or ‘Level’.
- polarity – in ‘Edge’ mode: ‘Rising’ or ‘Falling’. In ‘Level’ mode : ‘Low’ or ‘High’.
-
class
mccdaq.usb2600.usb2600.
InternalTrigger
(dio_pin, mode='Edge', polarity='Rising')[source]¶ Internal trigger by connection XTTLTRG to a digital output pin.
Parameters: - dio_pin – a
DIO_Pin
instance, physically connected to XTTLTRG. - mode – ‘Edge’ or ‘Level’.
- polarity – in ‘Edge’ mode: ‘Rising’ or ‘Falling’. In ‘Level’ mode : ‘Low’ or ‘High’.
- dio_pin – a
-
class
mccdaq.usb2600.usb2600.
AI_Single
(device, channel)[source]¶ Single sample, single channel analog input.
>>> volts = daq.ai0.read() >>> volts = daq.ai0() # callable.
-
class
mccdaq.usb2600.usb2600.
AI_Multichannel
(device)[source]¶ Single sample, multiple channel acquisition: out = daq.ai.read((ch1, ..., chn)).
-
class
mccdaq.usb2600.usb2600.
AI_Scan
(device, channels, nsamples, rate, trigger=False, retrigger=1, burst=True, packet_size=240, tf=0.5, verbose=True)[source]¶ Analog Input scan.
Acquired data in
data
.TO DO: return data as a Waveform object.
Parameters: - device –
USB2600
instance - channels – tuple of integers indicatings the analog input channels.
- nsamples – number of samples to acquire
- rate – sampling frequency (Hz). To use an external clock source
(connected to
AI_CLK_IN
on the board), setrate=0
. - trigger – Whether to wait for a trigger on XTTLTRG to start acquiring.
If False, acquisition starts when calling
run()
- retrigger – How often
- burst – burst mode (UNTESTED)
- packet_size – number of bytes in each USB read operation.
- tf – USB read time factor. If getting
AI_FIFO_OVERRUN
, try decreasing tf to pop data from the FIFO faster. - verbose – if True, print info to console while scan is running.
-
flush
()[source]¶ Read all remaining elements in FIFO.
It may be necessary to call flush() before an AI or AIO scan to remove old, unread samples from AI FIFO.
-
run
(thread=False)[source]¶ Start the scan in main or background thread.
In a background thread, call stop() to stop the scan before completion. In the main thread, use Ctl+C.
-
fifo_overrun
¶ Return True if the AI FIFO is full.
-
running
¶ Return True while samples are being read.
-
done
¶ Return True once all samples have been read.
- device –
-
class
mccdaq.usb2600.usb2600.
AO_Single
(device, channel)[source]¶ Single sample, single channel analog ouput.
>>> daq.ao0.write(0.56) # output 0.56 volts to AO0
-
class
mccdaq.usb2600.usb2600.
AO_Scan
(device, channels, waveform, rate=None, trigger=False, retrigger=1, packet_size=240, tf=0.5, verbose=False)[source]¶ Single- or multi-channel analog output scan.
To start the scan:
>>> run(n=0, thread=True|False) * n: output the waveform n times (0=infinity) * thread: whether to run in a background thread (call stop() to stop it) or in the main thread (Ctl+C to stop)
Parameters: - device –
USB2600
instance - channels – tuple of integers indicatings the analog output channels.
- waveform – a
Waveform
instance containing the data. Must have the same number of rows aschannels
- rate – sampling frequency (Hz). if not given, use
waveform.data
. - trigger – a
Trigger
instance to use as external trigger. - packet_size – number of bytes in each USB read operation.
- tf – USB read time factor. If getting
AO_FIFO_UNDERRUN
error, try decreasing tf to push data to the FIFO faster. - verbose – if True, print info to console while scan is running.
-
start
(repeat=1, continuous=False)[source]¶ Start the AO scan.
Parameters: - continuous – True for continuous operation (output until FIFO underruns). False to output a fixed number of samples, determined by the data waveform and the repeat parameter.
- repeat – number of time to output the waveform. 0 if forever.
-
run
(n=1, wait=False, thread=False)[source]¶ Start the scan.
Parameters: - n – number of waveform repeats. 0=forever.
- thread – whether to run the scan in a background thread.
if True, call
stop()
to interrupt the scan, other wise useCtrl+C
- wait – if True, block until the scan is complete. If False, return as soon as all data has been written to the FIFO.
-
fifo_underrun
¶ Return True if the AO FIFO is empty.
-
running
¶ Return True while samples are being output.
-
done
¶ Return True once all samples have been ouput.
- device –
-
class
mccdaq.usb2600.usb2600.
AIO_Scan
(device, AIchans, AOchans, AOwaveform, rate=None, packet_size=240, tf=0.5, verbose=False)[source]¶ Synchronous analog input and output scan.
To start the scan:
>>> run(thread=True|False) * thread: whether to run in a background thread (set running=False to stop it) or in the main thread (Ctl+C to stop).
The acquired analog input data is in the
data
attribute.Parameters: - device –
USB2600_Wrapper
instance - AIchans – tuple of integers indicating the analog input channels.
- AOchans – tuple of integers indicating the analog output channels.
- AOwaveform – a
Waveform
instance containing the analog output data. Must have the same number of rows asAOchans
- rate – sampling frequency (Hz). If not given, use
AOwaveform.rate
. - packet_size – number of bytes in each USB read/write operation.
- tf – USB read time factor. If getting
AO_FIFO_UNDERRUN
orAI_FIFO_OVERRUN
errors, try decreasing tf to pop/push data to the FIFO faster. - verbose – if True, print info to console while scan is running.
- device –