Function block scripts are programs, and like all programs, occasionally may need to be debugged. The more complicated the script, the more difficult it is to fully understand its behavior, making it more likely that debugging will be required.
Fortunately, Vehicle Spy provides a number of tools to help you debug your scripts. These can be broken down generally into two categories: real-time information displays, and specific debugging tools.
For the purposes of illustration, we will use the example script shown in Figure 1. It transmits three messages (Alpha, Beta and Gamma) in sequence using a counter before repeating. See the comments within the script for more details.
Figure 2 shows the sample script we are using as it appears while running with the script displayed. Several elements of information can be seen here to help you understand what is going on:
Several debugging tools in Vehicle Spy allow you to go beyond observing your script and interact with it directly to better understand what is happening in every step. Here are a few of the available options, several of which are displayed in Figure 3.
The Stop and Pause commands can help you debug by interrupting execution at critical points, and Pause can also display variable values. However, these tools are somewhat inconvenient, as they require actually changing the script.
A breakpoint allows you to tell Vehicle Spy to stop execution at a particular step. To set a breakpoint, select the step where you want to stop, then right-click in the script area to bring
up the context menu
You can have multiple breakpoints in a script. Each time a breakpoint is encountered as the script is run, it is removed and execution stops at the next one.
Script commands that evaluate conditional expressions to decide which commands to execute next (such as If, Else If, Jump If and Wait Until) can have their evaluations forced to either True or False so you can easily test different paths in the code.
To force a command, select it and then bring up the right-click menu, hover over Force, and then choose either Force to Fail (which sets the condition to
False) or Force to Pass (which sets the condition to True). Vehicle Spy indicates that forcing is in effect by highlighting a
Force to Fail in red, as in step 2 of our example
To remove a forcing state, select a step currently being forced, right-click, and choose Remove Force.
You can manually override the values of variables such as signals while your function block script is running, providing full control over how it executes. To do this, first select a step that uses variables. Then either right-click on it and select Modify Variables... from the pop-up menu, or hold down the Ctrl key on your keyboard and double-click the Value cell.
You can change the value of any of the variables in that command by selecting a variable, entering a new value, and then clicking Update as a number or Update as text. This will change the value of the variable "live" as the script is running. For example, if we did this for step 2 in our example script, a dialog box like that in Figure 4 would show up, and we could change the current value of Transmission Counter from 48to any other number.