Timer for Windows/Linux

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Timer for Windows/Linux

"Fabrício F. Kammer"
Hi all,

I need to implement a routine on my sofware to be executed each 5 minutes.

I'm using just FPC (without lazarus) becuase my software will run as a
console application and because I don't have graphical inteface on the
machine that I'm using.

How can I make a routine that works on both OS (Linux/Windows) like a
TTimer of the Delphi?

Regards,

Fabrício F. Kammer
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Timer for Windows/Linux

Felipe Monteiro de Carvalho
On 9/1/06, "Fabrício F. Kammer" <[hidden email]> wrote:
> I need to implement a routine on my sofware to be executed each 5 minutes.

Write a loop that first stores the current time, then executed
whatever you need, and then sleeps until current_time - previous_time
>= 5 minutes. Like this:

    while (not Terminated) do
    begin
      PreviousTime := Now;

      // Do what you need to do

      {----------------------------------------------
        "sleeps" while currentTime - PreviousTime isn´t bigger then 5 minutes
       ----------------------------------------------}
      while (Now - PreviousTime < 5 minutes) do
      begin
        Sleep(1000); // May be bigger
      end;
    end;

You can use the Now function here because 5 minutes a lot of time, and
so you don´t really need a lot of precision.

If you needed a nanosecond precision on your loop you could use the
powerful EpikTimer component:

http://wiki.lazarus.freepascal.org/EpikTimer

If you want to receive user input while your loop runs, then put the
loop on a separate thread.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Timer for Windows/Linux

"Fabrício F. Kammer"
Thanks Felipe,

Do you have an example of how to use this loop on a thread?

Sorry, but I don't know threads very well.

regards

Fabrício

Felipe Monteiro de Carvalho escreveu:

> On 9/1/06, "Fabrício F. Kammer" <[hidden email]> wrote:
>> I need to implement a routine on my sofware to be executed each 5
>> minutes.
>
> Write a loop that first stores the current time, then executed
> whatever you need, and then sleeps until current_time - previous_time
>> = 5 minutes. Like this:
>
>    while (not Terminated) do
>    begin
>      PreviousTime := Now;
>
>      // Do what you need to do
>
>      {----------------------------------------------
>        "sleeps" while currentTime - PreviousTime isn´t bigger then 5
> minutes
>       ----------------------------------------------}
>      while (Now - PreviousTime < 5 minutes) do
>      begin
>        Sleep(1000); // May be bigger
>      end;
>    end;
>
> You can use the Now function here because 5 minutes a lot of time, and
> so you don´t really need a lot of precision.
>
> If you needed a nanosecond precision on your loop you could use the
> powerful EpikTimer component:
>
> http://wiki.lazarus.freepascal.org/EpikTimer
>
> If you want to receive user input while your loop runs, then put the
> loop on a separate thread.
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Timer for Windows/Linux

Felipe Monteiro de Carvalho
On 9/1/06, "Fabrício F. Kammer" <[hidden email]> wrote:
> Do you have an example of how to use this loop on a thread?
>
> Sorry, but I don't know threads very well.

Yes, I have a very big example. It´s a GUI for a digital oscilloscope board.

The thread code is on the medidor.pas unit

You can download it´s source code and full documentation here:

http://eletronicalivre.incubadora.fapesp.br/portal/english/oscilloscope/

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Timer for Windows/Linux

"Fabrício F. Kammer"
Thank you very much Felipe.

Where are you from?

I'm Brazilian too, from Conchal/SP.

[]s

Fabrício

Felipe Monteiro de Carvalho escreveu:

> On 9/1/06, "Fabrício F. Kammer" <[hidden email]> wrote:
>> Do you have an example of how to use this loop on a thread?
>>
>> Sorry, but I don't know threads very well.
>
> Yes, I have a very big example. It´s a GUI for a digital oscilloscope
> board.
>
> The thread code is on the medidor.pas unit
>
> You can download it´s source code and full documentation here:
>
> http://eletronicalivre.incubadora.fapesp.br/portal/english/oscilloscope/
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Timer for Windows/Linux

Felipe Monteiro de Carvalho
On 9/1/06, "Fabrício F. Kammer" <[hidden email]> wrote:
> Where are you from?

I'm from São Paulo.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal