[fpc-pascal] Access to RS232 ports with fpc

Holger Bruns holger.bruns at gmx.net
Tue Nov 3 01:07:30 CET 2009


Marc Santhoff schrieb:
>
> sDefaultPort: string = '/dev/cuaa0'; { this would be /dev/ttyS2 for you }
>
> fPort = sDefaultPort;
>
> { Init }
> fCom := SerOpen(fPort);
> if (fCom > -1) then begin
>   SerSetParams(fCom, 1200, 7, NoneParity, 2, []);
> end else begin
>   writeln('Metex: failed to open port');
>   n := GetLastOSError;
> end
>
> { Reading }
> var
>   inbuf: array[0..14] of char;
> begin
>   fillchar(inbuf, sizeof(inbuf), #0);
>   res := SerRead(fCom, inbuf[0], 14); { last figure would be 1000 for you, bytes to read }
>   if (res < 0) then
>     { signal error }
> ...
>
> That way I use serial ports successfully on FreeBSD and Windows.
>
>   

This helps a lot. Thank you. This was the example I was looking for. My 
fault was the declaration of inbuffer: array of char, and I guess, I did 
not understand how to deal with hidden pointers. Now I've got this idea 
from you and hope so far, I can move on.

Best regards, Holger





More information about the fpc-pascal mailing list