Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize on restart of task

I'll outline what I need to do and hopefully someone can tell me how to best tackle it. A code example would be best if possible.

 

I have an application that will always be reading data on analog inputs (specifically strain on 4331 cards), but not always writing output data (on 6733 cards). However, when voltage is being output, I need it synchronized with start of my AI reads. I can synchornize them by using the start trigger when my application is first started up. But, if I stop my AO task, then restart it, I need it to synch back up to the AI. I figure I may be able to use a counter to do this but I'm not sure how.

 

So, to clarify with an example: Analog input and output tasks will be synchronized. The analog output task will be stopped but the AI task keeps reading. At some point in the future, the AO task restarts, but it shouldn't start outputting data until I get to the beginning of an AI read. So, if I am continuously reading 1000 AI samples from the buffer, but my AI task is currently reading sample number 500 out of 1,000 (i.e. only halfway done with a read) and my AO task restarts, the AO task shouldn't start outputting data until all 1,000 samples have been read by my AI task.

0 Kudos
Message 1 of 2
(5,508 Views)

@for(imstuck) wrote:

I'll outline what I need to do and hopefully someone can tell me how to best tackle it. A code example would be best if possible.

 

I have an application that will always be reading data on analog inputs (specifically strain on 4331 cards), but not always writing output data (on 6733 cards). However, when voltage is being output, I need it synchronized with start of my AI reads. I can synchornize them by using the start trigger when my application is first started up. But, if I stop my AO task, then restart it, I need it to synch back up to the AI. I figure I may be able to use a counter to do this but I'm not sure how.

 

So, to clarify with an example: Analog input and output tasks will be synchronized. The analog output task will be stopped but the AI task keeps reading. At some point in the future, the AO task restarts, but it shouldn't start outputting data until I get to the beginning of an AI read. So, if I am continuously reading 1000 AI samples from the buffer, but my AI task is currently reading sample number 500 out of 1,000 (i.e. only halfway done with a read) and my AO task restarts, the AO task shouldn't start outputting data until all 1,000 samples have been read by my AI task.


My have solved this: have a counter task output a counter at the rate I want to read from the buffer (say 1hz). Use that as the start trigger. It seems to work but when I stop then restart the output task I get this error: Some or all of the samples to write could not be written to the buffer yet. More space will free up as samples currently in the buffer are generated.

 

This is odd to me because the configuration works fine initially; it's only after I stop and then restart (without reconfiguring but as far as I understand it, the configuration should remain).

 

Edit: I had to preinitialize the buffer with output data before restarting the task. Error then went away.

0 Kudos
Message 2 of 2
(5,503 Views)