From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

PyDAQmx and USB-6000/USB-TC01 Thermocouple Device

Hello all, 


I am thinking of purchasing the same device for an application of my company. Can somebody verify that the code works/works as supposed?

0 Kudos
Message 21 of 27
(1,274 Views)

Here are some useful link that can work for you in the future about

PyDAQmx

https://pythonhosted.org/PyDAQmx/usage.html

 

This GitHub page is awesome, a lot of examples  https://github.com/ni/nidaqmx-python

 

Here is an official white paper http://www.ni.com/white-paper/53059/en/ about    NI and Python Resources

 

Here is a really good pdf https://media.readthedocs.org/pdf/nidaqmx-python/latest/nidaqmx-python.pdf 

 

have a great day.

 

0 Kudos
Message 22 of 27
(1,259 Views)

I conflated the two versions, 

 

One is PyDAQmx  and the other is NI-DAQmx  Python API 

0 Kudos
Message 23 of 27
(1,244 Views)

Hello,

I tried to run the script given but I get the following error:

    sensor = NiUsbTC01()
  File "nitc.py", line 33, in __init__
    self.nidaq = ctypes.WinDLL(nidaq_dll_path)
  File "C:\Python35-32\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

 

The reason is that I don't have the nicau.dll. How can I get it to run without installing all the nidaqmx runtime?

 

Cheers!

 

0 Kudos
Message 24 of 27
(1,166 Views)

Unfortunately, you'll indeed need it. Use the commented-out line:

self.nidaq = ctypes.windll.nicaiu

My code from above is incorrect for that matter, since using only the one DLL doesnt work, which I hadnt realized before I tested it on another machine where the runtime wasnt installed.

 

I also tried to walk down all the dependencies, hoping it'll be just a couple of DLLs that I'd have to add and that it would be portable, but no luck, I finally gave up. But let me know if you can come up with something, it's quite annyoing that you have to install a whopping 300MB software bundle to be able to read out a simple temperature sensor...

0 Kudos
Message 25 of 27
(1,160 Views)

Hello all,

In order to run the python script you have to include the absolute file path of nicau.dll (mine is "C:/Windows/SysWOW64/nicaiu.dll").

I attach the code.

0 Kudos
Message 26 of 27
(892 Views)

Hello All,

 

Python nidaqmx does support logging from the USB-TC01 thermocouple as task:

 

import nidaqmx
from nidaqmx.constants import TerminalConfiguration
import time
import threading
import keyboard

from datetime import datetime

start: bool = False
period: float = 0.1 # every 100 ms ??
logTimeInMinutes: int = 1

def measure_thread(taskDev, devName):

now = datetime.now()
fileName = now.strftime("Thermal_Log_%d_%m_%Y_%H_%M_%S")
print(fileName)
directory = "Log/"
fileHandle = open(directory + fileName + ".csv", "w")
fileHandle.write("TimeStamp (ms), " + "TotalMinElapsed (min), "
+ "Temperature (F) " + "\n")

global start
global period

startTimeInMs = time.time()*1000
lastMinElapsed = 0


while start:
# timeStamp = now.strftime("%d:%m:%Y:%H:%M:%S , ")
timeStamp = time.time()*1000 - startTimeInMs
# 60 seconds in a minute, 1000 ms in a second
TotalMinElapsed = timeStamp/(1000*60)

#in Hours
SegmentHourElapsed = (TotalMinElapsed - lastMinElapsed)/60


samples_per_channel = 10

data = taskDev.read(samples_per_channel)
print(f"{data}")

SampleAvg = sum(data)/len(data)

print(f"{SampleAvg}")
strToWrite = (f"{timeStamp:.3f}, {TotalMinElapsed:.6f}, {SampleAvg:.3f},")

fileHandle.write(strToWrite + "\n")
time.sleep(period)
fileHandle.close()

def main():
global start

devName = 'Dev3'

with nidaqmx.Task() as ThermoTaskDev:
ThermoChannel = ThermoTaskDev.ai_channels.add_ai_thrmcpl_chan("Dev3/ai0",
name_to_assign_to_channel="Thermocouple",
min_val=0.0,
max_val=100.0, units=nidaqmx.constants.TemperatureUnits.DEG_F,
thermocouple_type=nidaqmx.constants.ThermocoupleType.K,
cjc_source=nidaqmx.constants.CJCSource.BUILT_IN)

while start is False:
value = input("Enter 's' to Start: ")
if (value == 's'):
start = True

threadHandle = threading.Thread(
target=measure_thread, args=(ThermoTaskDev, devName))
threadHandle.start()

while True:
if keyboard.read_key() == "q":
start = False
break

threadHandle.join()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
main()
0 Kudos
Message 27 of 27
(337 Views)