[fpc-pascal] One experience with the unit serial
Holger Bruns
holger.bruns at gmx.net
Thu Nov 19 14:30:02 CET 2009
Brad Campbell schrieb:
> Holger Bruns wrote:
>> Hi,
>>
>> one more question regarding the unit serial. I use the following
>> function to get one single byte form a serial port, which has been
>> open before with seropen:
>>
>> function getdata(inhandle: tserialhandle; var recdata: char): longint;
>> begin
>> fillchar(inbuffer, sizeof(inbuffer), #0);
>> getdata := serread(inhandle, inbuffer[0], 1);
>> recdata := inbuffer[0]
>> end;
>>
>> I repeat this function as long as I need to read data from a serial
>> port, byte by byte. One interesting error occurs at the 52478th byte:
>> serread returns 0 instead of 1. How can I get it work properly?
>
> The answer to that probably depends on a bit more information that you
> have provided in your question.
Thank you for your answer. I played with different baud rates. The
sender delivers a stream of bytes. The faster a transmission rate is,
the less amount of data can be received. This leds me to two
conclusions: At first, there must be a queue for incoming data despite I
ruled out a queue with an inbuffer with the length 1. Secondly, a
timeout error appeared, the sender gave up. For now, I try to solve this
problem with slower baud rates. Since iopl is still not available to fpc
in its 64-bit-version, I should move to c for future port programming.
For that matter it could be interesting to know two more things: How can
I call external executable code like "setserial /dev/ttySx none" and
secondly, how can I use c functions like pascal functions?
>
> Are you sure you have data waiting for you?
Yes.
Holger
More information about the fpc-pascal
mailing list