Developer Blog

15/09/2015 by Magnus Carlsson

Kvaser TRX and Environment Variables (3 of 3)

This is the last post in a 3-part series about Environment Variables in t programs:

  1. Introduction to Environment Variables
  2. Accessing Environment Variables from CANlib
  3. Kvaser TRX and Environment Variables

In this last part of the environment variable series, we’ll see how we can interact with environment variables using the Kvaser TRX. Kvaser TRX is a light weight IDE for developing t programs for Kvaser devices and is included in the CANlib SDK 1. Full program listings are available on

First we connect a device that is capable of running t programs to the PC, I will be using a Kvaser Eagle. Now we start Kvaser TRX and open the t program we created in the first post of this series, envvar.t. We do this by selecting File->Open, then browse for the file, select the file, and click “Open”.

can networking

Figure 1: Kvaser TRX is started, we have an Eagle connected to the PC and the file envvar.t is loaded.

The next step is to Compile, Download and Run the t program. A quick way of doing this is to push the play button on the Kvaser TRX toolbar. A pop-up will ask you to save your new project. Just accept the default name and click “Save”.

The t program will now start, indicated by the message “Script no 0 started. proc=0” in the Device Output part of the lower pane. After the simulated boot delay, a new message will appear, “Signal that we are ready to accept connections”, see Figure 2.

can bus system

Figure 2: The t program has been started and we can see print outs in the Device Output tab of Kvaser TRX.

To view an environment variable, we first open up the Envvar window by selecting Window->Toggle Envvar Window from the menu. In the Envvar Window we enter the name of the environment variable we would like to view, and click “Add Envvar” as shown in Figure 3.

can networking

Figure 3: Adding the environment variable HostIdConnected to the Envvar Window in Kvaser TRX.

If we would like to see the value of the environment variables updated regularly in the Envvar window, we can tick the “Auto Refresh” check box. Having “Auto Refresh”, enabled we can now restart the t program (Select Run->Stop and then Run->Start) and observe that the value of HostIdConnected is 1 at the start of the t program and switches to 0 at the same time as the message “Signal that we are ready to accept connections.” is printed. This is just as we expected, see the t program listing for details.

Now we add two more environment variables, Severity and Message, in the same way as we just have added the environment variable HostIdConnected.

When an environment variable is selected, a status row is showed where the Name, Type and Value is shown. The value box is labeled “New Value” which hints that you can enter a new value here and then click “Set Value” to update the value of the selected environment variable, see Figure 4.

The status row also shows a button named “Remove” which can be used to remove the selected environment variable from the Envvar window.

can bus system

Figure 4: Setting a new value to the environment variable Message in the Envvar Window of Kvaser TRX.

Change the value of Message to ‘My Message’ and click “Set Value”. Beside that the value is updated in the Envvar window, we also see that the running t program catches this change and writes “Severity: 0 -My message” at the console in the the lower pane of the Kvaser TRX window.

You can also try and change the severity. The change will be updated in the Envvar window, but since we do not have any hook for this environment variable in our t program, nothing will happen in the console area.

As an excersise, try and change the value of the environment variable HostIdConnected. Why does the Envvar window not show the new value? A hint is to take a look at the on envvar hook for HostIdConnected

This ends this series about environment variables in t programs, hope you have enjoyed it. If you have any comments, contact us at


1 More about the CANlib SDK can be found at

Author Image

Magnus Carlsson

Magnus Carlsson is a Software Developer for Kvaser AB and has developed firmware and software for Kvaser products since 2007. He has also written a number of articles for Kvaser’s Developer Blog dealing with the popular Python language.