LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I implement "for loop" in my code below?

Solved!
Go to solution

NOTE: 

I have attached my well documented code. Hopefully, it will give me a pass for a good code.

Note: The code is running as I am expecting it to run; I just want to figure out how to implement for loop to simplify my code just in case I want more duplications later. I have tried but failed miserably.

 

Quick explanation of what I am doing:

 

I am supplying 3 volts and 2 volts to 2 of my tests (the goal is to have more than 2 tests later). The two tests are not running sequentially. The supply between 3V and 2V are being done alternatively. I have relays to switch between these two voltages (3V and 2V). Each test will have adjustable test duration (time). Also, 3 Volts supply time will be adjustable.

 

Here is the math:

For example, for  Test 1 I set the test duration time to 24 hours, then I set the 3 volts supply time to 1 hour.

So 24 hour – 1 hour = 23 hours >> time for 2 volts supply.

So in the period of 24 hours, 3 volts will be supplied for 1 hour and 2 volts will be supplied for 23 hours (the remaining hour).

Note: I am only adjusting time for the 3 volts supply and test duration.

So test duration and 3 V supply time are not always always 24hr and 1hr respectively. They can vary.

 

If "for loop" cannot be implemented, please let me know also. 

0 Kudos
Message 1 of 9
(1,615 Views)

Hi GRCK,

 


@GRCK5000 wrote:

I just want to figure out how to implement for loop to simplify my code just in case I want more duplications later.


Why do you think a FOR loop would simplify this VI?

 

You may simplifiy your VI by replacing those HH, MM, SS controls by a single numeric DBL control and set it's format to <HH:MM:SS> (and maybe limiting its valid input range): no need for math to calculate number of seconds from 3 inputs…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(1,599 Views)

Hi GerdW,

 

Thanks for the input. I've always thought "for loop" can also be used to prevent duplication. 

0 Kudos
Message 3 of 9
(1,593 Views)

@GerdW wrote:

Hi GRCK,

 


@GRCK5000 wrote:

 


 

You may simplifiy your VI by replacing those HH, MM, SS controls by a single numeric DBL control and set it's format to <HH:MM:SS> (and maybe limiting its valid input range): no need for math to calculate number of seconds from 3 inputs…


I agree that your timing inputs need work.

The format code is actually:

%<%H:%M:%S>t

(I will have to try and remember this... again. 😁 )

 

Frozen_0-1676647199271.png

 

 

You can further simply by only having one case statement.

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
Message 4 of 9
(1,580 Views)
Solution
Accepted by topic author GRCK5000

If you are familiar with array and cluster manipulation, you can get it done pretty easily. See the attachment for the modified code. You could Enabling Parallel For Loop Iterations as well.

-------------------------------------------------------
Applications Engineer | TME Systems
Message 5 of 9
(1,568 Views)

WOW. This is cool. Thanks a lot! I didn't know about this.

0 Kudos
Message 6 of 9
(1,559 Views)

WOW Zyong! You nailed it. Thanks a lot!!!! This is exactly what I'm talking about and thanks for the information.

0 Kudos
Message 7 of 9
(1,539 Views)

There is still huge room for improvements. For example if each case gets the time, that belongs before the case.

 

Here's a quick rewrite. You can image how the other cases look like. 😄

 

 

altenbach_0-1676651576680.png

 

(An yes, there is no need for absolute time if we are only interested relative times. (e.g. high resolution relative seconds would work). Once you use plain DBLs as time input (in relative time format), here's how it would simplify to.

 

altenbach_1-1676651980836.png

 

Message 8 of 9
(1,522 Views)

Thanks Mr. Altenbach! I can definitely figure out what the other cases look like. 

0 Kudos
Message 9 of 9
(1,488 Views)