Let’s take a quick look at the CAN gateway database file that we’ve provided for you for this example.
There are two CAN messages defined, Ecu1 and Ecu2. In each of these messages there’s several signals. What we’re going to do is, when channel 1 sees a message coming from Ecu1, we’re going to extract some signals in Ecu1, take those values and attach them to a CanMessage of Ecu2 and send it on CAN channel 2.
Let’s jump into TRX and I’ll show you how it works. Here’s our existing CAN gateway t script. Let’s begin by adding a CAN database file to our project by right clicking our project to the right, adding a database, select the database that we’ve provided for you, and you can see that it’s been added to our project. And we can reference the Ecu’s or any of the messages by referring to them as CanMessage underscore message name (CanMessage_ECU2). So we’re gonna go ahead and create a variable for Ecu2, we’re gonna call it Ecu2, lowercase ecu2.
So when we get ECU1 message on CAN channel 1, then we want to jump into this block. What we’re going to have to do is put prefilter, Â so when you use a CanMessage from a database file, when you reference a database file you must use the prefilter before CanMessage.
Kvaser Tip
The prefilter can only be use in message hooks when using the datalogger hardware. Adding the prefilter keyword to your message hook causes the hook code to be evaluated before any of the trigger conditions defined in the datalogger’s configuration.
Go ahead and erase our previous video for actions and will say ecu2.Switch1.Raw, Â so this is a raw format of that signal equals (=) this.Ecu1_Switch1.Raw.
So what we’re doing here is we’re referencing with this, we’re referencing the CanMessage that we just got ECU1, we’re taking the signal Ecu1_switch1 signal, the raw format, and we’re applying it to the raw format of Switch1 of Ecu2.
Let’s go ahead and do that for a few more signals. So we have the Ecu2 CanMessage three signals, so we have a Switch1, Switch2 Â and Sensor1 being set to Ecu1 CanMessage signals. And after we set those we can canWrite ecu2.
And that’s how you implement a CAN Database file into your t script. Again, it allows for code reuse if the signals change or maybe the IDs change in the database we’re still grabbing the same database, so it allows us to give us a little bit of flexibility as well and can also add into the readability of our t script.