04-13-2023 05:03 PM
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?
Solved! Go to Solution.
04-13-2023 05:09 PM
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.
04-15-2023 12:41 AM - edited 04-15-2023 01:12 AM
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
04-15-2023 03:21 PM
Hi NataliaB14,
I modified your code. Give it a try and let me know if it works for you.
04-15-2023 04:46 PM - edited 04-15-2023 04:47 PM
@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).
04-15-2023 05:20 PM
Thank you!
04-15-2023 05:24 PM
Thank you so much 🙂 ! I got it to work with Gregory´s idea and I didn´t have to change much of my code
04-15-2023 06:44 PM - edited 04-15-2023 06:45 PM
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!!! 👍👏
04-16-2023 01:49 PM - edited 04-16-2023 02:08 PM
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.