Re: [fpc-pascal] SerReadTimeout question

2022-09-19 Thread Christo Crause via fpc-pascal
On Mon, Sep 19, 2022 at 7:51 AM Christo Crause 
wrote:

>
>
> On Mon, 19 Sep 2022, 03:18 James Richters via fpc-pascal, <
> fpc-pascal@lists.freepascal.org> wrote:
>
>> I can't seem to find any documentation or SerRead or SerReadTimeout..
>> searching for either along with Freepascal doesn't get me any results.
>> If it exists somewhere and I am just missing it, can someone tell me where
>> it is?
>>
>> Anyway, what I'm trying to figure out is when the timeout timer starts...
>>
>
> FPC uses the OS provided functionality to interact with the serial port.
> On Windows the timeout seems to start when the read request is made (
> https://learn.microsoft.com/en-us/previous-versions/ff547486(v=vs.85)).
> On POSIX (at least Linux) it depends on the specific set of flags specified
> , scroll down to the discussion on canonical/noncanonical mode for the
> details (https://linux.die.net/man/3/termios).
>

A bit more information after peeking into the source code: on win32 the
timeout information can be read or set using Get/SetCommTimeouts. The
COMMTIMEOUTS structure (
https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts)
contains a read interval timeout and total timeouts for read & write
operations. SerReadTimeout sets the ReadTotalTimeoutConstant value, so
basically the total timeout duration.

On Linux SerReadTimeout uses a fpSelect on the handle with the specified
timeout, so in principle it is the same behaviour as on Windows, i.e. a
total timeout.

While both OSs provide some functionality to specify inter character
timeouts, FPC does not directly expose this functionality in the Serial
unit.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get TMethod from function reference

2022-09-19 Thread Hairy Pixels via fpc-pascal



> On Sep 19, 2022, at 4:17 PM, Sven Barth  wrote:
> 
> === code begin ===
> 
> Proc1 := @c.OnChange;
> Proc2 := @c.OnClick;
> Proc3 := @c2.OnChange;
> 
> === code end ===
> 
> Will result in the following capture object:
> 
> === code begin ===
> 
> type
>   TCapturer = class(TInterfacedObject, TProc1, TProc2, TProc3)
> m1: TNotifyEvent;
> m2: TNotifyEvent;
> m3: TNotifyEvent;
> 
> procedure Anonymous1(Sender :TObject); //will call m1
> procedure Anonymous2(Sender: TObject); // will call m2
> procedure Anonymous3(Sender: TObject); // will call m3
>   end;
> 
> === code end ===
> 

Interesting, so all reference assignments in a scope generate a single 
TCapturer? Yeah that makes what I want impossible unless specific support was 
added to get back one of those fields.

So I guess I need to make a record wrapper for the reference stores the target 
class. Thankfully you fixed that crash so I can do this now. :)

Regards,
Ryan Joseph

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


Re: [fpc-pascal] SerReadTimeout question

2022-09-19 Thread Alexey Torgashin via fpc-pascal
I wrote this info to new page https://wiki.freepascal.org/Serial_unit , 
welcome to add more info there.

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


Re: [fpc-pascal] Get TMethod from function reference

2022-09-19 Thread Sven Barth via fpc-pascal
Hairy Pixels  schrieb am So., 18. Sep. 2022, 02:50:

>
>
> > On Sep 17, 2022, at 10:57 PM, Sven Barth 
> wrote:
> >
> > === code begin ===
> >
> > type
> >   TProc = reference to procedure;
> >   TMyClass = class
> > procedure DoThis;
> >   end;
> >
> >   TCapturer = class(TInterfacedObject, TProc)
> > m: procedure of object;
> > procedure Anonymous1;
> >
> > procedure TProc.Invoke = Anonymous1;
> >   end;
> >
> > var
> >   p: TProc;
> >   c: TMyClass;
> >   capturer: TCapturer;
> >   capturer_keepalive: IUnknown;
> > begin
> >   capturer := TCapturer.Create;
> >   capturer_keepalive := capturer;
> >   c := TMyClass.Create;
> >   capturer.m := @c.DoThis;
> >   p := capturer as TProc;
> > end.
> >
> > === code end ===
>
> Well if p is effectively TCapturer then you COULD get back TMethod from m
> (procedure of object) but the compiler doesn’t have a method generated for
> this.
>

No, you can't, because if you have multiple such assignments inside one
function the capture object is shared and you'd have multiple fields where
you wouldn't know to which anonymous function is belongs:

=== code begin ===

Proc1 := @c.OnChange;
Proc2 := @c.OnClick;
Proc3 := @c2.OnChange;

=== code end ===

Will result in the following capture object:

=== code begin ===

type
  TCapturer = class(TInterfacedObject, TProc1, TProc2, TProc3)
m1: TNotifyEvent;
m2: TNotifyEvent;
m3: TNotifyEvent;

procedure Anonymous1(Sender :TObject); //will call m1
procedure Anonymous2(Sender: TObject); // will call m2
procedure Anonymous3(Sender: TObject); // will call m3
  end;

=== code end ===

Please note that you can't rely on the index as other converted anonymous
methods (maybe with the same signature) might be intermixed. So you won't
know which field is used by what method.

I read your announcement email again last night and saw that TProc could
> actually be subclassed which opens up the possibility to read the field (if
> it’s not intentionally hidden) or use the RTTI perhaps even. Is that
> possible? If the field “m" is hidden I would say that should be exposed for
> the purposes of subclassing .
>

When you subclass a function reference you can not assign any function to
it, but you really need to use a self written class type that you use as
instance.

Regards,
Sven

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