Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadCounterF64() timeouts blocking program runtime

Hi,

 


I have a PCI-7342 board connected to a MID-7652 box that is being used to control a servo motor on a rotary axis with an encoder. I also have a PCIe-6323 board that is used to read a quadrature linear encoder on the counter using DAQmx and I am programming in C. As the axis rotates, it passes breakpoints and sends a trigger signal in order for the counter to latch a reading from the quadrature encoder. I have also posted this in the Counter/Timer message boards.

 

 

The DAQmx is set up using the following functions:
     DAQmxCreateTask(, &thHandle);
     DAQmxCreateCILinEncoderChan(thHandle, "Dev1/ctr0", , , , , , , , , );
     DAQmxCfgSampClkTiming(thHandle, "/Dev1/PFI0", , , , );
     DAQmxStartTask(thHandle);

 

This sets up the counter to be latched every time a signal arrives at the PFI0 terminal. I have connected the breakpoint output from the MID-7652 box to PFI0.

 


The rotary axis is configured with modulo breakpoints using the following functions:
     flex_configure_breakpoint(, , NIMC_MODULO_BREAKPOINT, NIMC_RESET_BREAKPOINT, );
     flex_load_bp_modulus(, , 250, );
     flex_load_pos_bp(, , 0, );
     flex_enable_breakpoint(, , NIMC_TRUE);

 

Due to modulo breakpoints, I have to call flex_enable_breakpoint(, , NIMC_TRUE); every time a breakpoint occurs in order for the next breakpoint to be able to trigger.

 


The problem I have lies in the next stage. I want to call the read function which will wait for incoming trigger on PFI0. So I call the function:
     DAQmxReadCounterF64(thHandle, -1, dTimeOut, , , , );

 

Next in my code I start the motion of the rotary axis
     flex_start(, , );
     do
     {
          flex_read_axis_status_rtn(, , &usAxisStatus);
          usBPStatus = !((usAxisStatus & NIMC_POS_BREAKPOINT_BIT)==0);
          if (usBPStatus)
          {
               flex_enable_breakpoint(, , NIMC_TRUE);
          }
} while ( !(usAxisStatus & (NIMC_MOVE_COMPLETE_BIT | NIMC_AXIS_OFF_BIT )));

 

But this line is never reached because the DAQmxReadCounterF64() function keeps waiting for an input at the PFI0 terminal and blocks the program from running and times out, returning an error.

I have tried rearranging the order of the functions by calling flex_start(); first and then DAQmxReadCounterF64() before the do-while loop.
The problem with this method is that the DAQmxReadCounterF64() function blocks the runtime and so the second breakpoint is never enabled. The function again times out and returns an error.


I don't want to set it to indefinite or my program will wait forever and not do anything. Is there a way around the DAQmxReadCounterF64() timeout? Or a way to re-enable the breakpoints?

0 Kudos
Message 1 of 5
(4,218 Views)

Hi BonaBona,

 

Thank you for your question!

 

According to the "DAQmxReadCounterF64" function help it has the following parameters:

 

int32 DAQmxReadCounterF64(TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, float64 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);

 

Have you tried to set timeout to something other than "-1"? If timeout is set to "-1" this function will wait indefinitely.

 

Kind Regards,

0 Kudos
Message 2 of 5
(4,200 Views)

Yes I have tried setting it to 20 seconds. Unfortunately this means that nothing happens for 20 seconds then I get a timeout error.

0 Kudos
Message 3 of 5
(4,195 Views)

Assuming a finite counter input task, by default reading -1 samples will read the number of samples configured in the task (configured by DAQmxCfgSampClkTiming).  If those samples are not yet available, the read will block until they are (or until the configured timeout is reached).

 

It's not clear what behavior you are looking for, but here are some things one might do to prevent this from being an issue:

 

1.  Only call the read when you have already acquired the data you will be asking for.

a)  Event (DAQmxRegisterEveryNSamplesEvent or DAQmxRegisterDoneEvent)

b)  Polling (DAQmxGetReadAvailSampPerChan)

 

2.  Rather than reading a specific number of samples, read whatever is currently in the buffer (DAQmxSetReadReadAllAvailSamp)

 

3.  Decrease your timeout to something tolerable (i.e. less than 20 seconds) and handle the timeout error.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 5
(4,183 Views)

Sorry if I haven't been clear. What I want to achieve is that the value on the linear encoder is latched into the read buffer whenever an input trigger pulse is received at PFI0. I am looking to latch a finite number of readings.

 

Thanks for the suggestions. I will certainly try the second one. The third one will not work on my system as I will only get a timeout error each time.

0 Kudos
Message 5 of 5
(4,138 Views)