[fpc-pascal] problem setting up serial port

Marc Santhoff M.Santhoff at t-online.de
Fri Mar 10 15:51:46 CET 2006


Hi,

I'm trying to use a serial port at 1200baud, 7N2 with this code
sequence:

<snip>
fCom := fpOpen('/dev/cuaa0', O_RDWR OR O_NOCTTY );//OR O_NONBLOCK);
if (fCom < 0) then begin
	writeln(stderr, 'Couldn''t open serial port.');
	halt(1);
end;

r := 0;
fillchar(tios, sizeof(tios), #0);

cfsetispeed(tios, B1200);
cfsetospeed(tios, B1200);

tios.c_cflag := CREAD or CLOCAL or CS7 or CSTOPB;
tios.c_oflag := 0;
tios.c_iflag := IGNBRK OR IGNPAR;
tios.c_lflag := 0;
r := tcsetattr(fCom, TCSANOW, tios);
if (r = -1) then begin
	writeln(stderr, 'tcsetattr failed!');
	fpClose(fCom);
	halt(1);
end;
</snip>

and all I get when running it is: 'tcsetattr failed!'. The rights are
okay and running as root does make no difference. The hardware is
working, connections are checked okay ... another program doing mostly
the same is working as it should.

Maybe I have looked at it for too long, where is the problem?

TIA,
Marc





More information about the fpc-pascal mailing list