Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

PyDAQmx and USB-6000/USB-TC01 Thermocouple Device

Highlighted
None of that has anything that resembles the little bit of PyDAQmx that I saw. Study the c function prototypes as noted.
0 Kudos
Message 11 of 26
(2,429 Views)
Highlighted

@Yakav wrote:

Either help contribute, or don't reply. I'm not looking for passive-agressive answers - this goes to nyc


You are the person who chose to go down this path of using Open Source software.

You are the person who needs to do the work.

 

It seems you want the answers handed to you on a platter.

Do some WORK!

 

 

0 Kudos
Message 12 of 26
(2,423 Views)
Highlighted

Nyc,

 

Please leave - you are obviously a troll and unwilling to promote meaningful dialogue. Others have actually guided me towards a direction, while you on the other hand have been inconsiderate and ill-mannered. Take your unnecessary banter elsewhere.

0 Kudos
Message 13 of 26
(2,417 Views)
Highlighted

@Yakav wrote:

Nyc,

 

Please leave - you are obviously a troll and unwilling to promote meaningful dialogue. Others have actually guided me towards a direction, while you on the other hand have been inconsiderate and ill-mannered. Take your unnecessary banter elsewhere.


You were guided to the PyDAQmx website eons ago, and yet you choose to ignore it.

And kept coming back here for goodness know what reason?

 

Engineering is hard. If it was easy, people could just keep asking questions on message boards.

0 Kudos
Message 14 of 26
(2,411 Views)
Highlighted

If you attempted to read my comment earlier, you would have seen that I did read the PyDAQmx documentation and source code. This dead-end in information led me to asking if others have attempted a similar path (which obviously you haven't). I'm not interested in your lecturing, I could care less.

 

Here's a question, what are the message boards for? I've browsed around the forums looking for a similar question but no luck. So, am I suppose to go off leads with no lead? 

0 Kudos
Message 15 of 26
(2,402 Views)
Highlighted

@Yakav wrote:

If you attempted to read my comment earlier, you would have seen that I did read the PyDAQmx documentation and source code. This dead-end in information led me to asking if others have attempted a similar path (which obviously you haven't). I'm not interested in your lecturing, I could care less.

 

Here's a question, what are the message boards for? I've browsed around the forums looking for a similar question but no luck. So, am I suppose to go off leads with no lead? 


How exactly is it "dead end"????

 

 

And, again, you chose to use PyDAQmx. No one forced you to use it.

No documentation is due to *your* decision to use the software.

 

 

 

 

0 Kudos
Message 16 of 26
(2,395 Views)
Highlighted

I am forced to use PyDAQmx due to the circumstances of my company - please, take the time to read my previous comments (this is already explained). You obviously have trouble understanding my goals. Are you mentally handicapped? Please go entertain others that might be interested in a clown

 

 

0 Kudos
Message 17 of 26
(2,392 Views)
Highlighted

@Yakav wrote:

I am forced to use PyDAQmx due to the circumstances of my company - please, take the time to read my previous comments (this is already explained). You obviously have trouble understanding my goals. Are you mentally handicapped? Please go entertain others that might be interested in a clown

 

 


And again, your company gets what it "paid" for.

 

The documentation is there on the PyDAQmx webpage.

 

And again, what makes it "dead end"?

 

 

 

 

0 Kudos
Message 18 of 26
(2,390 Views)
Highlighted

I stumbled upon this thread after having the same task to do like you, which is reading out a NI USB TC01 via Python. It's probably a bit late, i know, but who knows, maybe this will help someone else.

 

I realized that what PyDAQmx does is basically talk to the NIDAQmx driver's C-API via Python's ctypes. Most of the wrapping functionality it brings isn't really needed for such a simple task, or at all helpful regarding the actual problem there, which is: how do you use this C-API, i.e., which functions to call?

 

Neither looking through the documentation for NI USB TC01, nor the example codes for C-API posted earlier, nor anything else I was able to come up with from NI websites helped me here, so this was a rather frustrating experience. Again, this is a problem of bad documentation on the side of NI, not one of "open source" or "not enough effort put in it" (or anything else of the troll bs posted here).

 

I finally managed to make it work, using the example code from Scipy cookbook and tinkering around with the exported functions from the dll, using the header file (NIDAQmx.h).

 

Here's the code.

Requires: Python 3, ctypes, numpy,  nicaiu.dll (obtained from NIDAQmx 15 runtime, in my case).

 

import ctypes
import numpy as np
import os

class NiUsbTC01:
    # type mappings
    int32 = ctypes.c_long
    uInt32 = ctypes.c_ulong    
    float64 = ctypes.c_double
    
    # constants mappings
    tc_types = {
        "J" : 10072,        # DAQmx_Val_J_Type_TC
        "K" : 10073,        # DAQmx_Val_K_Type_TC
        "N" : 10077,        # DAQmx_Val_N_Type_TC
        "R" : 10082,        # DAQmx_Val_R_Type_TC
        "S" : 10085,        # DAQmx_Val_S_Type_TC
        "T" : 10086,        # DAQmx_Val_T_Type_TC
        "B" : 10047 ,       # DAQmx_Val_B_Type_TC
        "E" : 10055,        # DAQmx_Val_E_Type_TC
    }
    
    temp_units = {
        "C" : 10143,        # DAQmx_Val_DegC
        "F" : 10144,        # DAQmx_Val_DegF
        "K" : 10325,        # DAQmx_Val_Kelvins
    }

    def __init__(self, device_id="Dev1", channel_id="ai0", tc_type="K", temp_unit="C", temp_min=-50, temp_max=100):
        # load the DLL        
        nidaq_dll_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bin/nicaiu.dll")
        self.nidaq = ctypes.WinDLL(nidaq_dll_path)
        
        # alternatively, if runtime is installed & registered:
        # self.nidaq = ctypes.windll.nicaiu
        
        self.task_handle = self.uInt32(0)
        physical_channel = "{}/{}".format(device_id, channel_id)
                
        # reset device
        self.nidaq.DAQmxResetDevice(device_id.encode("ASCII"))

        # create task        
        self._nidaq_assert(self.nidaq.DAQmxCreateTask(b"", ctypes.byref(self.task_handle)))

        # create channel
        self._nidaq_assert(self.nidaq.DAQmxCreateAIThrmcplChan(
            self.task_handle,
            physical_channel.encode("ASCII"),
            b"",
            self.float64(temp_min),
            self.float64(temp_max),
            self.temp_units[temp_unit],            
            self.tc_types[tc_type],
            10200,             # DAQmx_Val_BuiltIn   //  CJC Source "Built-In"            
            self.float64(0),
            b""
        ))
           
        # start task
        self._nidaq_assert(self.nidaq.DAQmxStartTask(self.task_handle))
       
    def __del__(self):        
        try:
            self._close_task()
        except:
            pass  # worth a try
            
    def _close_task(self):
        if self.task_handle.value != 0:
            self.nidaq.DAQmxStopTask(self.task_handle)
            self.nidaq.DAQmxClearTask(self.task_handle)
    
    def _nidaq_assert(self, err):
        """Raise Exception if return code 'err' is not 0."""
        if not err == 0:
            buf_size = 300
            buf = ctypes.create_string_buffer(b'\0' * buf_size)
            self.nidaq.DAQmxGetErrorString(err, ctypes.byref(buf), buf_size)
            raise Exception('nidaq call failed with error {}: {}'.format(err, repr(buf.value)))
                          
    def get_temperature(self):
        read = self.int32()        
        data = np.zeros(1, dtype=np.float64)  # size 1 array, passed by ref to be filled
        
        self._nidaq_assert(self.nidaq.DAQmxReadAnalogF64(
            self.task_handle,           
            1,                          # number samples per channel
            self.float64(1.0),          # timeout in sec
            0,                          # DAQmx_Val_GroupByChannel   // Group by Channel   
            data.ctypes.data,           # the array byref
            1,                          # array size in samples
            ctypes.byref(read),         # samples per channel read (return value)
            None                        # reserved
        ))                                                    
        
        return data[0]
        
if __name__ == "__main__":
    sensor = NiUsbTC01()
    print(sensor.get_temperature())
Message 19 of 26
(1,309 Views)
Highlighted

Thanks a lot! I need to do it right now!:)

0 Kudos
Message 20 of 26
(1,234 Views)