I am using FPC Serial to communicate with a device i have with PC.
The transmitting part (SerWrite) works nicely I love it. But I am having issues with SerRead. Hope you can help me.
The port opening is no issue as it works with SerWrite, the reading part code is as follows:
{$H+}{$LongStrings ON} // just in case
...
implementation
var
s: String;
In a TimerCallback, i have this:
procedure TForm1.readTimerTimer(Sender: TObject);
begin
s := '';
WriteLn('read');
status := SerRead(serialhandle,s,10);
end;
This application is windows app but I enabled the console so I can see WriteLn in console.
The issue crash happens at
second time reading (since I can see first 'read' in console but not subsequent ones), it seems 's' becomes not available anymore for some reason.
Exception: SIGSEGV error and debugger just show assembly language that I dont understand.
The timer is called every 500ms. And the data sent from device is about every 500ms, $00 $11 $22.... $FF (packet of 16 bytes of arbitrary values). I did try writeln(inttostr(status)), and yes first call of timer shows '10' (ie length of data received) was successful. But I can't access the 's' variable. it just crashes.