Script Type Function Block: Debugging Tools

Debugging

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.

Real Time Displays

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:

  • Variable Values: Commands that involve setting or evaluating expressions will show you their current values in the Value column. For example, in steps 1 and 2, VSpy is showing that the value of the Transmission Counter application signal is currently 17 (Figure 2:). You can also see this in step 5.

Debugging Tools

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.

Stop and Pause Commands

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.

Breakpoints

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.

Conditional Logic Forcing

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 remove a forcing state, select a step currently being forced, right-click, and choose Remove Force.

Modify Variables

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 48 to any other number.

Last updated