Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Start task on trigger

Hi,

I'm developping a c++ project using DAQmx. I use the NI PCI 6534 card and trying to start a digital output task when i get a bit from /dev1/port2/line0. So i suppose i have to use a trigger but i m not sure about how to use trigger functions. 

Someone could help me on their use?

 

Thank you.

 

Here is what i tried to do but doesn t work (Error terminal for this device invalid ) : 

 

int daqmxSendData(uInt8 data[], int size){

 

int error=0;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/line0:15","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgBurstHandshakingTimingExportClock(taskHandle,DAQmx_Val_ContSamps,size,1000.0,"/Dev1/PFI4",DAQmx_Val_ActiveHigh,DAQmx_Val_High,DAQmx_Val_ActiveLow));




DAQmxErrChk (DAQmxSetPauseTrigType(taskHandle,DAQmx_Val_DigLvl));
DAQmxErrChk (DAQmxSetDigLvlPauseTrigSrc(taskHandle,"/Dev1/port2/line0"));
DAQmxErrChk (DAQmxSetDigLvlPauseTrigWhen(taskHandle,DAQmx_Val_High));

 


DAQmxErrChk (DAQmxSetWriteRegenMode(taskHandle,DAQmx_Val_AllowRegen));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,size,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

 

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

printf("Generating digital output continuously. Press Enter to interrupt\n");
getchar();

Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
return 0;
}

0 Kudos
Message 1 of 4
(6,066 Views)

Hello,

 

If you have a look on the function help, you will find out your answer.

Actually, I think you should use this fonction :

 

"Configures the task to start acquiring or generating samples on a rising or falling edge of a digital signal.

 

Prototype

int32 DAQmxCfgDigEdgeStartTrig (TaskHandle Task_Handle, char Trigger_Source[], int32 Trigger_Edge);"

 

These information comes from the help document!

 

Regards,

Celine
National Instruments France

0 Kudos
Message 2 of 4
(6,053 Views)

Ok Thank you for your reply.

 

So i tried to use your function. But i get an error while using it.

 

triggerDAQmx Error: Start Trigger Type requested is not supported given the requested Timing Type.

To use the requested Timing Type, do not set the Start Trigger Type property. NI-DAQmx automatically selects a compatible Start Trigger Type setting.

To use the requested Start Trigger Type, select a different Timing Type.
Property: DAQmx_SampTimingType
Requested Value: DAQmx_Val_BurstHandshake

Property: DAQmx_StartTrig_Type
Requested Value: DAQmx_Val_DigEdge

Task Name: _unnamedTask<0>

Status Code: -200904

 

 

Apparently i can't use :

 

DAQmxCfgDigEdgeStartTrig (taskHandle, "/Dev1/line0" , DAQmx_Val_Rising);

 

with :

 

DAQmxCfgBurstHandshakingTimingExportClock(taskHandle,DAQmx_Val_ContSamps,size,1000.0,"/Dev1/PFI4",DAQmx_Val_ActiveHigh,DAQmx_Val_High,DAQmx_Val_ActiveHigh)

 

 

I've changed my code and replace DAQmxCfgBurstHandshakingTimingExportClock with DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI2",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,size));

 

and now i can use  DAQmxCfgDigEdgeStartTrig (taskHandle, "/Dev1/line0" , DAQmx_Val_Rising); but still got an error with the line i want to use for the trigger.

 

triggerDAQmx Error: Terminal for the device is invalid.
Property: DAQmx_DigEdge_StartTrig_Src
Requested Value: /Dev1/line0

Task Name: _unnamedTask<0>

Status Code: -89129

 

 

 

 

Any idea?

 

Thank you.

Alex.

0 Kudos
Message 3 of 4
(6,047 Views)

I'm still stuck with this function. 

I think that I understood that a trigger can t be configure on a Digital output line like i did above. But my function have to generate data on lines 0:15 and be able to read on line 16:31 to get trigger info.

So i found that we can tristate line to be able to change input/output lines and so now, I m trying to use a pattern trigger on line 16:31 but I still can't make it works.

Thank you for any help.

Alex.

 

my code:

 

int daqmxSendData(uInt8 data[], int size, int mode){
int error=0;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};
int32 read,bytesPerSamp;
/*********************************************/
// DAQmx Configure Code
/*********************************************/


DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/line0:31","",DAQmx_Val_ChanForAllLines));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,size));


DAQmxErrChk (DAQmxSetWriteRegenMode(taskHandle,DAQmx_Val_AllowRegen));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,size,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));


if(mode == 1){
printf("trigger");



DAQmxErrChk ( DAQmxSetDOTristate(taskHandle,"/Dev1/line16:31",1));

DAQmxErrChk (DAQmxCfgDigPatternStartTrig (taskHandle, "/Dev1/line16:31","1000000000000000" , DAQmx_Val_PatternMatches));

}




/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));


printf("Generating digital output continuously. Press Enter to interrupt\n");
getchar();


Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
return 0;
}

0 Kudos
Message 4 of 4
(6,025 Views)