functions
- time
- dword timeNow()
- long addTimeMeasurementStartTime(int64 timeSpan, long time[]);
- void getLocalTime(long time[]);
- write
- void write(char format[], ...);
- dword writeCreate(char name[])
- void writeLineEx(long sink, dword severity, char format[], ...)
- void writeConfigure( dword sink, dword lines, dword logging, char filename[]);
- void writeTextColor(dword sink,dword red, dword green, dword blue)
- void writeTextBkgColor(dword sink,dword red, dword green, dword blue)
- void writeClear(dword sink)
- void writeDestroy(dword sink)
time
dword timeNow()
- dword timeNow()
- float timeNowFloat();
没有本质区别,只不过返回值一个是整形,一个是浮点型 返回值的单位都是10ms
下面的返回值是ns:
- float TimeNowNS();
- int64 timeNowInt64();
没有本质区别,只不过返回值一个是整形,一个是浮点型 返回值的单位都是ns+
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | On key 'c' { //1微秒等于一百万分之一秒(10-6秒),函数的单位是10ms,所以 除以100000 write("time1:%ld",timeNow());//unit :10ms write("time2:%f",timeNow()/100000.0);//unit :s write("time3:%f",timeNowFloat());//unit :10ms write("time4:%f",timeNowFloat()/100000.0);//unit :s //1纳秒等于十亿分之一秒(10-9秒) write("time5:%I64d",timeNowInt64());//unit :ns write("time6:%f",timeNowInt64()/1000000000.0);//unit :s write("time7:%f",TimeNowNS());//unit :ns write("time8:%f",TimeNowNS()/1000000000.0);//unit :s } |
输出:
time1:93694
time2:0.936940
time3:93694.000000
time4:0.936940
time5:936941094
time6:0.9369411
time7:936941094.000000
time8:0.9369411
long addTimeMeasurementStartTime(int64 timeSpan, long time[]);
获取函数执行时的日期时间
1 2 3 4 5 6 7 8 9 10 11 12 13 | On key 'c' { long time[8]; //获取按下键盘c的时间 addTimeToMeasurementStartTime(timeNowNS(), time); write("key c event occured on %02d/%02d/%02d %02d:%02d:%02d.%-3d", time[5]+1, time[4], time[6]-100, time[3], time[2], time[1], time[0]); //获取开始 run的时间, getMeasurementStartTime(time); write("Measurement was started on %02d/%02d/%02d %02d:%02d:%02d.%-3d", time[5]+1, time[4], time[6]-100, time[3], time[2], time[1], time[0]); } |
输出:
key c event occured on 05/28/20 10:02:38.896
Measurement was started on 05/28/20 10:02:35.158
void getLocalTime(long time[]);
返回日期时间数组
-
void getLocalTimeString(char timeBuffer[]);
返回日期时间字符串
1 2 3 4 5 6 7 8 9 10 11 12 | On key 'c' { long time[9]; char timeBuffer[64]; //数组输出 getLocalTime(time); write("key c event occured on %02d/%02d/%02d %02d:%02d:%02d.%-3d", time[5]-100, time[4]+1, time[3], time[3], time[2], time[1], time[0]); //字符串输出 getLocalTimeString(timeBuffer); write("key c event occured on %s",timeBuffer); } |
输出:
key c event occured on 20/05/28 28:19:09.42
key c event occured on Thu May 28 19:09:42 2020
write
canoe 没有debug 功能,一切输出需要再write窗口显示
标注1的功能依次是:
- 暂停打印
- 清除所有的输出窗口页(从标注2看出write有4个页面)
- 清除当前选中的页面
- 清除logging文件中的内容
- 搜索
- 拷贝
- 导出选中的页面中的数据到txt文件中
- 配置选项
void write(char format[], …);
最简单基础的输出函数,相当于C的printf函数。
dword writeCreate(char name[])
在write 窗口创建一个新的页面,下次启动canoe的时候自动被删除。
1 2 3 4 5 6 | On key 'c' { // 创建一个新的页,名字就叫做"New Page" mNewPage= writeCreate("New Page"); write("mNewPage:%d",mNewPage);//mNewPage相当于句柄,后面对这个页面的操作都要用到这个句柄 } |
多了一个"New Page" 的空页面
void writeLineEx(long sink, dword severity, char format[], …)
换行打印文本,在指定的页面
- void writeEx(long sink, dword severity, char format[], …)
在最后一行接着打印文本,在指定的页面
- sink 选择输出的页面,sink=0 ,选择的是 system; sink=1 ,选择的是 CAPL / .NET
- severity:打印信息的类型
- 0 :一般
- 1:信息
- 2:提醒
- 3:错误
1 2 3 4 5 6 7 8 9 | on start { //Create a new page at the Write Window mNewPage= writeCreate("New Page"); for(i=0;i<4;i++) { writeLineEx(mNewPage,i,"output type:%d ",i); } } |
输出:
可以看出前面的输出类型图标不一样
writeEx :不换行打印:
1 2 3 4 5 6 7 8 9 | on start { //Create a new page at the Write Window mNewPage= writeCreate("New Page"); for(i=0;i<4;i++) { writeEx(mNewPage,0,"output type:%d ",i); } } |
输出:
void writeConfigure( dword sink, dword lines, dword logging, char filename[]);
配置打印 log文件。可以将打印在指定页面的数据存储在logging文件中
1 2 3 4 5 6 7 8 9 10 11 12 | on start { //Create a new page at the Write Window mNewPage= writeCreate("New Page"); //第三个参数如果不等于0就使能logging记录,如果文件名不存在,则创建文件 writeConfigure(mNewPage, 20, 1, "c:\\temp\\writelog.TXT"); for(i=0;i<4;i++) { //Show the description of the program writeLineEx(mNewPage,i,"output type:%d ",i); } } |
输出:
void writeTextColor(dword sink,dword red, dword green, dword blue)
设置打印文本的字体颜色
void writeTextBkgColor(dword sink,dword red, dword green, dword blue)
设置打印文本的字体背景颜色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | variables { long mNewPage; // Sink identifier int i; } on start { //Create a new page at the Write Window mNewPage= writeCreate("New Page"); writeConfigure(mNewPage, 20, 1, "c:\\temp\\writelog.TXT"); for(i=0;i<4;i++) { writeLineEx(mNewPage,i,"output type:%d ",i); } } on key 'q' { WriteTextColor(mNewPage,255,0,0); WriteLineEx(mNewPage,1,"This is red text"); WriteTextBkgColor(mNewPage,0,255,0); WriteLineEx(mNewPage,1,"This is red text with green background"); } on key 'w' { writeclear(mNewPage); } on stopMeasurement { //最后还原字体设置,否则下次run的时候字体仍然是红色的。 WriteTextColor(0,0,0,0); WriteTextBkgColor(0,255,255,255); //destroy the new created Page writeDestroy(mNewPage); } |
按下键盘c,输出:
void writeClear(dword sink)
清空指定的页面
void writeDestroy(dword sink)
删除创建的页面