[Tutor] trying to call function in dll
Todd G. Gardner
piir at earthlink.net
Tue Dec 23 20:22:03 EST 2003
Hello all,
/* DLL Function
int32 DAQmxCreateTask (const char taskName[], TaskHandle *taskHandle);
I have installed ctypes-0.6.2a.win32-py2.3.exe.
I am not sure where to start asking questions so I figured I would dive in
and give this a shot. My goal is to be acquire an analog voltage using a
data acquisition card from National Instruments and the python language.
Pardon my ignorance as I am quite the newbie regarding python. Also, I have
done minimal programming in "c". I have done 12 years or programming in
LabVIEW. The card is a PCMCIA DacCard model 6062E. Currently I read this
card using LabVIEW which inturn calls the nidaq32.dll. My newbie questions
start with the dll function "DAQmxCreateTask()" and the following text
details the codes successes and failures that I have been having.
/* This next three lines of python code seem to work however, I am not sure
if the result is correct.
>>> from ctypes import *
>>> ni = windll.nidaq32
>>> print ni
<WinDLL 'nidaq32', handle 21000000 at a90e40>
/* The nidaq32.dll manual shows the syntax to this call as.
/* int32 DAQmxCreateTask (const char taskName[], TaskHandle *taskHandle);
/* This next two lines of python code seem to work...
>>> taskHandle = c_void_p
>>> print taskHandle
<class 'ctypes.c_void_p'>
/* This next line of python code does not work and generates the Traceback
shown.
>>> ptaskHandle = pointer(taskHandle)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in -toplevel-
ptaskHandle = pointer(taskHandle)
File "C:\Python23\Lib\site-packages\ctypes\__init__.py", line 206, in
pointer
return POINTER(type(inst))(inst)
File "C:\Python23\Lib\site-packages\ctypes\__init__.py", line 189, in
POINTER
{'_type_': cls})
TypeError: _type_ must have storage info
>>>
/* This next line of python code generates the Traceback error shown.
/* What syntax should be used?
>>> ni.DAQmxCreateTask("",taskHandle)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
ni.DAQmxCreateTask("",taskHandle)
File "C:\Python23\Lib\site-packages\ctypes\__init__.py", line 250, in
__getattr__
func = self._StdcallFuncPtr(name, self)
AttributeError: function 'DAQmxCreateTask' not found
>>>
/***************************************************
/* FYI: Below, I have copied the "ContAcq-IntClk-AnlgStart_Fn.c" written by
National Instruments(see below).
/* I don't understand all of this function however, I included it to lend
some idea of what actually should be occuring.
/* Every function call starting with "DAQmx..." is a call to a dll function
call.
/***************************************************
#include "NIDAQmx.h"
#include "ContAcq-IntClk-AnlgStart_Fn.h"
// Configures the task.
// Recommended parameters:
// chan = "Dev1/ai0"
// min = -10.0
// max = 10.0
// samplesPerChan = 1000
// rate = 10000.0
// triggerSource = "PFI0"
// triggerSlope = DAQmx_Val_Rising
// triggerLevel = 0.0
int32 Configure_ContAcqIntClkAnlgStart(const char chan[], float64 min,
float64 max, uInt32 samplesPerChan, float64 rate, const char
triggerSource[], uInt32 triggerSlope, float64 triggerLevel, uInt32
*numChannels, TaskHandle *taskHandle)
{
int32 error=0;
/*********************************************************************
* 1. Create a task.
* 2. Create an analog input voltage channel.
* 3. Set the rate for the sample clock. Additionally, define the
* sample mode to be finite.
* 4. Define the parameters for an Analog Slope Start Trigger.
*********************************************************************/
DAQmxErrChk (DAQmxCreateTask("",taskHandle));
DAQmxErrChk
(DAQmxCreateAIVoltageChan(*taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,
DAQmx_Val_Volts,NULL));
DAQmxErrChk
(DAQmxCfgSampClkTiming(*taskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_ContSa
mps,samplesPerChan));
DAQmxErrChk
(DAQmxCfgAnlgEdgeStartTrig(*taskHandle,triggerSource,triggerSlope,triggerLev
el));
if( numChannels )
DAQmxErrChk
(DAQmxGetTaskAttribute(*taskHandle,DAQmx_Task_NumChans,numChannels));
Error:
return error;
}
// Starts the task.
int32 Start_ContAcqIntClkAnlgStart(TaskHandle taskHandle)
{
return DAQmxStartTask(taskHandle);
}
// Reads data into user allocated buffer.
// Recommended parameters:
// bufferSize = 1000
int32 Read_ContAcqIntClkAnlgStart(TaskHandle taskHandle, uInt32
sampsPerChan, float64 data[], uInt32 bufferSize, int32 *read)
{
return
DAQmxReadAnalogF64(taskHandle,sampsPerChan,10.0,DAQmx_Val_GroupByScanNumber,
data,bufferSize,read,NULL);
}
// Stops the task.
int32 Stop_ContAcqIntClkAnlgStart(TaskHandle taskHandle)
{
int32 error=0;
error = DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
return error;
}
/***************************************************************************
*******************************
Any information or ideas would be greatly apprecieted!
Thank you,
Todd
--
Todd Gardner
San Jose, CA
More information about the Tutor
mailing list