03-03-2009 01:20 PM
I am reading 25 analog input channels through code adapted from sample code I found here and developed in MS Visual Studio 2005 in C++. The created code worked fine but when we integrated it into a larger coding structure, where the program is supposed to begin when a button is pressed, the task creation fails. DAQmxCreateTask does not initialize the task when the program is run and taskHandle comes up as 0x0000000 instead of 0xsome memory location. Can anyone please let me know reasons for why this would happen? The code works on the same computer with the same basic structure (everything after the variable declaration) when it is a stand alone project. Thanks for any help! The code that doesn't work is below (sorry about all the smiley faces, I don't know how to not have them automatically show up).
// C_TangibleSensorPage.cpp : implementation file
//
#include "stdafx.h"
#include "BFMAViewer.h"
#include "C_TangibleSensorPage.h"
TANGIBLESENSOR g_tangiblesensor;
// C_TangibleSensorPage dialog
IMPLEMENT_DYNAMIC(C_TangibleSensorPage, CPropertyPage)
C_TangibleSensorPage::C_TangibleSensorPage()
: CPropertyPage(C_TangibleSensorPage::IDD)
{
}
C_TangibleSensorPage::~C_TangibleSensorPage()
{
}
void C_TangibleSensorPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(C_TangibleSensorPage, CPropertyPage)
ON_BN_CLICKED(IDC_IMU_CONNECT_BUTTON, &C_TangibleSensorPage::OnBnClickedConeConnectButton)
END_MESSAGE_MAP()
// C_TangibleSensorPage message handlers
void C_TangibleSensorPage::OnBnClickedConeConnectButton()
{
int32 error=0;
int32 s=5000;
TaskHandle taskHandle=0;
int32 read;
float64 data[50];
float64 fulldata[25][5000];
char errBuff[2048]={'\0'};
// DAQmx analog voltage channel and timing parameters
(DAQmxCreateTask("",&taskHandle));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai49","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai50","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai51","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai52","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai53","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai54","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai55","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai64","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai65","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai66","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai67","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai68","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai69","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai70","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai71","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai57","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai58","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai59","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai60","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai61","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai62","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai63","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai72","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai73","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai74","",DAQmx_Val_RSE,0,5.0,DAQmx_Val_Volts,NULL));
(DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,10000));
// DAQmx Start Code
(DAQmxStartTask(taskHandle));
// DAQmx Read Code
FILE *OutFile = fopen("aidata.txt","w");
// Stop and clear task
for (int i = 0; i<s; i++)
{
(DAQmxReadAnalogF64(taskHandle,2,10.0,DAQmx_Val_GroupByChannel,data,50,&read,NULL));
for (int j=0; j<25; j++)
{
fulldata[j][i]=data[2*j];
fprintf(OutFile, "%f\t", fulldata[j][i]);
}
fprintf(OutFile,"\n");
}
fclose(OutFile);
DAQmxClearTask(taskHandle);
}
03-03-2009 07:21 PM
mduff,
I can't say off the top of my head why this call would fail. However, all of these DAQmx function calls should return an interger error code. If task handle is NULL, I assume that there is probably an error code being returned which may help you determine your issue.
Dan
03-04-2009 02:00 PM
03-04-2009 07:30 PM
Hi mduff,
Hmm... That seems a bit strange. The one thing that I could think of is that maybe your MAX Database has become corrupt. I've managed to do this myself a couple of times by killing processes with my debugger or doing other "unfriendly" things to my system. Take a look at the following link, "How Do I Recover From MAX Database Corruption."
Please note the steps about backing up your current data. If you create tasks and/or channels in MAX, you will lose these configurations when you perform the steps outlined by the knowledge base I liked to above.
Hope this helps,
Dan
03-05-2009 11:32 AM
03-05-2009 11:43 AM
If it were a MAX database issue, I would expect that it would not work regardless of whether that code was integrated into the larger piece of software or not. I got the impression from your post that the failure to complete the execution of DAQmx Create Task was a new behavior you were observing. That may have been a bad assumption on my part. If the stand-alone code is still working, I would tend to think something else is going on.
Dan