09-17-2024 02:30 AM
I have created a scheduler to turn on a pump for a certain time, three times daily. The VI is working, at least over a weekend period. At present the pump is only pseudo turned on for testing. My problem is, the user enters just the three times but not the date. The date is checked and changed accordingly, if the time has passed, to the next day after the current day.
I realise that polling the current time continuously is maybe not the best way as the CPU will be busy but that is not a problem as the PC is dedicated to just this task.
When I run the VI for the first time, the remaining time till next "on" is a minus value. If I stop the VI and run again, it is correct. Can anyone see where I have made a mistake.
Many thanks.
Mark
Solved! Go to Solution.
09-17-2024 03:13 AM - edited 09-17-2024 03:14 AM
Hi vtiu,
@vtiu wrote:
Can anyone see where I have made a mistake.
Your timestamp math is way too complicated!
See this:
I recommend to cleanup and simplify the other code too…
09-17-2024 04:36 AM
Thank you for your input. That makes things a lot easier.
I also had to set a default value in the time 1 to 3 where the seconds were 0. I didn't notice that they were fixed at 57. Now the countdown time remaining fits better with the actual time.
The timestamp math in the while loop is also simplier. Why simple when you can be complicated 🤔
The finished version is attatched as a new VI. I have to remember why the changes were made.
Regards
Mark.
09-17-2024 05:37 AM
Hi vtiu,
@vtiu wrote:
The timestamp math in the while loop is also simplier. Why simple when you can be complicated 🤔
More simplifications:
@vtiu wrote:
I have to remember why the changes were made.
This is where you place your comments when you commit your new code to your code repository!
You use a code revision tool, do you?
(Or when you place comments in the code.)
09-17-2024 10:05 AM
In addition to what has been said, there is quite a bit of code smell here.
All you really need is a proper state machine, one toplevel loop running at a reasonable rate and defined states and transitions based on time and state.