How can I send a CAN frame or a CAN Signal with CANape?
This can be done through the following steps. In CANape open Tools | Function Editor and define a New Project function.
The following example defines a frame with ID 0x100 and the data bytes filled with 0x01. The frame is sent out on the CAN bus with device ExampleDevice_send.
Function SendExchangeFrame ()
ExampleDevice_send.SendMessage(0x100, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01);
More details to the function SendMessage() can be found in the CANape help.
The next example shows a function for an existing CAN device ExampleDevice_send with description file (DBC file) in which the signals (SendSignal_01; SendSignal_02) are described. The signals shall be sent out to the CAN bus with a fixed value of 0x10 for SendSignal_01 and 0x20 for SendSignal_02.
Function SendExchangeSignal ()
ExampleDevice_send.SendSignal_01 = 0x10;
ExampleDevice_send.SendSignal_02 = 0x20;
A further use case can be a XCP to CAN gateway. The signals channel1 and channel2 from the device XCPSim should be routed to the signals XCPtoCAN_Sig_01 and XCPtoCAN_Sig_02 of the CAN device XCPtoCAN_V01.
Here it is important to have matching data types of the XCP and the CAN signal.
Function XCPtoCAN ()
XCPtoCAN_V01.XCPtoCAN_Sig_01 = XCPsim.channel1;
XCPtoCAN_V01.XCPtoCAN_Sig_02 = XCPsim.channel2;
As a next step open Start | Measurement Configuration, go to Functions and insert a Measurement function. Then Select your just created Project functions SendExchangeFrame();or SendExchangeSignal() or XCPtoCAN().
Via Measurement mode you can define when the Measurement function is called and thus when the CAN frame is sent. In case of routing from XCP signals to CAN it makes sense to use the same measurement mode that the XCP signal are using.