【灵冰肌】CAPL编程例子

上传人:豆浆 文档编号:11356152 上传时间:2017-09-02 格式:PDF 页数:5 大小:300.58KB
返回 下载 相关 举报
【灵冰肌】CAPL编程例子_第1页
第1页 / 共5页
【灵冰肌】CAPL编程例子_第2页
第2页 / 共5页
【灵冰肌】CAPL编程例子_第3页
第3页 / 共5页
【灵冰肌】CAPL编程例子_第4页
第4页 / 共5页
【灵冰肌】CAPL编程例子_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《【灵冰肌】CAPL编程例子》由会员分享,可在线阅读,更多相关《【灵冰肌】CAPL编程例子(5页珍藏版)》请在金锄头文库上搜索。

1、CAPL 编程例子 /*Example 1 - Event Message Transmission*/ . 1 /*Example 2 - Periodic Message Transmission*/ . 1 /*Example 3 - Conditionally Periodic Message Transmission*/ . 2 /*Example 4 - Responding to a Received Message*/ . 2 /*Example 5 - Reading the Data within a Received Message*/ . 3 /*Example 6 -

2、 Responding to a message after a delay*/ . 3 /*Example 7 - Measuring the Time Between Periodic Messages*/ . 4 /*Example 8 - Using CAPL to control logging*/ . 4 /*Example 9 - Responding to a change in an Environmental Variable*/ . 5 /*Example 1 - Event Message Transmission*/ /定义了 ID为 0x555长度为 1的消息值为

3、0xAA,按键 b触发发送 variables message 0x555 msg1 = dlc=1; on key b msg1.byte(0)=0xAA; output(msg1); /*Example 2 - Periodic Message Transmission*/ /定义了 ID为 0x555长度为 1的消息 , 按照周期 100ms, 值 +发送 variables message 0x555 msg1 = dlc=1; mstimer timer1; / define timer1 on start setTimer(timer1,100); / initialize tim

4、er to 100msec on timer timer1 setTimer(timer1,100); / reset timer msg1.byte(0)=msg1.byte(0)+1; / change the data output(msg1); / output message CAPL 编程例子 /*Example 3 - Conditionally Periodic Message Transmission*/ /定义了 ID为 0x400 长度为 1的消息 , 按 住 a有效 触发发送 , 按照周期 200ms, 值 -发送 variables message 0x400 msg

5、A = dlc=1; mstimer timerA; int conditionA = 0; / initialize conditionA= off on key a conditionA =! conditionA; / toggle conditionA if(conditionA = 1) / if condition is active setTimer(timerA,200); / then start timer on timer timerA if(conditionA = 1) / if condition is still true setTimer(timerA,200)

6、; / then continue timer msgA.byte(0)=msgA.byte(0)-1; / change the data output(msgA); / output message /*Example 4 - Responding to a Received Message*/ on message ABSdata, EngineData message WheelInfo wMsg; / Define a new message / Print a message to the screen write(“Message %lX received on CAN%ld”,

7、 this.ID,this.CAN); / Send out another message output(cdMsg); CAPL 编程例子 /*Example 5 - Reading the Data within a Received Message*/ on message EngineData long product; / Read EngSpeed and EngTemp signals product = this.EngSpeed.phys * this.EngTemp.phys; write(“The product of the engine speed and”); w

8、rite(“engine temperature is %l”, product ); on message EngineTemp byte value; float temp; value = this.byte(0); / Scale the number so we get 2 decimal places temp = float / 100; write(“The temperature is %lf degrees.”, temp); /*Example 6 - Responding to a message after a delay*/ Variables Timer dela

9、yTimer; / Seconds-based timer long delayTimerPeriod = 5; / Delay of 5 seconds on message doorState if (this.Closed = 1) setTimer(delayTimer, delayTimerPeriod); else / Do sth if doors are open on timer delayTimer message DomeLight dlMsg; dlMsg.Status = 0; / Turn off dome light output(dlMsg); CAPL 编程例

10、子 /*Example 7 - Measuring the Time Between Periodic Messages*/ /Method 1: on message 0x101 long lastTime = 0; write(“Message 0x101 recevied at %ld”, this.TIME); write(“Time interval = %lf milliseconds”,(this.TIME - lastTime) / 100.0); lastTime = this.TIME; /Method 2: variables message 0x202 saveMsg;

11、 on message 0x202 write(“Message 0x202 received at % this.TIME); write(“Time interval = %ld milliseconds”,timeDiff(saveMsg, this); saveMsg = this; / saveMsg declared globally /*Example 8 - Using CAPL to control logging*/ on message 0x101 / Set the PreTrigger time to 1 second (1000 ms) setPreTrigger(

12、1000); / Set the PostTrigger time to 5 seconds (5000 ms) setPostTrigger(5000); / Set the name and path of the log file setLogFileName(“c:logslog101”); / Trigger logging. trigger(); CAPL 编程例子 /*Example 9 - Responding to a change in an Environmental Variable*/ /改变环境变量的响应 on envVar switchState int switchValue; switchValue = getValue(this); switch (switchValue) case 0: write(“Switch is now off.”); break; case 1: write(“Switch is now on.”); break; default: write(“Switch returned an illegal value.”); break; on start CallAllOnEnvVar();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号