Menu

FORTE Time Handling

Developers
2015-03-11
2015-03-11
  • AYDIN HOMAY

    AYDIN HOMAY - 2015-03-11

    Hi guys
    I am looking to understanding CTimeHandler in FORTE, but I have two question:

    1- What is the meaning of FORTE_TIME_BASE_UNITS_PER_SECOND it shows what ?
    2- What is the functionality of below function ? why we have this condition (MILISECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND) over here?

    void CIEC_TIME::setFromMiliSeconds(TValueType pa_nValue){
    #if MILISECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND
    this = pa_nValue * (FORTE_TIME_BASE_UNITS_PER_SECOND / MILISECONDS_PER_SECOND);
    #else
    this = pa_nValue / (pa_nValue / FORTE_TIME_BASE_UNITS_PER_SECOND);
    #endif
    }
    True body make sense but False body dose not make sense ...!

     
  • Zoitl Alois

    Zoitl Alois - 2015-03-11

    Hi Aydin,

    ad 1) FORTE_TIME_BASE_UNITS_PER_SECOND defines the time base for the values stored in the TIME data type. IEC 61131-3 does not define the accuracy of TIME and with the that value you can define it for your platform. Per default the value is 1 000 000 000 which means that the base unit is 1ns.

    ad 2) the function takes a time in miliseconds and transforms it to the representation of the TIME data type. The ifdef is needed to keep numeric stability. However as you noted the #else part makes no sense. If you look at the other functions around it you can see that. In cset [forte:958c76] you can find a fix.

    Thanks a lot for reporting this issue.

     

    Related

    Commit: [958c76]