Lately we've received some questions about one of the key concerns in control: controlling something at a specific point in time.
- Maybe you want to turn on a pump at 6:00 a.m. every day
- Or start a process on Tuesday
- Or restart a count at midnight on the last day of each month
This tip pulls together some resources for control based on time, day, and date.
Synchronizing time
Did you know there's a giant clock in the sky—er, cloud—that computers can look at to know what time it is?
Well, in a way. In the U.S., for example, the National Institute of Standards and Technology (NIST) provides time servers you can access using the Network Time Protocol (NTP) or Simple Network Time Protocol (SNTP) to synchronize the clock on your computer or controller with a recognized source.
Ben explains how to do this in his recent blog post, How to set the clock on a PAC Controller.
Time and Date commands in PAC Control
When you build a control strategy in PAC Control, you have many time and date commands to help you.
You can Get (read) or Set (write) Seconds, Minutes, Hours, Day, Month, and Year. You can work with time zones and time protocols and copy dates and times to strings. And more. For complete information on each command, see the "Time/Date Commands" chapter in the PAC Control Command Reference, form 1701. Or when you're in PAC Control, click the Command Help button in the Add Instruction dialog box.
Tip for accuracy: If you need to read more than one element of time from the controller (for example, seconds, minutes, and hours), the command Get Date and Time is your best choice. It's easier and more accurate than getting individual elements separately.
Tip for simplicity: Another useful and surprisingly powerful Time/Date command is Get Seconds Since Midnight. Ben's Seconds since Midnight blog post shows you how to turn on that pump at 6:00 a.m. in both OptoScript and flowchart blocks. He also has some solid advice for using time in your user interface, so be sure to check that out.
A recent OptoForum thread walked a newbie through making decisions based on schedule/time. That thread contains short code examples and related tips as well.
More sample code
In addition to the blog posts and forum thread already mentioned, you'll find sample code for using Time and Date commands here:
OptoForums:
Don't forget to post your questions and your sample code on the OptoForum.
Enjoy your time!