Point of sale 如何在verifone vx520中设置多个计时器

Point of sale 如何在verifone vx520中设置多个计时器,point-of-sale,verifone,Point Of Sale,Verifone,我想设置输入键的定时器和一个关闭背光的定时器,但它使用我设置的第一个定时器,我不能设置多个定时器,第二个定时器不工作 我使用下面的代码 int timer1, timer2; long events; timer1 = set_timer(8000, EVT_TIMER); timer2 = set_timer(5000, EVT_TIMER); while(1){ events = wait_event(); if(events & EVT_KBD){ clr_timer(timer1

我想设置输入键的定时器和一个关闭背光的定时器,但它使用我设置的第一个定时器,我不能设置多个定时器,第二个定时器不工作

我使用下面的代码

int timer1, timer2;
long events;
timer1 = set_timer(8000, EVT_TIMER);
timer2 = set_timer(5000, EVT_TIMER);
while(1){
events = wait_event();
if(events & EVT_KBD){
clr_timer(timer1);
break;
}
else if (events & EVT_TIMER)
{
printf("TIME_OUT");
break;
}

while(1){
events = wait_event();
if(events & EVT_KBD){
clr_timer(timer2);
break;
}
else if (events & EVT_TIMER)
{
printf("TIME_OUT2");
break;
}
}

如果要将它们捕获为不同的事件,则需要使用不同的事件掩码(EVT_计时器)。棘手的是,你需要小心使用哪一个,因为它可能会触发其他动作。这些事件在
svc.h
中定义(请注意,掩码是
长的
,而
长的
被定义为32位,因此在使用所有标准事件后,您实际上没有任何剩余内容)

好消息是
set\u timer
返回一个ID(这就是
timer1
timer2
在代码中的内容)。然后,您可以使用
SVC\u TICKS
API来确定哪个计时器已过期。我写了一个名为“时间遗骸”的包装来帮助我

//First, define "timeRemains"
char timeRemains(long* timer)
{
    return SVC_TICKS(0, timer);
}

//Here's what your code may look like:
if(!timeRemains(&timer1))
{
    //timer1 has expired.  Do whatever you wanted to do when that happens.
    //NOTE: you don't know the state of timer2--it may also have expired, 
    //      so you will need to deal with that
}

if(!timeRemains(&timer2))
{
    //timer2 has expired.  Do whatever you wanted to do when that happens.
    //NOTE: even though we are PRETTY sure that timer1 has not yet expired,
    // you can't just forget about it. If you are going to exit this polling loop, 
    // be sure to clear it first.
}

另一种方法是将计时器保留在自己的数据结构中(例如,按计时器过期时间排序的排序列表),并仅使用一个系统计时器使第一个计时器过期(即排序列表中的第一个计时器)

当您收到
EVT_TIMER
系统事件时,您将触发过期时间已过的所有计时器(将其从排序列表中删除)

如果列表中还有任何计时器,则启动新的系统计时器,以使新的第一个计时器过期

有(至少)两件事需要注意:

  • 添加新计时器时,必须检查它是否不是第一个过期的计时器。如果是这样,您必须使用
    clr\u timer()
    取消现有的系统计时器,并为新的第一个计时器设置一个新的系统计时器以使其过期(新添加的计时器现在是排序列表中的第一个计时器)。将新计时器添加到空列表时,跳过
    clr\u timer()
    调用(因为现在应该没有激活的系统计时器)

  • 如果使用
    read_ticks()
    调用来计算计时器过期时间(或其他任何情况),请确保在计时器值溢出回零时(每49.7天发生一次)进行处理