Ejemplo n.º 1
0
def daq():
    instrument = NIDAQmxInstrument(model_number=device_model_number)

    # configure port0.line0 and line1 to inputs
    instrument.port0.line0
    instrument.port0.line1

    # configure ao lines to 0V
    instrument.ao0 = 0
    instrument.ao1 = 0

    yield instrument
Ejemplo n.º 2
0
from daqmx import NIDAQmxInstrument

# tested with NI USB-6001
# which has the following digital inputs:
#  - port0/line0 through line7
#  - port1/line0 through line3
#  - port2/line0

# first, we allocate the hardware using the automatic hardware allocation
# available to the instrument; this is safe when there is only one NIDAQmx
# instrument, but you may wish to specify a serial number or model number
# for a safer experience
daq = NIDAQmxInstrument()

print(daq)

# read the True or False state on the digital outputs
# by reading the `portX` and `lineX` attributes; you
# may wish to use the 5V output available to force the
# pin to a state
print(daq.port0.line0)
print(daq.port0.line1)

# !!! IMPORTANT !!!!
# if you set the value of a port/line, the hardware will be changed to an
# output; however if you read the value using the similar syntax, the hardware
# will be changed to an input!
Ejemplo n.º 3
0
def test_hardware_acq_dev_name_invalid():
    with pytest.raises(ValueError):
        daq = NIDAQmxInstrument(device_name='DevBlah')
Ejemplo n.º 4
0
def test_hardware_acq_dev_name():
    daq = NIDAQmxInstrument(device_name=device_name)
    assert daq.model == device_model_number
Ejemplo n.º 5
0
def test_hardware_acq_sn_int():
    daq = NIDAQmxInstrument(serial_number=int(device_serial_number, 16))
    assert daq.model == device_model_number
Ejemplo n.º 6
0
def test_hardware_acq_no_param():
    daq = NIDAQmxInstrument()
    assert daq.model == device_model_number
Ejemplo n.º 7
0
from daqmx import NIDAQmxInstrument

# tested with NI USB-6001

# first, we allocate the hardware using the automatic hardware allocation
# available to the instrument; this is safe when there is only one NIDAQmx
# instrument, but you may wish to specify a serial number or model number
# for a safer experience
daq = NIDAQmxInstrument()
print(daq)  # printing the instrument will result in showing the
# device name, model number, and serial number

# you may also want to specify a particular device name, as assigned by
# the DAQmx interface; this is usually something like `Dev3`, although
# I believe that it may be renamed through the DAQmx interface
daq = NIDAQmxInstrument(device_name='Dev3')
print(daq)

# you might also simply wish to specify the model number to acquire
daq = NIDAQmxInstrument(model_number='USB-6001')
print(daq)

# further, you may wish to specify a particular serial number
daq = NIDAQmxInstrument(serial_number='1B5D996')  # <-- the serial number, as
print(daq)  # read off the back of the
# device in a hex format, is
# entered as a string

daq = NIDAQmxInstrument(serial_number=28694934)  # <-- this is the same device,
print(daq)  # entering the serial number
# as an integer instead of as
Ejemplo n.º 8
0
from daqmx import NIDAQmxInstrument

# tested with NI USB-6001
# which has the following analog outputs:
#  - ao0
#  - ao1

# first, we allocate the hardware using the automatic hardware
# allocation available to the instrument; this is safe when there
# is only one NIDAQmx instrument, but you may wish to specify a
# serial number or model number for a safer experience
daq = NIDAQmxInstrument()

print(daq)

# set the voltage on the analog outputs by setting the
# attribute `aoX`; use your multimeter to verify!
daq.ao0 = 1.02
daq.ao1 = 2.04

# once the attribute is set, you should be able to read
# it on the daq; if the attribute hasn't been set, this
# will result in an error (for now)
print(f'ao0: {daq.ao0:.2f}V')

# if you set an attribute on an output that doesn't exist,
# then the attribute will be set on the object, but nothing
# will happen!  be sure that you are setting valid attributes
daq.ao2 = 3.0
print(daq.ao2)  # <-- there is no "ao2"!!!