Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

null TaskHandle in Python?

GaryS,

 

Have you tried using the python None type instead of using the null = ctypes.POINTER(ctypes.c_int)() syntax?

 

check out this example code

http://scipy.org/Cookbook/Data_Acquisition_with_NIDAQmx 

Message Edited by Arvont on 07-05-2009 07:39 PM
0 Kudos
Message 11 of 14
(1,873 Views)

GaryS,

 

Have you tried using the python None type instead of using the null = ctypes.POINTER(ctypes.c_int)() syntax?  I've had success using the DAQmx dll in windows and problems typically reduce down to figuring out the proper way of passing variables from the python script to the C function.

 

Learning the ctypes module is the key. 

 

nidaq.DAQmxWriteDigitalLines(enable,
                                                   ctypes.c_int32(1),        # numSamplsPerChan
                                                   ctypes.c_int32(1),        # autostart=1
                                                   ctypes.c_float64(1),     # timeout
                                                   DAQmx_Val_GroupByChannel,
                                                   ctypes.c_uint8(1),        # VALUE TO BE WRITTEN
                                                   ctypes.byref(sampsPerChanWritten),

                                                   None  )      # reserved, supposed to be NULL 

 

check out this example code as well

http://scipy.org/Cookbook/Data_Acquisition_with_NIDAQmx 

0 Kudos
Message 12 of 14
(1,868 Views)

Hello,

 

I just tried (not being aware of this thread) to do the same thing: wrapping DAQmxBase into python under SuSE Linux 10.3, python 2.5.

My approach was using swig, but I unfortunately ran into the same problem -> the taskHandle pointer was NULL after createTask.

 

This just for the records. I might now consider to try the presented solution (compile into python), or I just stay in c++ - don't know yet.

 

Cheers

 

Volker 

 

0 Kudos
Message 13 of 14
(1,842 Views)

Gary S,

 

Your problem is not the last parameter, but with the third last.  DAQmxWriteDigitalLines wants an array of samples.  If you only have one sample, you can try replacing:

 

ctypes.c_uint8(1)

 

with:

 

ctypes.byref(ctypes.c_uint8(1))

 

I think the way to handle it generically would be:

 

numSamples = 1 # or however many samples you want

valArray = (ctypes.c_uint8*numSamples)()

 

valArray[0] = 1

 

nidaq.DAQmxWriteDigitalLines(enable,
                                                   ctypes.c_int32(1),        # numSamplsPerChan
                                                   ctypes.c_int32(1),        # autostart=1
                                                   ctypes.c_double(1),     # timeout
                                                   DAQmx_Val_GroupByChannel,
                                                   ctypes.byref(valArray),        # VALUES TO BE WRITTEN
                                                   ctypes.byref(sampsPerChanWritten),
                                                   null  )

 

0 Kudos
Message 14 of 14
(1,730 Views)