Here is an example code on how to check for a specific CAN message in your Codesys application and then call the "SysClose" sub-routine to power down the Controller. (This remote power cycling logic is needed to remotely flash the controller using the VDS/VDSR tool)
The CAN message used in this example is as follows:
- CAN_ID: 16#1EADBEEF
- DLC: 4 bytes
- Byte 1: 16#DE
- Byte 2: 16#AD
- Byte 3: 16#BE
- Byte 4: 16#EF
Here is the code:
//CAN reset message
fb_x_can_obj_get_msg.ou32_Handle := gu32_CanHandleReset;
fb_x_can_obj_get_msg();
IF fb_x_can_obj_get_msg.os16_Status = C_NO_ERR AND
fb_x_can_obj_get_msg.ot_Msg.u8_Dlc = 4 AND
fb_x_can_obj_get_msg.ot_Msg.au8_Data[0] = 16#DE AND
fb_x_can_obj_get_msg.ot_Msg.au8_Data[1] = 16#AD AND
fb_x_can_obj_get_msg.ot_Msg.au8_Data[2] = 16#BE AND
fb_x_can_obj_get_msg.ot_Msg.au8_Data[3] = 16#EF
THEN
fb_x_ser_write_string(ops_String := ADR('CAN Reset!$r$l'));
q_CanReset := TRUE;
END_IF
//shutdown?
IF gu8_SysIgnition = X_OFF OR q_CanReset = TRUE THEN
fb_x_ser_write_string(ops_String := ADR('Ran '));
s_Temp := UDINT_TO_STRING(gu32_SysTimeMs / 1000);
fb_x_ser_write_string(ops_String := ADR(s_Temp));
fb_x_ser_write_string(ops_String := ADR(' seconds.$r$l'));
fb_x_sys_delay_us(ou32_Delay_us := 250000); //delay 0.25 seconds
fb_SysClose(); (* power down system *)
END_IF
Here is a screenshot of the CAN handle in Codesys: