I am trying to port a Windows Service application written in Delphi7/2007 back in 2004-2012 to FPC/Lazarus so it can later be moved to Linux.
This application talks via RS232 to a data collection system for control and data retrieval.
Unfortunately there was no built-in support in Delphi for serial comm so we used external components for this, at first a very simple TSerial component from a developer in the UK and later Turbo Async Pro.
I have conditionals in the code to switch between the two components.
The TSerial component is contained in a single source file whereas AsyncPro is splitting its serial component in a large set of units, very hard to navigate.
In both cases the application is written using the
event model for receiving data and non-blocking send functions.
I would rather not port these components (at least not Async Pro) since they are inherently Windows centric.
Instead I want to use the FPC built-in Serial component, but it needs to be packaged with a wrapper such that an OnRxData event is added and such that there is a non-blocking transmit.
It must be possible to set the RX/Tx buffer size too.
What is the best way to accomplish the move of serial comm to FPC/Lazarus in such a way that it is portable to Linux?
Is there a way to add receive events and non-blocking send function to the built-in serial object in FPC?
I mean if I make a custom component by inheriting from the built-in serial, how can these extra features be added?
Maybe it has already been done?
EDIT:After posting I found LazSerial, which can be installed using OnLine PackageManager.
But when I look at it it has these read and write functions defined like this:
// read data from port
function DataAvailable: boolean;
function ReadData: string;
// function ReadBuffer(var buf; size: integer): integer;
// write data to port
function WriteData(data: string): integer;
function WriteBuffer(var buf; size: integer): integer;
As you can see the ReadBuffer method is not implemented.
Since I will read/write non-textual binary data I need a Read method that can handle binary buffers and not work with strings. Strings are hard to use since there is inherent interpretation of unicode and such, which is not allowed on binary data.
How is this solved for binary transfers? On the send side there is a WriteBuffer() method but not for receiving data....