Presentation timer on a CV12 with an NI Series Master

dmenkedmenke Junior MemberPosts: 24
I realize this may be a simple thing for more experienced programmers, and yes I have scoured the forums, but not found what I am looking for. My client has asked for a countup timer that shows the amount of time that has passed since the start button has been pressed, for timing presentations and such. I am aware that the WAIT command is notoriously inaccurate for measuring time consistently, and the TIMELINE command seems Greek. A fellow Linux user suggested sampling the system clock, and maths, going so far to give me examples in JAVA and C++. More Greek.

So far, I have managed to put together a usable interface, but am failing miserably at the code to drive it. Can anyone throw me a bone with some code, and possibly an explination of TIMELINE if that is how you do it?

Thanks,

Doug

Comments

  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,130
    How I would approach this using pseudo-code and describing concepts:

    I would essentially (obviously) create a stop watch-type thing.

    I upon the start button - I would start a repeating timeline that ticks away each second. I would create a integer variable called MyTimer or whatever that starts at 1 and increments each fire of the timeline.

    The pause button would just pause/kill the timeline. The RESET button would just set the counter time back to zero.

    To display the time on the touch panel, I'd make a little routine/function that converts the integer decimal number of seconds since start to minutes/seconds.

    It looks like this:

    nMins=MyTijmer/60
    nSeconds= MyTimer-(MyTijmer*60)
    (there are quite a few ways to do this - this is basically just to explain the principle.

    Then convert the integers nMins and nSeconds to the text you want. and then send the whole text to a variable text button on the TP.

    You'll have to do a little bit of logic to deal with leading zeros and so forth.

    ex: if the nMins=5 and nSeconds=8

    if you just do something like send_string MyTP," 'TEXT101-',itoa(nMins),':',itoa(nSeconds)";
    you'll get 5:8 on the TP instead of 5:08 So, I'd do something like

    if(nSecond=0){MyString='00';}
    else if(nSecond<10){ MyString=" '0',itoa(nSeconds);
    else {MyString="itoa(nSeconds)";
  • javery1javery1 Junior Member Posts: 21
    Timelines could use better documentation in NetLinx Studio (like everything else), but they're not as tricky as they first appear.

    You will need to create a long variable to use as the timeline ID, and a long array to use as the times the timeline will fire. Something like this:
    DEFINE_CONSTANT
    long tlTimerID = 1;
    long tlTimerTimes[] = {1000};  //1000 = 1 second
    


    When it comes time to start the timer, timeline_create will start the timeline events firing at the specified times:
    timeline_create(tlTimerID, tlTimerTimes, max_length_array(tlTimerTimes), timeline_absolute, timeline_repeat);
    
    Here, it doesn't matter if we use timeline_absolute or timeline_relative, since we only have one time in our array, but if we had multiple items in the array, this would determine how they fired.
    Timeline_repeat will keep the timeline running until we stop it.


    When it comes time to stop the timer, use timeline_kill
    timeline_kill(tlTimerID);
    &#8203;
    


    To perform a task when the time has elapsed, use a timeline event:
    timeline_event[tlTimerID]
    {
      //increment time here
      //display new time here
    }
    
Sign In or Register to comment.