<< Click to Display Table of Contents >> Complex flashing with scripts |
|
Let's assume that in our project we have many Motor objects of the same type, each of which has several State and Speed parameters, and depending on their values, we want the objects (Motor) to flash/not flash on the screen. Since in this case there is a dependence of flashing on several tags, it is necessary to use scripts. And since we have several objects of the same type in our project, it is more convenient to use indirect names to bind tags to an object.
1. First, let’s create tags for each object - State and Speed (we’ll arrange them as a group):
2. In this case, we need intermediate tags to enable or disable the flashing of an object. - Flash1, Flash2 and Flash3, let's create them:
3. Let’s create a graphical Motor object for our example:
In the Object properties in the "General" tab, create a user-defined property "Number" and set its value "1", because we will bind this object to the Flash1 tag:
4. Close the "Collections" window and click "OK" in the Object Properties Window to save the changes. Now let’s open the Object Properties again and configure the Flash property: bind the tag by specifying the indirect name: Flash{Number}:
5. Depending on the tag values for each Motor object, we will use the frequency:
State |
Speed |
Flash frequency |
---|---|---|
0 |
Any |
Not flashing |
1 |
0...500 |
1000 |
1 |
500...1000 |
500 |
1 |
>1000 |
250 |
6. Let's create a script for an object in the ST language with the execution type - OnDataChange:
Let's write a script:
After you have recorded the script, be sure to launch it by clicking the button on the toolbar:
7. Now let’s bind the script to the object - open the properties of the object, select the “Main” tab and fill in the “Collection” in the “Scripts” field:
So, we have a Motor with the Flash property set according to the script.
8. Now we need to duplicate the created Motor object as many times as needed in the project, and in each newly created object correct the value of the user-defined property "Number" ((most quickly, on the Property Sheet):
9. Let's Run simulation to check the settings:
You can download this project here.