I'm trying to read the linFrame sent from a slave LIN node, to identify when a particular bit has changed from from zero to one.
I'm sending a LIN message to a slave servo that commands it to move beyond a physical end-stop.
Once it physically hits the end-stop, its status message will set a single bit from zero to one. That bit identifies when the servo motor has stalled. My goal is to have the CAPL script detect that the motor has stalled.
My command message is sent by my CAPL script using the "output()" function. I'm unsure which function can read the response, but I think I have to send a header for the response message and then read the response frame.
variables
{
linFrame 0x03 ACT_CTRL_MT3 = {msgChannel=1}; // actuator control command
linFrame 0x21 ACT_STA_MT3 = {msgChannel=1}; // actuator status response
mstimer timer1;
}
on key 'c'
{
// command large angular position from servo at node 3
ACT_CTRL_MT3.RTR = 0;
ACT_CTRL_MT3.byte(0)=0x12; // section 4.5.9 of manual
ACT_CTRL_MT3.byte(1)=0xE4;
ACT_CTRL_MT3.byte(2)=0x14;
ACT_CTRL_MT3.byte(3)=0xFE; // max angle
ACT_CTRL_MT3.byte(4)=0xFF; // max angle
ACT_CTRL_MT3.byte(5)=0x00;
ACT_CTRL_MT3.byte(6)=0x00;
ACT_CTRL_MT3.byte(7)=0x40;
output(ACT_CTRL_MT3); // update command payload
// Send the frame header
ACT_CTRL_MT3.RTR = 1;
output(ACT_CTRL_MT3);
settimer(timer1,5000); // wait 5 seconds for motor to move
}
on timer timer1{
//send header of status message
ACT_STA_MT3.RTR = 1;
output(ACT_STA_MT3);
write("Reading message...");
//output message context
writelineex(1,1,"FrameId=%d Length=%d, 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X;", ACT_STA_MT3.ID, ACT_STA_MT3.DLC,
ACT_STA_MT3.byte(0), ACT_STA_MT3.byte(1), ACT_STA_MT3.byte(2), ACT_STA_MT3.byte(3), ACT_STA_MT3.byte(4), ACT_STA_MT3.byte(5), ACT_STA_MT3.byte(6), ACT_STA_MT3.byte(7));
}
The data that is written by the "writelinee" function is very different from the values seen in my LIN trace window in CANalyzer.
I find it especially strange that the ID field written out is different from the ID set in the variables section at the start of the code. In the code I define the frame ID of that status message as 0x21, but the write command gives a different value (0x35 I believe, although I'm away from my setup at the moment.