An event in V-Control works as a trigger. If the event occurs, a defined task is executed as event handler. All events are triggered by a variable change. This could be a device variable, a system variable or a global variable.
The device drivers collect information about the connected device and represent the status of the device in device variables. Each time a variable changes an event is fired. If there is an event handler for this event then the task that handles the event is fired. Device Events allow V-Control to respond on external events triggered by a connected device. If, for example, a temperature sensor send a message that a limit is reached, or a motion sensor detects a person and notify this, or a players position has changed, V-Control can launch a task and react on this event.
To trigger an event, a condition script determines if the event handling task is fired or not. Lets say we have a temperature sensor and we want to start a fan if the temperature is over 35°C. The fan should stop if the temperature is less then 30°C. So we have two conditions to check and determine which task to start.
Condition 1 is: if Temperature > 35 then start fan Condition 2 is: if Temperature < 30 then stop fan
These events initiated by the external attached devices, e.g. a liquid level sensor reports a new level or a light barrier detects a break. The sensor send a message via the channel (or the device driver requests the status periodically), and V-Control looks if there is an event handler. If an event handler is found, it checks the condition and fire the task if the condition is true.
The ioLogic E1214 is a TCP controlled box from Moxa. It uses the Modbus TCP protocol. It has 6 Relays and 6 digital inputs.Now we want to run a task if digital input 1 gets High. Select the device and the device variable D0Status. Then click the Create Condition Template button. V-Control creates a condition script that has to be edited so that the condition is true if D0Status = 1.
The first line of the condition script is a comment. It is shown in the Eventlist and is used as a hint for the programmer. Change the condition script as shown below.
Click the Add Event button. Now there is a new entry in the Eventlist. The next step is to assign a task to this event. In the context menu (click right) of the event list select Assign Task. The list now looks like this:
Now, if the variable D0Status of the device changes from 0 to 1, the task assigned to the event is fired.
The first row of the condition script is a comment and shown in the Eventlist. Write whatever is helpful to have a good hint what the script is doing.
The second row
Dim D0Status as String
creates the local variable D0Status. This is necessary because we don't have direct access to a device variable.
D0Status = GetDeviceVar("ioLogic_E1214_v4","D0Status")
the content of the device variable D0Status is assigned to the local variable D0Status. The GetDeviceVar function accept only strings as parameters, so the device name and the variable name have to be surrounded by “.
The last row checks if the condition is true. The condition is always false by default and changes only to true if explicit set.
If D0Status = "1" then Condition = true
The Condition Editor tries to support the programmer in creating the script. As explained above, the Create Condition Template button creates a script that is used as first step.
Variable change events can occur from device variables and global variables. If then Use Device Variable option is set, a device variable is used. For global variables use the Use Global Variable option.
Device variables can change very frequently. A variable containing a timecode changes every 33 ms (30 fps). If you have a condition such as
Dim Positionas string Dim iPosition,iTarget as Integer Position = GetDeviceVar("DVS_Pronto","Position" iTarget = TimecodeToFramecode("10-12-21-10") iPosition = TimecodeToFramecode(Position) if (iPosition >= iTarget) and (iPosition < Target +10) then Condition = true
This script returns true if the Position is between 10-12-21-10 and 10-12-21-20. It might be that V-Control does not detect all of the 10 valid variable changes, but for sure more then one. In this case the Task that is linked to the event is fired frequently during this period. It could happen that V-Control tries to fire the task again while it is still running. For that reason we have the After fired block for ms. Here you can enter the time in ms the event should not fire again. After the time it will fire again. This value is 1000ms (1 Second) by default.
If your script causes compile errors the line with the error is marked in the script and an error message is shown (Compiler Message).
A double click in the eventlist loads the event again. To change the event click the Update Event button, to create a new click the Add Event button.
To create events that depend on a Date, Time or Time interval the System device is used. To add a System device open the Device Setup dialog by clicking the Device button in the toolbar. Search for System_v4.
The System Device is the only device that does not need a channel. It has no commands, only status variables representing Date and Time. The Time is in the format HH:MM:SS:FF (FF = Frames). The framerate is determined in the Options Dialog System page.
DayOfWeek is the current weekday (1=Sunday..7=Saturday)
To create an event that fires weekdays at 9:00 AM we have to check the current Time and the DayOfWeek. Because the DayOfWeekVariable changes only every 24 hours, we use the CurrentTime variable as trigger.
Select the CurrentTime variable, select the Events tab and pres the Create Condition Template button.
Change the Template to
//If CurrentTime = "09:00:00 " and DayOfWeek >1 and < 7 then Condition = true Dim CurrentTime as String CurrentTime = GetDeviceVar("System_v4","CurrentTime") //ignore frames, analyse the part "HH:MM:SS" only If Mid(CurrentTime,1,8) = "09:00:00" then Dim DayOfWeek as Variant DayOfWeek = GetDeviceVar("System_v4","DayOfWeek") if DayOfWeek >1 and DayOfWeek < 7 then condition = true end
Maybe one is wondering about Dim DayOfWeek as Variant. If DayOfWeek was declared as string, then an operation such as if DayOfWeek > 1 would couse a compile error, because a string cannot be compared with an integer. A variant behaves as string if the content is a string, or as integer if the content can be converted to integer. So the string “1” can be converted to the integer 1. This happens automatically.
Now the event is fired 25 Times (from “09:00:00:00” - “09:00:00:24” at 25 fps). Because we want to ensure that the event is only fired ocne, set the After fired block for ms to 2000 ms. Now press the Add Event Button
Finally, after assigning a task to the event, the result is