当前位置: 首页 > news >正文

Vector - CAPL - 定时器函数和使用

定时器在C语言中的使用我想学习过C编程的都不会陌生,它能够提供延时,完成等待一定的时间;它也可以实现多线程的操作,并行实行某些软件功能。那在CAPL中,定时器又能做哪些工作呢?又是怎么使用的呢?今天我们就一起来看下。

timer&msTimer

在CAPL中主要的定时器有毫秒定时器和秒定时器,他们分别是Timer和msTimer。对于计时器类型的变量,最长时间为2147483647 s(=596523.23h),对于msTimer类型的变量最长时间是2147483647ms(=2147483647s=596,52h);我们常定义在variables中,如下:

variables
{timer timer1;msTimer mstimer2;message 0x100 msg1;message 0x101 msg2;
}on timer timer1
{output(msg1);write("执行timer1内部内容,发送0x100报文");
}on timer mstimer2
{output(msg2);write("执行mstimer2内部内容,发送0x101报文");
}

setTimer

功能CAPL中的定时器精度取决于所使用的的硬件,一般精度为一毫秒;

msTimer的最大值为:2147483647 ms=2147483648 s=596,52h。

from 2:计时器的最大值为2147483647 s=596523.23h

from 3:计时器的UI大致为2147483647秒+214783647ns ~ 2147483649秒

t:上面在variables中定时的毫秒计时器或秒定时器

duration:设置定时器时间为duration,时间为毫秒或者秒

durationSec:起始时间

durationNanoSec:终止时间

variables {msTimer t1;Timer t23;
}on key F1 {setTimer(t1, 200); // set timer t1 to 200 ms
}on key F2 {setTimer (t23, 2); // set timer t23 to 2 sec
}on key F3 {setTimer (t23, 0, 1250*1000 ); // set timer t23 to 1.250 milliseconds
}on timer t1 {write("F1 was pressed 200ms ago");
}on timer t23 {write("F2 was pressed 2 sec ago or F3 1250000 nsec ago");
}

setTimerCyclic

功能:设置一个循环计时器,循环调用定时器

t:毫秒定时器或秒定时器(timer&msTimer),在variables中定义的定时器

firstDuration:启动定时器起始时间

period:计时器在到期时重新启动的时间,周期时间以毫秒为单位

periodInNs:计时器在到期时重新启动的时间,,周期时间以纳秒为单位

variables {msTimer t1;Timer t23;message 0x100 msg1;
}
on timer timer1
{output(msg1);write("执行timer1内部内容,发送0x100报文");
}
void send_msg1()
{//以周期为20ms的周期发送0x100setTimerCyclic(timer1, 20)
}
void send_msg2()
{//等待100ms后以周期为20ms的周期发送0x100setTimerCyclic(timer1, 100,20)
}

cancelTimer

功能:停止正在激活的定时器

t:毫秒定时器或秒定时器(timer&msTimer),在variables中定义的定时器

variables {msTimer t1;Timer t23;message 0x100 msg1;
}
on timer timer1
{output(msg1);write("执行timer1内部内容,发送0x100报文");
}
void send_msg1()
{//以周期为20ms的周期发送0x100setTimerCyclic(timer1, 20)
}
void send_msg2()
{//等待100ms后以周期为20ms的周期发送0x100setTimerCyclic(timer1, 100,20)
}
void stop_msg()
{//停止周期发送报文0x100cancelTimer(timer1);
}

timetoelapse

功能:计时器超时并调用事件过程之前所需的时间

返回一个值,该值指示在调用计时器事件过程之前还要经过多少时间。对于Form 1,时间值以秒为单位返回;对于Form 2,时间值以毫秒为单位返回。如果计时器未激活,则返回-1;计时器事件过程本身也是如此。

t:毫秒定时器或秒定时器(timer&msTimer),在variables中定义的定时器

timer t;
setTimer(t, 5);
write("Time to elapse: %d", timeToElapse(t)); // writes 5

isTimerActive

功能:返回值指示特定计时器是否处于活动状态,在调用setTimer函数和调用ontimer事件过程之间就是这种情况。

t:毫秒定时器或秒定时器(timer&msTimer),在variables中定义的定时器;

返回值:如果计时器激活状态则为1;否则为0。0也在计时器事件过程中返回。

timer t;
write("Active? %d", isTimerActive(t)); // writes 0
setTimer(t, 5);
write("Active? %d", isTimerActive(t)); // writes 1

以上是CAPL相关定时器的所有常用函数,欢迎大家评论区交流!!!

http://www.lryc.cn/news/30961.html

相关文章:

  • 【嵌入式C】常见问题
  • [神经网络]Transfomer架构
  • C++之多态 虚函数表
  • AI_Papers周刊:第四期
  • A Simple Framework for Contrastive Learning of Visual Representations阅读笔记
  • mac安装开发工具:clipy、iterm2、go、brew、mysql、redis、wget等
  • DJ1-1 计算机网络和因特网
  • [1.3.3]计算机系统概述——系统调用
  • 【Java开发】JUC进阶 03:读写锁、阻塞队列、同步队列
  • Fragment中获取Activity的一点点建议
  • Java Math类
  • Javascript -- 加载时间线 正则表达式
  • gdb/git的基本使用
  • 信息安全与数学基础-笔记-④二次同余方程
  • Luogu P4447 [AHOI2018初中组]分组
  • 手把手创建flask项目
  • SpringCloud-4_Eureka服务注册与发现
  • 【react全家桶】生命周期
  • 虚拟机安装Windows 10
  • 【CMU15-445数据库】bustub Project #2:B+ Tree(下)
  • leetcode 困难 —— 外星文字典(拓扑排序)
  • ubuntu server 18.04使用tensorflow进行ddqn训练全过程
  • 2023年全国最新二级建造师精选真题及答案14
  • mysql一条语句的写入原理
  • 嵌入式Linux内核代码风格(二)
  • Spring Boot @Aspect 切面编程实现访问请求日志记录
  • 初学者的第一个Linux驱动
  • 7. 拼数
  • Java每天15道面试题 | Redis
  • 13_pinctrl子系统