LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to control the amount of times an email is sent inside a while loop

Solved!
Go to solution

I´m creating an irrigation system and I want labview to send an email when the value a humidity sensor reads exceeds the value of humidity that a crop can endure. The email is sent when this happens, but the problem is that since the case structure is inside a while loop, an email is sent every 1000ms and I don´t want to have that many notifications. Is there a way to control how many times the email is sent or how long to wait between sending emails if the case remains true?

0 Kudos
Message 1 of 9
(1,209 Views)
Solution
Accepted by topic author NataliaB14

Create an "elapsed time" VI that works like a stopwatch. If you want your time since last email to be more than n seconds, your logic is:

if humidity > threshold and elapsed time > n then send an email.

 

Whenever you send the email, make sure to reset elapsed time back to 0.

Message 2 of 9
(1,204 Views)

Hi NataliaB14,

 

Yes, what you are asking is achievable. 

Can you share the flow of your program? For example: first step: create text file using config VIs >> what is your next step and so on?

Once you share he flow of what you are trying to achieve, I will knock this out with a nice state machine and  and your problem will be solved. 

I look forward to hearing from you. 

But I would recommend that you learn about state machine producer consumer architecture. It will help you achieve a lot. It's very powerful. 

I'm waiting for the flow diagram or just a flow of your program so I can get to work. 

I look forward to hearing from you.

 

 

P.S.: Your code will look different, but the functionality will remain But no worries, I will comment so you can better understand it.

Thanks,

 

Grck5000

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

Hi NataliaB14,

 

I modified your code. Give it a try and let me know if it works for you. 

0 Kudos
Message 4 of 9
(1,113 Views)

@GRCK5000 wrote:

Hi NataliaB14,

 

I modified your code. Give it a try and let me know if it works for you. 


I don't think VISA Read is time critical, so it can be achieved just with Loop, You can poll for VISA Read and Sent email whenever is its applicable.

 

Read Config file should be done at the initial state of the application not every time (Applicable for both initial and modified codes.

In what way your code works different from NataliaB14 Code because in both case it tried to send the Email whenever it satisfies the condition (Only Difference is Case where it updates).

 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 9
(1,098 Views)

Thank you!

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

Thank you so much 🙂 ! I got it to work with Gregory´s idea and I didn´t have to change much of my code

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

Oh no! I wasted my time 😢. No need to answer questions for me, I guess. I will be quiet from now on.  😂 

Kudos to you, Greg!!! 👍👏

0 Kudos
Message 8 of 9
(1,070 Views)

Thanks @PalanivelThiruvenkadam               

 

 

Good to know that visa read is not time critical. See, I learned something today 😃

P.S.: The only difference between her code and mine is that I am using a state machine.  Architecture matters!!! It's very helpful. I used to code like she is doing which is good as long as everything is working fine. As time goes on, I starts to think, having a good architecture is very important too,  especially if you want your code to look professional. Assume you have a code review in front of other great labVIEW programmers and you have a large code with wires running left and right, no comments. Trust me they might get to you, you won't leave your presentation room without them mentioning that to you. 

So how your code looks #architecture matters. I think it's also beneficial for yourself as well as other programmers to understand your code. 

 

This is just something that I am learning and I thought I would share. 

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