CAN messages w/ events, script, other?

Discuss issues and ideas you have to configuring displays with PowerVision
dberezowski
Posts: 65
Joined: Wed Sep 08, 2010 4:03 pm

CAN messages w/ events, script, other?

Post by dberezowski » Wed Jun 08, 2011 8:23 am

1. Is it possible to send a CAN message triggered via an event? For example:
User presses a key, one or more of the 8 data bytes are populated with data and the message is sent.

2. Is it possible to send/receive CAN data via scripting?

3. Is it possible to cause an event to be triggered when a CAN message is received? If so, is it possible to process this CAN message in some way?
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: CAN messages w/ events, script, other?

Post by ksaenz » Thu Jun 09, 2011 8:20 am

1. Yes, the key press can fire a transition in a state machine. In the state you can change the value of the data bytes and then execute a J1939->Tx Ext Free Form() action to send a free form CAN message.

2. Yes, with scripting you can use the function sendEvent() instead of the key press and the rest would be the same.

3. You can use Fire on change to trigger an event when a CAN message changes the value of a variable and from there you can process the message using state machines or scripts.

Regards,

ksaenz
dberezowski
Posts: 65
Joined: Wed Sep 08, 2010 4:03 pm

Re: CAN messages w/ events, script, other?

Post by dberezowski » Thu Jun 09, 2011 3:13 pm

1. How do I change the value of one of the eight data bytes in a CAN message?
2. I am not familiar with how to use the J1939->Tx Ext Free Form() action as I have not used Free Form CAN messages as yet.

I don't suppose you have an example of what I am trying to do? In a nutshell:

The user presses a button and I need to populate one of the bytes of a CAN message with a value based on what key was hit. Then, of course, I need to trigger that CAN message to be sent out.
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: CAN messages w/ events, script, other?

Post by mbowdich » Sun Jun 12, 2011 10:09 am

This is actually very easy. When you create the FreeFormCAN message, you will assign a variable(s) to the specific bits in the message. You can use a state machine (or script) that is started by a button press to first run calculation events on the variable(s) that you assigned to the CAN message, followed by the send command. Each button can be assigned a different calculation event, changing the data that will be sent.

One key point to remember is to make sure you set all unused bits to 1s if the message is going to follow J1939 protocol. I do this with some fixed value variables. I have one set to 3 (bin 11), one set to 15 (bin 1111) and one set to 255 (bin 1111 1111). In the FreeFormCAN message, I set all of the unused bits to 1s using these variables.

A second key point to remember is that the CAN message will send the variable value directly to the CAN bus (resolution of 1 and offset of 0). You will need to pre-process the variable if you require an offser or other resolution (such as sending engine speed, for example).

Attached is a basic example. If you actually want to load it, connect port A and Port B to the came CAN bus, and it will transmit from port A to port B. The example could have been simplified by calling he calculations directly from the buttons and sending the CAN message with a state machine called with the fire on change directly from the variable. This is good if you want to send the message whenever the variable is changed, but it will not work if the variable stays the same (calculating a 1 when it is already 1), and it does not work if you have other events that could change the variable when you do not want the CAN message to be sent.
Attachments
FFCAN example.db3
(3.02 MiB) Downloaded 35 times
dberezowski
Posts: 65
Joined: Wed Sep 08, 2010 4:03 pm

Re: CAN messages w/ events, script, other?

Post by dberezowski » Tue Jun 14, 2011 4:49 pm

Thank you for this example. I selected it to run on a PV450 and it works. However, I do not see where you defined the bits and bytes of the FreeForm CAN message. I do see MyDevice and TestSPN but not a detailed mapping of how a variable maps to bits or bytes. What am I not looking at?
dberezowski
Posts: 65
Joined: Wed Sep 08, 2010 4:03 pm

Re: CAN messages w/ events, script, other?

Post by dberezowski » Tue Jun 14, 2011 4:57 pm

One other question. What is causing the CAN value to timeout to 0 and how to I control that?
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: CAN messages w/ events, script, other?

Post by mbowdich » Wed Jun 15, 2011 9:11 am

The FFCAN message is defined on the Environment setup page. Just click on the CAN port 1 and you will see the configuration. To recieve the data on port 2 to show you feedback, I also defined it in the J1939 database.

The reason you see it time out at 5 seconds is because it is only being transmitted 1 time. Five seconds is the standard timeout on recieved J1939 messages; this cannot be adjusted easily. FFCAN message are only sent when you tell it to send. In this case, I only tell it to send 1 time after each button push. If you want it to send on a cycle, then you can use a state machine and a timer event to repeatadly send it at the timer's interval.