'Python nidaqmx to read K thermocouple value
I am a Python newbie but get by generally by modifying examples to suit my limited needs.
I am trying to automate some temperature measurements using NI 9213 in conjunction with NI CDAQ 9714
I viewed the video from NI and was able to take measurements generically
https://www.youtube.com/watch?v=NMMRbPvkzFs
However I cant specify correctly the type of thermocouple
import nidaqmx
nidaqmx.constants.ThermocoupleType(10073) nidaqmx.constants.TemperatureUnits(10143)
with nidaqmx.Task() as task:
task.ai_channels.add_ai_thrmcpl_chan("cDaq1Mod1/ai0:1")
#task.ai_channelsadd_ai_thrmcpl_chan("cDaq1Mod1/ai0:1","bob", 0.0, 100.0,units="TemperatureUnits.DEG_C: 10143", thermocouple_type="ThermocoupleType.J: 10072")
data=task.read(1,1.0)
print (data[0])
From here http://nidaqmx-python.readthedocs.io/en/latest/ai_channel_collection.html
I just cannot work out how to set the units and the type of thermocouple.
I can use commands to set these generically but I cannot refer to them in the add thermocouple command
I am using Anaconda Spyder 3.6
add_ai_thrmcpl_chan(physical_channel, name_to_assign_to_channel=u'', min_val=0.0, max_val=100.0, units=, thermocouple_type=, cjc_source=, cjc_val=25.0, cjc_channel=u'')[source]
Creates channel(s) that use a thermocouple to measure temperature.
Parameters:
physical_channel (str) – Specifies the names of the physical channels to use to create virtual channels. The DAQmx physical channel constant lists all physical channels on devices and modules installed in the system.
name_to_assign_to_channel (Optional[str]) – Specifies a name to assign to the virtual channel this function creates. If you do not specify a value for this input, NI-DAQmx uses the physical channel name as the virtual channel name.
min_val (Optional[float]) – Specifies in units the minimum value you expect to measure.
max_val (Optional[float]) – Specifies in units the maximum value you expect to measure.
units (Optional[nidaqmx.constants.TemperatureUnits]) – Specifies the units to use to return temperature measurements.
thermocouple_type (Optional[nidaqmx.constants.ThermocoupleType]) – Specifies the type of thermocouple connected to the channel. Thermocouple types differ in composition and measurement range.
cjc_source (Optional[nidaqmx.constants.CJCSource]) – Specifies the source of cold-junction compensation.
cjc_val (Optional[float]) – Specifies in units the temperature of the cold junction if you set cjc_source to CONSTANT_VALUE.
cjc_channel (Optional[str]) – Specifies the channel that acquires the temperature of the thermocouple cold- junction if you set cjc_source to CHANNEL.
Any suggestions hugely appreciated. Such a simple thing but I hit a roadblock and cant see any examples that directly relate.
Many Thanks
Gavin
Solution 1:[1]
I've had the same issue.
The solution was to also use nidaqmx.constants. in add_ai_thrmcpl_chan:
with nidaqmx.Task() as task:
task.ai_channels.add_ai_thrmcpl_chan("cDaq1Mod1/ai0:2",name_to_assign_to_channel="", min_val=0.0,
max_val=100.0, units=nidaqmx.constants.TemperatureUnits.DEG_C,
thermocouple_type=nidaqmx.constants.ThermocoupleType.K,
cjc_source=nidaqmx.constants.CJCSource.CONSTANT_USER_VALUE, cjc_val=20.0,
cjc_channel="")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | knolan |
