We have created a t script that acts as a CAN gateway by taking messages from channel 1 and writing them on channel 2, and messages from channel 2 and writing them on channel 1. We’ve gone over the on start and on stop blocks, the on CanMessage hooks and the variables block. But let’s take a look at the structures and let’s change this model up a little bit. What we’re gonna do is make our t script only send messages from channel 1 to channel 2, if they have an ID of x100. Do that by putting x100 in parentheses (0x100) right before the block. Let’s suppose when we receive this message with the CAN ID x100 you want to change the ID to 200 and we want to change a byte of data. How would we do that ?

So we use this message, this message is a structure, it’s a CanMessage structure, so we can access the ID by putting a period after this typing ID (this.ID) and setting it to 0x200.Will also change this.data third by two ex ff (0xff). So with a few lines of code we’re able to access a structure, change members, and then write it back to a new channel.

Back to: Intro to <em>t</em> Programming > Intro to t Programming: Part 4

Debug on...