...
...
...
...
Exercise: Setting
...
an oil change reminder with the Scheduler feature.
Table of Contents | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Scheduler Configuration
Create
...
...
Create 3 different action lists by clicking Tools > Script Editor… > click + icon > Create New Commands > name the first action list “Activate Vending” > click Add New Command, then assign the value “true” to the “Vending” tag > click OK.
...
Repeat this step for the second and third action list called “Activate Washer” and “Activate Light”. Make sure to assign a corresponding tag in the Parameters section
...
...
Create 3 different schedules by clicking Tools > Schedule Editor… > click + icon. Each Schedule Title will be “Activate Vending”, “Activate Washer”, and “Activate Light”.
...
Configure the schedule setup based on the information provided below and make sure to assign a corresponding action in the Action section.
Activate Vending: Start on 2023-03-01 at 07:30 military time and repeat every 1 day.
Activate Washer: Start on 2023-03-22 at 07:45 military time and repeat once a week every Wednesday.
Activate Light: Start on 2023-03-01 at 18:00 military time and repeat once every first day of the month.
...
Create three different text boxes and bind the “Vending”, “Washer”, and “Light” tags to the Text property of their respective text boxes.
...
To observe the operation of the scheduler, adjust the scheduled start date to occur the current date and start times to occur within the next 5 minutes, then run the simulator. At the scheduled start time of their respective schedule, the tag values should display “1”.
...
two tags. One will be named “Oil_Level,” and the other will be named “Oil_consumption.” Oil_Level will be an INT (INT16) with an Initial Value of 50. Oil_consumption will be a BOOL with the starting value as False.
Create a lamp on the page. To create a Switch/Lamp object, go to Insert > Switch/Lamp or left-click the Insert Switch/Lamp icon in the Toolbar. Then, click and drag on the screen to place the lamp. Once the Switch/Lamp object is created, drag the Oil_consumption tag to the Lamp. This will bind the Value field to the Tag Oil_consumption.
Create a Rectangle and a Fillable Rectangle. Create a Rectangle by going to Insert > Rectangle or by left-clicking the Insert Rectangle icon in the Toolbar. Click and drag across the screen to place the Rectangle. While the Rectangle is selected, go to Actions and in the Under Press section, create a new Command. Create a set Tag Value command. Make sure the command will set Oil_Level to 100 when Pressed.To insert the Fillable Rectangle, click on Insert > Fillable Rectangle or by left-clicking the Insert Fillable Rectangle icon in the Toolbar. Click and drag across the screen to place the Fillable Rectangle.
Bind Oil_Level to the Fillable Rectangle. This can be achieved by clicking and holding the Oil_level tag and dragging it into the Fillable Rectangle. This will bind the current level property of the Fillable Rectangle to the Oil_level tag.
Click on Tools > Script Editor. Click the + icon to create a new script; on the popup window, click OK. Copy and paste the following code into the new script:
Code Block |
---|
thread.msleep(500); // sleeps for 500 ms
while(tag.read("Oil_consumption")){ // while Oil_consumption is true
thread.sleep(2); // pauses for 2 seconds
tag.write("Oil_Level", tag.read("Oil_Level") - 1); // deducts 1 from the oil level.
} |
Once pasted in, close the Script Editor by clicking OK. Select the lamp and go to the Actions tab. If Actions does not display, go to View > Properties > Actions and check the box. Under On Press, click the Action field and Create New Command. Click on Add New Command and select Toggle Tag Value. In the Tag field, select the Oil_consumption tag. Then, in the top left of the Command Editor, click the + icon to create a new command. Change the new command to Call Script and select the created script.
Create a new Schedule. To achieve this, go to Tools > Schedule Editor. Click the + to create a new schedule; set the Schedule Title to “Oil_Refill”. Set the Start Date to the current date and the Start Time to 5 minutes from the current time. For example, if the current time is 2:30, the Start Time should be 2:35. Set the schedule to repeat every hour. Click the Action Field > Create New Commands. Create a Send Screen Notification Command; the message for this notification should be “Refill the oil”. Click OK to save and exit, and click OK again to exit the Schedule Editor.