08-17-2020 09:43 AM
I have a quite simple problem with Python code. I'm using the cDAQ-9185 with NI 9237 module connected to 2xKulite XTM-190M pressure transducers. My aim is to get data in a continuous manner until user input is given (this is not implemented atm). I have based my code on this video:
How to Make a Temperature Measurement with Python and NI CompactDAQ
The main issue right now is to specify the custom scale for the measurement.
The pressure transducer documentation specifies 0.216 mV/bar (so linear scaling).
from nidaqmx.constants import BridgeUnits
from nidaqmx.constants import UnitsPreScaled
from nidaqmx.constants import BridgeConfiguration
from nidaqmx._task_modules.channels.ai_channel import AIChannel
import matplotlib.pyplot as plt
# Prevent the graph from closing during measurement
# Index of a data point
i = 0
# bool: Specifies if NI-DAQmx divides the measurement by the
# excitation. You should typically set this property to True
# for ratiometric transducers. If you set this property to
# True, set **ai_max** and **ai_min** to reflect the scaling.
# My custom scale
custom_scale1 = nidaqmx.scale.Scale.create_lin_scale('99991', (1/0.000216), 0.0,
pre_scaled_units = UnitsPreScaled.VOLTS)
# Initiating a task for bridge based sensor
with nidaqmx.Task() as task:
# min_val = -0.075 V, max_val = 0.075 V
# units = 10065 - custom units
min_val = -0.075, max_val = 0.075,
units = BridgeUnits(10065),
custom_scale_name = '99991')
while i < 100:
data1 = task.read(number_of_samples_per_channel = 1)
plt.scatter(i, data1, c = 'r')
i += 1
Using this code it raises an error:
DaqError: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Requested Value: DAQmx_Val_Volts
Possible Values: DAQmx_Val_VoltsPerVolt
Channel Name: cDAQ9185-1EF7BE9Mod1/ai0
Task Name: _unnamedTask<27>
Status Code: -200077
So even though the 'ai_excit_use_for_scaling.setter(False)' is in place the bridge still wants 'volt per volt' measurement (which is incorrect in my case).
How to implement the 0.216 mV/bar in Python then?
NI MAX version 19.0.0f0
NI Device Monitor 188.8.131.52152
Windows 10 Enterprise N