Lazarus
Programming => Packages and Libraries => Topic started by: hakelm on April 04, 2012, 10:35:59 am
-
In synaser.pas (007.002.000) line 1905 "SerialCheck(fpioctl(integer(FHandle), TCFLSH, TCIOFLUSH)); " causes a compilation error under LInux.
I haven't been able to figure out what to replace TCIOFLUSH with but I added oldlinux to my units and replaced line 1905 with
SerialCheck(tcflush(integer(FHandle), TCIOFLUSH));
and this seems to work.
Is there anyone who knows to what structure and data the 3rd argument in fpioctl(integer(FHandle), TCFLSH, @????)); should point to?
H
-
Just cast TCIOFLUSH to a pointer. The problem has been solved in the svn version of synaser:
{$IFNDEF MSWINDOWS}
procedure TBlockSerial.Purge;
begin
{$IFNDEF FPC}
SerialCheck(ioctl(FHandle, TCFLSH, TCIOFLUSH));
{$ELSE}
{$IFDEF DARWIN}
SerialCheck(fpioctl(FHandle, TCIOflush, Pointer(PtrInt(TCIOFLUSH))));
{$ELSE}
SerialCheck(fpioctl(FHandle, TCFLSH, Pointer(PtrInt(TCIOFLUSH))));
{$ENDIF}
{$ENDIF}
FBuffer := '';
ExceptCheck;
end;
{$ELSE}
-
Thanks a lot,
this works even if I don't grasp the syntax.
H
-
I get it, it is not what is pointed at, but the the pointer itself that is the datum.
-
Just cast TCIOFLUSH to a pointer. The problem has been solved in the svn version of synaser:
{$IFNDEF MSWINDOWS}
procedure TBlockSerial.Purge;
begin
{$IFNDEF FPC}
SerialCheck(ioctl(FHandle, TCFLSH, TCIOFLUSH));
{$ELSE}
{$IFDEF DARWIN}
SerialCheck(fpioctl(FHandle, TCIOflush, Pointer(PtrInt(TCIOFLUSH))));
{$ELSE}
SerialCheck(fpioctl(FHandle, TCFLSH, Pointer(PtrInt(TCIOFLUSH))));
{$ENDIF}
{$ENDIF}
FBuffer := '';
ExceptCheck;
end;
{$ELSE}
That code is wrong. *BSD does not support TCFLSH (which is Linux only, or maybe Solaris too)
Smartest would be to simply use termio.tcflush
-
That code is wrong. *BSD does not support TCFLSH (which is Linux only, or maybe Solaris too)
Smartest would be to simply use termio.tcflush
Solaris does support TCFLSH. termio.tcflush for solaris is implemented in fpc as
Function TCFlush(fd,qsel:cint):cint; {$ifdef VER2_0}inline;{$endif}
begin
TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
end;
From the doc I found that TIOCFLUSH expects a pointer to an int and not the int itself (A bug report found here: http://wesunsolve.net/bugid/id/4143249). TCFLSH expects the int.
The other problem is that the tcflush parameters for solaris are defined for TCFlush:
TCIFLUSH = 0;
TCOFLUSH = 1;
TCIOFLUSH = 2;
while those for bsd match the TIOCFLUSH values:
TCIFLUSH =1;
TCOFLUSH =2;
TCIOFLUSH =3;
When I look at the implementation of NetBSD (http://www.koders.com/c/fidB1DBDDE277209C66898CA4CFE116A72C4CD38D46.aspx?s=cdefs#L36) the same pointer problem exists in the FPC implementation:
tcflush(fd, which)
int fd, which;
{
int com;
switch (which) {
case TCIFLUSH:
com = FREAD;
break;
case TCOFLUSH:
com = FWRITE;
break;
case TCIOFLUSH:
com = FREAD | FWRITE;
break;
default:
errno = EINVAL;
return (-1);
}
return (ioctl(fd, TIOCFLUSH, &com));
}
Function TCFlush(fd,qsel:cint):cint;
begin
TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
end;