synaser.pas - handling of FHandle is capable to use 64-bit based handlers.

git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@121 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
geby 2010-01-28 14:38:59 +00:00
parent fcfa5d7a70
commit 583afbc35e

View File

@ -169,7 +169,7 @@ const
CS7fix = $0000020; CS7fix = $0000020;
type type
TDCB = packed record TDCB = record
DCBlength: DWORD; DCBlength: DWORD;
BaudRate: DWORD; BaudRate: DWORD;
Flags: Longint; Flags: Longint;
@ -189,8 +189,11 @@ type
PDCB = ^TDCB; PDCB = ^TDCB;
const const
// MaxRates = 30; {$IFDEF LINUX}
MaxRates = 30;
{$ELSE}
MaxRates = 19; //FPC on some platforms not know high speeds? MaxRates = 19; //FPC on some platforms not know high speeds?
{$ENDIF}
Rates: array[0..MaxRates, 0..1] of cardinal = Rates: array[0..MaxRates, 0..1] of cardinal =
( (
(0, B0), (0, B0),
@ -212,8 +215,9 @@ const
(57600, B57600), (57600, B57600),
(115200, B115200), (115200, B115200),
(230400, B230400), (230400, B230400),
(460800, B460800){, (460800, B460800)
(500000, B500000), {$IFDEF LINUX}
,(500000, B500000),
(576000, B576000), (576000, B576000),
(921600, B921600), (921600, B921600),
(1000000, B1000000), (1000000, B1000000),
@ -223,7 +227,8 @@ const
(2500000, B2500000), (2500000, B2500000),
(3000000, B3000000), (3000000, B3000000),
(3500000, B3500000), (3500000, B3500000),
(4000000, B4000000)} (4000000, B4000000)
{$ENDIF}
); );
{$ENDIF} {$ENDIF}
@ -759,7 +764,7 @@ end;
class function TBlockSerial.GetVersion: string; class function TBlockSerial.GetVersion: string;
begin begin
Result := 'SynaSer 6.3.5'; Result := 'SynaSer 7.4.0';
end; end;
procedure TBlockSerial.CloseSocket; procedure TBlockSerial.CloseSocket;
@ -769,7 +774,7 @@ begin
Purge; Purge;
RTS := False; RTS := False;
DTR := False; DTR := False;
FileClose(integer(FHandle)); FileClose(FHandle);
end; end;
if InstanceActive then if InstanceActive then
begin begin
@ -856,6 +861,7 @@ procedure TBlockSerial.Config(baud, bits: integer; parity: char; stop: integer;
softflow, hardflow: boolean); softflow, hardflow: boolean);
begin begin
FillChar(dcb, SizeOf(dcb), 0); FillChar(dcb, SizeOf(dcb), 0);
GetCommState;
dcb.DCBlength := SizeOf(dcb); dcb.DCBlength := SizeOf(dcb);
dcb.BaudRate := baud; dcb.BaudRate := baud;
dcb.ByteSize := bits; dcb.ByteSize := bits;
@ -923,7 +929,10 @@ begin
{$ELSE} {$ELSE}
FHandle := THandle(fpOpen(FDevice, O_RDWR or O_SYNC)); FHandle := THandle(fpOpen(FDevice, O_RDWR or O_SYNC));
{$ENDIF} {$ENDIF}
SerialCheck(integer(FHandle)); if FHandle = INVALID_HANDLE_VALUE then //because THandle is not integer on all platforms!
SerialCheck(-1)
else
SerialCheck(0);
{$IFDEF LINUX} {$IFDEF LINUX}
if FLastError <> sOK then if FLastError <> sOK then
if FLinuxLock then if FLinuxLock then
@ -937,7 +946,10 @@ begin
FDevice := '\\.\COM' + IntToStr(FComNr + 1); FDevice := '\\.\COM' + IntToStr(FComNr + 1);
FHandle := THandle(CreateFile(PChar(FDevice), GENERIC_READ or GENERIC_WRITE, FHandle := THandle(CreateFile(PChar(FDevice), GENERIC_READ or GENERIC_WRITE,
0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0)); 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0));
SerialCheck(integer(FHandle)); if FHandle = INVALID_HANDLE_VALUE then //because THandle is not integer on all platforms!
SerialCheck(-1)
else
SerialCheck(0);
ExceptCheck; ExceptCheck;
if FLastError <> sOK then if FLastError <> sOK then
Exit; Exit;
@ -955,7 +967,7 @@ begin
if not TestCtrlLine then {HGJ} if not TestCtrlLine then {HGJ}
begin begin
SetSynaError(ErrNoDeviceAnswer); SetSynaError(ErrNoDeviceAnswer);
FileClose(integer(FHandle)); {HGJ} FileClose(FHandle); {HGJ}
{$IFDEF LINUX} {$IFDEF LINUX}
if FLinuxLock then if FLinuxLock then
cpomReleaseComport; {HGJ} cpomReleaseComport; {HGJ}
@ -991,7 +1003,7 @@ begin
RTS := True; RTS := True;
end; end;
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
result := FileWrite(integer(Fhandle), Buffer^, Length); result := FileWrite(Fhandle, Buffer^, Length);
serialcheck(result); serialcheck(result);
{$ELSE} {$ELSE}
FillChar(Overlapped, Sizeof(Overlapped), 0); FillChar(Overlapped, Sizeof(Overlapped), 0);
@ -1098,7 +1110,7 @@ begin
if PreTestFailing then {HGJ} if PreTestFailing then {HGJ}
Exit; {HGJ} Exit; {HGJ}
LimitBandwidth(Length, FMaxRecvBandwidth, FNextRecv); LimitBandwidth(Length, FMaxRecvBandwidth, FNextRecv);
result := FileRead(integer(FHandle), Buffer^, length); result := FileRead(FHandle, Buffer^, length);
serialcheck(result); serialcheck(result);
{$ELSE} {$ELSE}
var var
@ -1418,7 +1430,7 @@ end;
function TBlockSerial.WaitingData: integer; function TBlockSerial.WaitingData: integer;
begin begin
{$IFNDEF FPC} {$IFNDEF FPC}
serialcheck(ioctl(integer(FHandle), FIONREAD, @result)); serialcheck(ioctl(FHandle, FIONREAD, @result));
{$ELSE} {$ELSE}
serialcheck(fpIoctl(FHandle, FIONREAD, @result)); serialcheck(fpIoctl(FHandle, FIONREAD, @result));
{$ENDIF} {$ENDIF}
@ -1601,7 +1613,7 @@ end;
procedure TBlockSerial.SetCommState; procedure TBlockSerial.SetCommState;
begin begin
DcbToTermios(dcb, termiosstruc); DcbToTermios(dcb, termiosstruc);
SerialCheck(tcsetattr(integer(FHandle), TCSANOW, termiosstruc)); SerialCheck(tcsetattr(FHandle, TCSANOW, termiosstruc));
ExceptCheck; ExceptCheck;
end; end;
{$ELSE} {$ELSE}
@ -1617,7 +1629,7 @@ end;
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
procedure TBlockSerial.GetCommState; procedure TBlockSerial.GetCommState;
begin begin
SerialCheck(tcgetattr(integer(FHandle), termiosstruc)); SerialCheck(tcgetattr(FHandle, termiosstruc));
ExceptCheck; ExceptCheck;
TermiostoDCB(termiosstruc, dcb); TermiostoDCB(termiosstruc, dcb);
end; end;
@ -1662,9 +1674,9 @@ begin
else else
FModemWord := FModemWord and not TIOCM_DTR; FModemWord := FModemWord and not TIOCM_DTR;
{$IFNDEF FPC} {$IFNDEF FPC}
ioctl(integer(FHandle), TIOCMSET, @FModemWord); ioctl(FHandle, TIOCMSET, @FModemWord);
{$ELSE} {$ELSE}
fpioctl(integer(FHandle), TIOCMSET, @FModemWord); fpioctl(FHandle, TIOCMSET, @FModemWord);
{$ENDIF} {$ENDIF}
{$ELSE} {$ELSE}
if Value then if Value then
@ -1693,9 +1705,9 @@ begin
else else
FModemWord := FModemWord and not TIOCM_RTS; FModemWord := FModemWord and not TIOCM_RTS;
{$IFNDEF FPC} {$IFNDEF FPC}
ioctl(integer(FHandle), TIOCMSET, @FModemWord); ioctl(FHandle, TIOCMSET, @FModemWord);
{$ELSE} {$ELSE}
fpioctl(integer(FHandle), TIOCMSET, @FModemWord); fpioctl(FHandle, TIOCMSET, @FModemWord);
{$ENDIF} {$ENDIF}
{$ELSE} {$ELSE}
if Value then if Value then
@ -1775,12 +1787,12 @@ begin
TimeVal := nil; TimeVal := nil;
{$IFNDEF FPC} {$IFNDEF FPC}
FD_ZERO(FDSet); FD_ZERO(FDSet);
FD_SET(integer(FHandle), FDSet); FD_SET(FHandle, FDSet);
x := Select(integer(FHandle) + 1, @FDSet, nil, nil, TimeVal); x := Select(FHandle + 1, @FDSet, nil, nil, TimeVal);
{$ELSE} {$ELSE}
fpFD_ZERO(FDSet); fpFD_ZERO(FDSet);
fpFD_SET(integer(FHandle), FDSet); fpFD_SET(FHandle, FDSet);
x := fpSelect(integer(FHandle) + 1, @FDSet, nil, nil, TimeVal); x := fpSelect(FHandle + 1, @FDSet, nil, nil, TimeVal);
{$ENDIF} {$ENDIF}
SerialCheck(x); SerialCheck(x);
if FLastError <> sOK then if FLastError <> sOK then
@ -1816,12 +1828,12 @@ begin
TimeVal := nil; TimeVal := nil;
{$IFNDEF FPC} {$IFNDEF FPC}
FD_ZERO(FDSet); FD_ZERO(FDSet);
FD_SET(integer(FHandle), FDSet); FD_SET(FHandle, FDSet);
x := Select(integer(FHandle) + 1, nil, @FDSet, nil, TimeVal); x := Select(FHandle + 1, nil, @FDSet, nil, TimeVal);
{$ELSE} {$ELSE}
fpFD_ZERO(FDSet); fpFD_ZERO(FDSet);
fpFD_SET(integer(FHandle), FDSet); fpFD_SET(FHandle, FDSet);
x := fpSelect(integer(FHandle) + 1, nil, @FDSet, nil, TimeVal); x := fpSelect(FHandle + 1, nil, @FDSet, nil, TimeVal);
{$ENDIF} {$ENDIF}
SerialCheck(x); SerialCheck(x);
if FLastError <> sOK then if FLastError <> sOK then
@ -1891,7 +1903,7 @@ end;
procedure TBlockSerial.Flush; procedure TBlockSerial.Flush;
begin begin
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
SerialCheck(tcdrain(integer(FHandle))); SerialCheck(tcdrain(FHandle));
{$ELSE} {$ELSE}
SetSynaError(sOK); SetSynaError(sOK);
if not Flushfilebuffers(FHandle) then if not Flushfilebuffers(FHandle) then
@ -1904,9 +1916,9 @@ end;
procedure TBlockSerial.Purge; procedure TBlockSerial.Purge;
begin begin
{$IFNDEF FPC} {$IFNDEF FPC}
SerialCheck(ioctl(integer(FHandle), TCFLSH, TCIOFLUSH)); SerialCheck(ioctl(FHandle, TCFLSH, TCIOFLUSH));
{$ELSE} {$ELSE}
SerialCheck(fpioctl(integer(FHandle), TCFLSH, TCIOFLUSH)); SerialCheck(fpioctl(FHandle, TCFLSH, TCIOFLUSH));
{$ENDIF} {$ENDIF}
FBuffer := ''; FBuffer := '';
ExceptCheck; ExceptCheck;
@ -1930,9 +1942,9 @@ begin
Result := 0; Result := 0;
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
{$IFNDEF FPC} {$IFNDEF FPC}
SerialCheck(ioctl(integer(FHandle), TIOCMGET, @Result)); SerialCheck(ioctl(FHandle, TIOCMGET, @Result));
{$ELSE} {$ELSE}
SerialCheck(fpioctl(integer(FHandle), TIOCMGET, @Result)); SerialCheck(fpioctl(FHandle, TIOCMGET, @Result));
{$ENDIF} {$ENDIF}
{$ELSE} {$ELSE}
SetSynaError(sOK); SetSynaError(sOK);
@ -1946,7 +1958,7 @@ end;
procedure TBlockSerial.SetBreak(Duration: integer); procedure TBlockSerial.SetBreak(Duration: integer);
begin begin
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
SerialCheck(tcsendbreak(integer(FHandle), Duration)); SerialCheck(tcsendbreak(FHandle, Duration));
{$ELSE} {$ELSE}
SetCommBreak(FHandle); SetCommBreak(FHandle);
Sleep(Duration); Sleep(Duration);