[fpc-pascal] One experience with the unit serial

Brad Campbell brad at wasp.net.au
Thu Nov 19 09:20:06 CET 2009


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.

Is your port open blocking or non-blocking?

Are you checking the handle for readability using Select() prior to trying to read a byte from it?

Have you traced the program using strace to see what the syscall is actually returning from the kernel?

Are you sure you have data waiting for you?

Brad
-- 
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.



More information about the fpc-pascal mailing list