LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

timed case structure

Solved!
Go to solution

Hi,

 

I am trying to save analog output from a pressure transducer to a spreadsheet using NI USB-6218 and LabVIEW 2022. The transducer works fine.

I have a case structure inside a while loop. The case structure contains the part where the data is stored to a file.

My goal is to initiate the save operation using a Boolean switch. I want to save the data for 10 seconds, without stopping the while loop, and be able to repeat the process of saving the data (for 10 seconds every time I hit the Boolean switch) until I choose to stop the program.

 

I have tried working with the 'Elapsed Time VI' but I can't seem to make it work for me.

 

Any help would be appreciated.

 

Thanks,

lza

Download All
0 Kudos
Message 1 of 5
(967 Views)

Hi Iza,

 


@laz_2331 wrote:

My goal is to initiate the save operation using a Boolean switch. I want to save the data for 10 seconds, without stopping the while loop,

 

I have tried working with the 'Elapsed Time VI' but I can't seem to make it work for me.


I see two options:

  • Use ElapsedTime and your button to start the timer. Save as long as the time has not elapsed - switch off the AutoReset feature of that ExpressVI…
  • Use a simple shift register to hold a numeric value. When you press the button you write e.g. 100 to the shift register. Save the data when that value is >0 and decrement the value inside the "Save data" case. So you will save for 100 iterations: change this value based on the save duration (10s) and the iteration time of your loop (100ms in my example calculation)…

 

Btw. why are there two attachments with the very same filename, but with different size?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(937 Views)

@GerdW wrote:

 

Btw. why are there two attachments with the very same filename, but with different size?


The smaller one is LabVIEW 2019, the larger 22.3. (Yes, It is typically a very bad idea to use the same file name for different files!)

0 Kudos
Message 3 of 5
(900 Views)

There are several serious flaws, for example having the path control inside would stall the code if the path is invalid.

 

Why are there two stacked case structures all you need is make the "extract data" button latch action and reset the timer if true, then wait for the tome to elapse. 

 

Your bias has a race condition because if will only apply to the next iteration, not the current because of glaring misuse of a local variable.

 

Of course you also need to decide how to handle exceptions, for example what should happen if the users presses save again while it is already saving, etc.

0 Kudos
Message 4 of 5
(895 Views)
Solution
Accepted by topic author laz_2331

See if this can give you some ideas....

 

(You should use low-level file IO to keep the file open. "Write to spreadsheet file" will open and close the file with each call for significantly more overhead. Not sure of the bias control should be latch or switch action)

 

altenbach_0-1695232517440.png

 

Message 5 of 5
(887 Views)