You are not logged in.
Pages: 1
Topic closed
Hello,
ïs it possible somehow to measure, how long the code inside REXLANG is running each periode? I tried using functions CurrentTime and ElapsedTime, but this is not working.
Thanks for help.
example:
long main(void)
{
time_start = CurrentTime();
/*EXECUTED CODE*/
time_out = ElapsedTime(CurrentTime(),time1);
return 0;
}
Offline
Hello bodie,
your approach is completely right - I would do it the same way.
The issue is that you are referencing wrong variable into ElapsedTime() function. It should look like:
long main(void)
{
time_start = CurrentTime();
/*EXECUTED CODE*/
time_out = ElapsedTime(CurrentTime(),time_start);
return 0;
}
Hope it helps.
Regards, Tomas
Offline
Hello,
it is my mistake, I do not change the name of both variables in the post, in the REXLANG code it is OK. Problem is that the time_out is zero. I checked value time_start in Trace (or CurrentTime from each periode, see code below) and it is not changing for several periodes. The periode of task is 2 ms. I do not know what is the resolution of ElapsedTime function?
The data type of time1 variable is double.
long init(void)
{
time1 = CurrentTime();
return 0;
}
long main(void)
{
Trace(11,CurrentTime()-time1);
return 0;
}
6.4.2018 13:07:41.009 Info REXLANG[00289,00029,0011]: 7052
6.4.2018 13:07:41.011 Info REXLANG[00289,00029,0011]: 7052
6.4.2018 13:07:41.013 Info REXLANG[00289,00029,0011]: 7052
6.4.2018 13:07:41.015 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.017 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.019 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.021 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.023 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.025 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.027 Info REXLANG[00289,00029,0011]: 7067
6.4.2018 13:07:41.029 Info REXLANG[00289,00029,0011]: 7083
6.4.2018 13:07:41.031 Info REXLANG[00289,00029,0011]: 7083
6.4.2018 13:07:41.033 Info REXLANG[00289,00029,0011]: 7083
6.4.2018 13:07:41.035 Info REXLANG[00289,00029,0011]: 7083
Offline
Hi bodie,
are you sure the time1 variable is of type double? I guess it's a long in your declaration.
Let me know,
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Hello,
the declaration looks like this:
double time1 = 0;
I tried using
double time1 = 0.0;
to see if the type is not cast to long, but it did not help.
I tried several things and now it is working - the code is OK, but I was running it on localhost on PC. When I download it to RPi3 and run, it is OK.
So only for be sure, is there problem running some functions on PC, or probably is it some kind of bug?
Offline
Hello Bodie,
sorry for troubles with platform inconsistency. You are right - on Linux based systems it works well - however you should be aware that ElapsedTime() returns value in microseconds (Linux) / miliseconds (Windows).
Many thanks for reporting this bug. We will fix it in next release.
If I can be of any assistance, let me know.
Regards, Tomas
Offline
Thanks for informations and your help.
Offline
Pages: 1
Topic closed