web123456

[Zero-Basic Learning CAPL]——Send CAN message (LiveCounter-Life Signal)

includes { } variables { message ESC_125 meg1; msTimer Timer1; long Cycle_Timer1; int Button1; int VehicleSpeedVD1; long VehicleSpeed1; int tempRollingCounter=0x00;//Define RollingCounter and initialize } //Create a message on message ESC_125 { // (0)=0x11; // (1)=0x12; // =8; //CANFD message sending flag meg1.FDF = 1; meg1.BRS = 1; } //Create a timer on timer Timer1 { output(meg1); setTimer(Timer1,Cycle_Timer1); } //Write default values ​​to corresponding controls in the panel on start { sysSetVariableInt(sysvar::TestOne::Button,1);//The default value of the Button-bound control is 1, open state sysSetVariableInt(sysvar::TestOne::Length,8);//The value of Length binding is 8 by default sysSetVariableInt(sysvar::TestOne::Cycle_Time,50);//Cycle_Time bound control default value is 50 sysSetVariableInt(sysvar::TestOne::VehicleSpeedVD,0);//0x0:Valid,0x1:Invalid sysSetVariableInt(sysvar::TestOne::VehicleSpeed,0);//The default value of vehicle speed is 0 sysSetVariableInt(sysvar::TestOne::RollingCounter,0);//The loop code defaults to 0 } //Click the button to trigger periodic sending of messages on sysvar_update sysvar::TestOne::Button { Button1 = @this; if(Button1 == 1) { setTimer(Timer1,Cycle_Timer1); } else { cancelTimer(Timer1); } } //Change the length manually in the panel on sysvar_update sysvar::TestOne::Length { meg1.DLC=@this; } //Change the period value manually in the panel on sysvar_update sysvar::TestOne::Cycle_Time { Cycle_Timer1=@this; } //Manually change the effective speed value in the panel on sysvar_update sysvar::TestOne::VehicleSpeedVD { VehicleSpeedVD1=@this; meg1.ESC_VehicleSpeedVD.phys=VehicleSpeedVD1; } //Change the speed value manually in the panel on sysvar_update sysvar::TestOne::VehicleSpeed { VehicleSpeed1=@this; meg1.ESC_VehicleSpeed.phys=VehicleSpeed1; } ///liveCpunter algorithm implementation //RollingCounter(new)=(RollingCounter(old)+1)&0x0F //The cycle between 0-15 //The classic algorithm can be used with tempRollingCounter=tempRollingCounter%16 On signal_update ESC_125::ESC_RollingCounter { tempRollingCounter++; tempRollingCounter=tempRollingCounter%16; if(@sysvar::TestOne::RollingCounter_Button1==1) { meg1.ESC_RollingCounter=tempRollingCounter; @TestOne::RollingCounter=tempRollingCounter; write("Cycle value: %d",tempRollingCounter); } else { meg1.ESC_RollingCounter=1; } //Manually enter the value of RollingCounter if(@sysvar::TestOne::RollingCounter_Button1==0) { meg1.ESC_RollingCounter=@TestOne::RollingCounter; write("Fixed value: %d",meg1.ESC_RollingCounter); } }