MultiChannelIO is a class written in python meant to simplify the coding of read and write commands to the National Instruments DAQ USB-6003. It makes use of the PyDAQmx package to communicate with the NIDAQmx package, written in C, provided by National Instruments.
daq = MultiChannelIO(inputChannels, outputChannels, digitalChannels, scalings, channelVoltageLimits, reset)
inputChannels
is a list of the physical device input channels,
e.g. ['Dev1/ai0', 'Dev1/ai1']
.
outputChannels
is a list of the physical device output channels,
e.g. ['Dev1/ao0']
.
digitalChannels
is a list of the physical device digital output channels,
e.g. ['Dev1/port0/line1']
.
optionally, you can input scalings, channelVoltageLimits, and reset
scalings
is a list of values of scale factors to apply to analog inputs and outputs
before writing and after reading,
e.g. [100, 0.05].
Note: specify the scalings for all inputs and outputs if you specify any.
channelVoltageLimits
is a list of pairs of vales of channel range in Volts
e.g. ((-10.0,10.0), (-10.0,10.0), (-10.0,10.0)).
Note: specify the limits for all inputs and outputs if you specify any.
reset
is a boolean for whether the channels should be reset at instantiation.
Configure the device for reading and writing. Create “tasks” within the NIDAQmx framework.
Read one value from all input channels. Returns a python dict referenced by the input channel name.
Read one value (or number_of_points values) from the specified input channel (defaults to first input channel). Returns an numpy array of values.
Write a persistent value to the specified analog output channel (defaults to first analog output channel).
Read ten points (or the number of points specified, should be less than 2000) from the specified input channel, and return the mean value.
Write a 1ms digital high pulse to the output channel specified (defaults to first digital channel). Function returns after the 1ms pulse is completed.
Resets the device. All outputs return to zero.
# setup
from MultiChannelIO import MultiChannelIO
daq = MultiChannelIO(['Dev1/ai0'], ['Dev1/ao0'], ['Dev1/port0/line1'], scalings=[100.0, 0.05])
daq.configure()
# set an output voltage (remains indefinitely)
daq.write('Dev1/ao0’, 50)
# read voltages
daq.readAll()
# read one channel's voltage
daq.read('Dev1/ai0')
# read 1000 samples and take the mean
daq.readMean('Dev1/ai0', 1000)
# send a digital high pulse to port0 line1
daq.digitalPulse()
# reset everything
daq.reset()
Stephen Fleming, during PhD studies in the Golovchenko Lab in the physics department at Harvard University.