[fpc-pascal] TFPTimer does not fire, why?

2020-09-07 Thread Bo Berglund via fpc-pascal
Ì have a problem using TFpTimer on Linux (FPC 3.0.4, Lazarus 2.0.8 on
Raspbian).

The application is a small GUI test app where I have added a timer in
order to update the display with incoming data.
So I have it set up like this:

{$mode Delphi}
interface
uses
  ...
  fptimer,
  ...
type

  TfrmMain = class(TForm)
  ...  
  private
FTimCheckInputs: TFpTimer;
  ...
procedure OnTimCheckInputs(Sender: TObject);
  ...

implementation

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  ...
  FTimCheckInputs := TFpTimer.Create(NIL);
  FTimCheckInputs.OnTimer := OnTimCheckInputs;
  FTimCheckInputs.Interval := 500; // 500 ms latency
  ...
end;

procedure TfrmMain.OnTimCheckInputs(Sender: TObject);
begin
  ShowInByte; //<== This is NEVER reached!
end;

procedure TfrmMain.btnOpenComClick(Sender: TObject);
begin
  ...
  if FRemote.OpenPort(edComPort.Text, StrToInt(cbxBaud.Text)) then
  begin
...
FTimCheckInputs.Enabled := true;
  end
  else
  begin
...
FTimCheckInputs.Enabled := false;
  end;
end;

procedure TfrmMain.FormClose(Sender: TObject; var CloseAction:
TCloseAction);
begin
  FTimCheckInputs.Enabled := false;
  FTimCheckInputs.Free;
  ...
end;

When I click the btnOpenCom button I get to the button event and the
code reachers the line:

  FTimCheckInputs.Enabled := true;

So presumably here the timer should start and fire after 500 ms as set
up in the FormCreate procedure.
But it never does! I do not get into this at all. I have put a
breakpoint there but it never fires, whereas other breakpoints do fire
so I can see that for example btnOpenComClick fires off properly and
the timer should be enabled.

And before you ask, I *have* this at the beginning of the lpr file:
uses
  {$IFDEF UNIX}
  cthreads, 
  {$ENDIF}


Why does the FpTimer event not fire?
I am assuming the Interval property is in milliseconds...

When I step through the code and reach the place where the timer is
enabled the text that appears when I hover over the Enabled keyword is
very strange:

"FTimCheckInputs.Enabled = TYPE FPTIMER has no component named
ENABLED.
published property TFPTimer.Enabled:Boolean"

Is it not possible to start the timer using Enabled?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TFPTimer does not fire, why?

2020-09-07 Thread Michael Van Canneyt via fpc-pascal


On Mon, 7 Sep 2020, Bo Berglund via fpc-pascal wrote:


Ì have a problem using TFpTimer on Linux (FPC 3.0.4, Lazarus 2.0.8 on
Raspbian).

The application is a small GUI test app where I have added a timer in
order to update the display with incoming data.
So I have it set up like this:

{$mode Delphi}
interface
uses
 ...
 fptimer,
 ...
type

 TfrmMain = class(TForm)
 ...
 private
   FTimCheckInputs: TFpTimer;
 ...
   procedure OnTimCheckInputs(Sender: TObject);
 ...

implementation

procedure TfrmMain.FormCreate(Sender: TObject);
begin
 ...
 FTimCheckInputs := TFpTimer.Create(NIL);
 FTimCheckInputs.OnTimer := OnTimCheckInputs;
 FTimCheckInputs.Interval := 500; // 500 ms latency
 ...
end;

procedure TfrmMain.OnTimCheckInputs(Sender: TObject);
begin
 ShowInByte; //<== This is NEVER reached!
end;

procedure TfrmMain.btnOpenComClick(Sender: TObject);
begin
 ...
 if FRemote.OpenPort(edComPort.Text, StrToInt(cbxBaud.Text)) then
 begin
   ...
   FTimCheckInputs.Enabled := true;
 end
 else
 begin
   ...
   FTimCheckInputs.Enabled := false;
 end;
end;

procedure TfrmMain.FormClose(Sender: TObject; var CloseAction:
TCloseAction);
begin
 FTimCheckInputs.Enabled := false;
 FTimCheckInputs.Free;
 ...
end;

When I click the btnOpenCom button I get to the button event and the
code reachers the line:

 FTimCheckInputs.Enabled := true;

So presumably here the timer should start and fire after 500 ms as set
up in the FormCreate procedure.
But it never does! I do not get into this at all. I have put a
breakpoint there but it never fires, whereas other breakpoints do fire
so I can see that for example btnOpenComClick fires off properly and
the timer should be enabled.

And before you ask, I *have* this at the beginning of the lpr file:
uses
 {$IFDEF UNIX}
 cthreads,
 {$ENDIF}


Why does the FpTimer event not fire?


Do you call checksynchronize at regular intervals ? The default timer is
threaded, and the OnTimer event is called in the main thread. For this to
work, you need to call checksynchronize at regular intervals in your main
thread.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TFPTimer does not fire, why?

2020-09-07 Thread Bo Berglund via fpc-pascal
On Mon, 7 Sep 2020 12:40:07 +0200 (CEST), Michael Van Canneyt via
fpc-pascal
 wrote:

>> Why does the FpTimer event not fire?
>
>Do you call checksynchronize at regular intervals ? The default timer is
>threaded, and the OnTimer event is called in the main thread. For this to
>work, you need to call checksynchronize at regular intervals in your main
>thread.

Before I read your reply I tested another thing:
I dropped a regular timer from the component palette onto the form
intending to use that instead of FpTimer.

So I made an event function by doubleclicking the event as usual and
added the same call there.
I set the new timer to disabled by default so I can enable it on
successful port open like the FpTimer.

Once all that was done I again stepped through the application with
breakponts in both event functions and amazingly the FpTimer event now
fired! And after it was done the new timer also called its event...

In fact it now seems to work where it did not before.

So next I *removed* the newly dropped timer and its references in the
code and now the FpTimer still works. How very strange!

Concerning calling CheckSynchronize I do not really know where it can
be done...
I think you do not mean that I should put a timer on the main form and
then in its OnTimer event call CheckSynchronize?
This program is a GUI application and I do not know where one could
put a call like that.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TFPTimer does not fire, why?

2020-09-07 Thread Michael Van Canneyt via fpc-pascal



On Mon, 7 Sep 2020, Bo Berglund via fpc-pascal wrote:


On Mon, 7 Sep 2020 12:40:07 +0200 (CEST), Michael Van Canneyt via
fpc-pascal
 wrote:


Why does the FpTimer event not fire?


Do you call checksynchronize at regular intervals ? The default timer is
threaded, and the OnTimer event is called in the main thread. For this to
work, you need to call checksynchronize at regular intervals in your main
thread.


Before I read your reply I tested another thing:
I dropped a regular timer from the component palette onto the form
intending to use that instead of FpTimer.


That is because you then add the LCL to the application, and in their
application object, they call checksynchronize on idle.

Even if you remove the LCL timer, the checksynchronize still will do it's job.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to implement a circular buffer object in pascal?

2020-09-07 Thread Brian via fpc-pascal
Bo,

Most of the users on this forum have never interfaced with hardware , as you
can see from the responses. Those who have interfaced with hardware have
developed circular buffers which they  know work , and they reuse them again
and again.

I will describe in general terms the structure a circular buffer implemented
to receive data , as it is usually more difficult to received the data than
to send it due to the asynchronism between the sender and receiver.
It has been used for many years , starting in 16bit-DOS , the 32bit-DPMI
using interrupt handlers , then Linux using threads. The concept is the same
for versions.

The following assumes you are receiving data from a sender , and in this
case the sender and receiver are connected via 1Gbps Ethernet using Synapse
(works really well).



A thread receives data into an array of byte. RxBuffer : Array[0..1500] of
byte  ... and copies the number of bytes received into a circular buffer ,
which is an array of RxBuffer.

In pseudo code it looks like this ...
CircularBuffer : Array[0..N] of RxBuffer
There is a ReadIndex and a WriteIndex , both longword or longint.

The thread moves the data into the circular buffer continuously  increase
the WriteIndex each write of RxBuffer data. If the WriteIndex > N then
WriteIndex := 0 , otherwise it is increased by 1.

The main loop (below)  moves the byte data using MOVE from CircBuffer to
whatever structure it represents , increase the ReadIndex by one and decodes
the data as needed.

 If ReadIndex <> WriteIndex then
  .. do the work as described above and increment the ReadIndex

I use the Free Pascal unit which allows suspending the thread while the
ReadIndex is being increased. In the old DOS/DPMI days we would disable
interrupts briefly.

If you are innterested I can send you code snippets showing exactly how to
implement the circular buffer.

Regards
Brian
 







--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Why can I not build fpc 3.0.4 with ppcarm 3.0.0 or 3.0.4?

2020-09-07 Thread Bo Berglund via fpc-pascal
I have a script I use all the time to install FPC/Lazarus on Raspberry
Pi units when I configure for development.



Today when I was setting up a Raspberry PiZero I was hit with this
message when I was going to build fpc 3.0.4 (sources checked out from
svn):

Makefile:2790: *** The only supported starting compiler version is
3.0.2. You are trying to build with ..  Stop.

The script downloads ppcarm from my website where I have stuffed 3.0.0
in a tar archive to use for this purpose. Has worked on more than 10
RPi units so far. I never before saw a requirement for ppcarm 3.0.2...

Anyway I know that fpc can build itself so I made an archive for
ppcarm 3.0.4 and uploaded that to the website and modified the script.
But no go, same message...

Any ideas?

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Ethernet Relays

2020-09-07 Thread James Richters via fpc-pascal
When I try to compile either of the examples below, I get Error: Identifier not 
found "ESocketError" 
Any ideas?  

James


Yes, catch the ESocketError in a try..except:

Try
   S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
except
   On E: ESocketError do
 Writeln('Could not connect to server'); end;

> Is there a way to change the amount of time before the timeout?

Yes, but then you need to create an instance, i.e. the Simple* commands won't 
do that for you:

Instead, it will look like this:

uses fphttpclient;

Var
   C : TFPHTTPClient;

begin
   C:=TFPHTTPClient.Create(Nil);
   try
  try
C.ConnectTimeout:=10; // Or whatever you think is good
C.Get('http://10.10.01.01/3/15');
  except
On E: ESocketError do
  Writeln('Could not connect to server');
  end;
   finally
 C.Free;
   end;
end;

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why can I not build fpc 3.0.4 with ppcarm 3.0.0 or 3.0.4?

2020-09-07 Thread Bo Berglund via fpc-pascal
On Tue, 08 Sep 2020 00:59:51 +0200, Bo Berglund via fpc-pascal
 wrote:

>Today when I was setting up a Raspberry PiZero I was hit with this
>message when I was going to build fpc 3.0.4 (sources checked out from
>svn):
>
>Makefile:2790: *** The only supported starting compiler version is
>3.0.2. You are trying to build with ..  Stop.
>

It turns out that this was a grossly misleading error message!
The real problem was that the RPiZero is arm v6 and the seed compiler
downloaded was arm v7!

After changing to ppcarm 3.0.0 for arm6 the build works.


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Ethernet Relays

2020-09-07 Thread Michael Van Canneyt via fpc-pascal


Add the ssockets unit to your uses clause.

Michael

On Mon, 7 Sep 2020, James Richters via fpc-pascal wrote:

When I try to compile either of the examples below, I get Error: Identifier not found "ESocketError" 
Any ideas? 


James


Yes, catch the ESocketError in a try..except:

Try
  S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
except
  On E: ESocketError do
Writeln('Could not connect to server'); end;


Is there a way to change the amount of time before the timeout?


Yes, but then you need to create an instance, i.e. the Simple* commands won't 
do that for you:

Instead, it will look like this:

uses fphttpclient;

Var
  C : TFPHTTPClient;

begin
  C:=TFPHTTPClient.Create(Nil);
  try
 try
   C.ConnectTimeout:=10; // Or whatever you think is good
   C.Get('http://10.10.01.01/3/15');
 except
   On E: ESocketError do
 Writeln('Could not connect to server');
 end;
  finally
C.Free;
  end;
end;

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal