LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to csv to occur after a specific time interval

Solved!
Go to solution

I have created a write to csv file which takes inputs from a controller and records the motion of the controller like pan angle and tilt angle .But i want this recording to be done in everz 2 seconds or time to be defined by the user .Since this write to vi is present inside a while loop (code for the controller operation) I want the 2 second time gap to affect only the write to csv function and not to delay the overall while loop itself.

0 Kudos
Message 1 of 17
(3,750 Views)

You'll need a Producer Consumer architecture. 

The Producer/Consumer architecture is based on a producer loop adding data to a queue and the consumer loop dequeueing the data. The process-intensive or time-hogging code goes in the consumer loop to free up the producer loop to run at the speed you need it to run.

For example, you have code that acquires data every 100ms and needs to write that data to file. It takes 50ms for the acquisition code to run and 80ms for the write-to-file code to run. Uh Oh! You're now taking 130ms per loop and your application is backing up. Now you move the write-to-file code to a consumer loop and enqueue data to it from your producer loop. Voila! Your 50ms code and 80ms code run in parallel and can both keep up with the 100ms period.

More information here.

 

But..... why do you want to delay your write to file?? That doesn't make any sense. Do you mean you want to slow down your acquisition period to 2sec?

 

Please include a Snippet of your code, or attach your VIs, so that we can better assist you. It's easier for us to understand what you're doing if we can see what you've been doing.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 2 of 17
(3,743 Views)

I have attached an image of the portion of the code as the vi is too large and for other reasons cannot be attached.positions of the controller need to be recorded in a csv and the controller values should be recorded after a particular time gap like for e.g after everz 2 sec or so.But if i put a wait until in the wirte to csv it delays the whole loop.So i want to particularly delay the write to csv file part and the whole loops runs at 250ms .

0 Kudos
Message 3 of 17
(3,723 Views)

I told you what to do above. You haven't given any new information.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 17
(3,712 Views)

wel i want to slow the acquisition by 2 seconds ,lets say the controller is at an angle of 20 deg at start to my write to file records that value now it only records the controller value after 2 sec like it was at 20 deg at 0sec and at 21 deg at 1 sec and at 22 deg at 2 sec .So now the next value to be written will be 22 deg .I am not sure about the producer consumer concept it seems to complicate the code (i apologise for my lack of understanding it) .It is possible to implement shift registers where is calculates the 250ms of main loop and for e.g we need the write to wait for 1 sec .so 250 ms x 4 cycles enable write command?

 

please let me know if any other detail is required also if consumer poducer is the way to go about it i shall review it again .

 

thank you

0 Kudos
Message 5 of 17
(3,697 Views)

Hi Raunakbahri,

 

Producer-Consumer is a very basic programming concept, so you really should understand it.

And yes, I also think it's the way to go!

 

Btw. using FormatIntoString would greatly simplify your VI, when it is still like in the image above…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 17
(3,693 Views)

Thank you GerdW and James for your valuable inputs , so i tried to implement the producer consumer logic. My main concern was i did not want 2 parallel loops to be running frankly speaking .Because initially i had implemented the same logic with notifiers aswel but the requirement was to try to have them in the same loop .

anyways , so i tried to implement it and it works fine (note that i have taken pseudo values instead of the actual controller output ). 

I have a doubt lets say i start the main loop at 8.30 and stop it at 8.35 . Will the excel file include the latest value which the controller had at 8.35 ? Or since there is a delay of 3 seconds it stops writing at that very state it is in when the stop is pressed ? 

 

If so how to avoid this ? I mean even if the main loop is stopped the write cycle should complete i.e write all values latest til the time 8.35. I hope i am making sense in this question .

0 Kudos
Message 7 of 17
(3,651 Views)

Sorry, can't open your VI due to it's LabVIEW version…

 

I mean even if the main loop is stopped the write cycle should complete i.e write all values latest til the time 8.35.

General answer: don't stop the consumer loop before all data got written to file…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 17
(3,620 Views)

hey GerdW 

 

I have saved the vi in older version .I am not sure if the vi i have created the wirte cycle is getting completed .Also consumer loop is stopping with the main loop .

0 Kudos
Message 9 of 17
(3,604 Views)

Hi Raunakbahri,

 

your VI has some bad design decisions…

 

- the consumer loop should run as fast as possible: it will use the Dequeue function to wait for new data packets. Never have the consumer run slower (in your case 8 times!) then the producer!

- why is there a sequence frame?

- why is there a case structure in the producer loop?

- use FormatIntoString with a proper format string instead of ConcatenateString!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 17
(3,586 Views)