[fpc-pascal] Using built-in serial instead of synaser and the like for Linux console app?
Michael Van Canneyt
michael at freepascal.org
Tue Sep 1 14:21:44 CEST 2020
On Tue, 1 Sep 2020, Bo Berglund via fpc-pascal wrote:
> On Tue, 01 Sep 2020 10:22:08 +0200, Bo Berglund via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>
>> Maybe I could tie the timeout to the actual baud used? Slower speeds
>> use longer timeout etc? Timeout could be set to the time it takes to
>> transfer the number of bytes to read?
>>
>> And both arguments could be made properties of the class such that the
>> user can tweak performance a bit?
>
> I tried to do this:
>
> TComPortReadThread=class(TThread)
> private
> FBuffer: TBytes;
> FPacketSize: integer; default 10;
> FReadTimeout: integer; default 10;
> public
> MustDie: boolean;
> Owner: TFpSerialPort;
> property ReadPacketSize: integer read FPacketSize write
> FPacketSize; //How many bytes to read in each operation
> property ReadTimeout: integer read FReadTimeout write
> FReadTimeout; //Max time to wait for data in thread
> protected
> procedure CallEvent;
> procedure Execute; override;
> published
> property Terminated;
> end;
>
> But I cannot set the default value of the two new fields FPacketSize
> and FReadTimeout, I get an error in the above code (and variations of
> the same).
> Is there no way to declare a property to have a default non-zero
> value?
You must set it on the property:
Property property ReadPacketSize: integer read FPacketSize write FPacketSize default 10;
Note that this does not actually set the property to the indicated value. It
is only a hint for the streaming system:
You must still set the default value in the constructor.
>
> Note that the thread itself has no idea what is the baudrate in use so
> it cannot calculate the proper value at the start of Execute...
> And there is no Create method either that I can use.
The constructor can always be overridden.
Michael.
More information about the fpc-pascal
mailing list