function OpenCom(Mode:boolean) : boolean;
var
dw : dword;
begin
result:=FALSE;
if hCom<>INVALID_HANDLE_VALUE
then CloseCom;
if FlgOvrlp
then dw:=FILE_FLAG_OVERLAPPED
else dw:=FILE_ATTRIBUTE_NORMAL;
hCom:=CreateFile(PChar('
\\?\COM'+IntToStr(iComNum)),GENERIC_READ
or GENERIC_WRITE,0,
nil,OPEN_EXISTING,dw,0);
if hCom<>INVALID_HANDLE_VALUE
then begin
SetupComm(hCom,$20000,$20000);
//8192, 8192); // Rd , Wr
if GetComDCB
then begin
if Mode
then DCB.Flags := (DCB.Flags
and $ffff8000)
or $0001
else DCB.Flags := (DCB.Flags
and $ffff8000)
or $0011;
//$1011;
DCB.ByteSize := 8;
DCB.Parity := 0;
DCB.StopBits := 0;
DCB.BaudRate := iComBaud;
if SetComDCB
then begin
ComTimeouts.ReadIntervalTimeout:=20;
//0
ComTimeouts.ReadTotalTimeoutMultiplier:=1;
//0
ComTimeouts.ReadTotalTimeoutConstant:=200;
//200
ComTimeouts.WriteTotalTimeoutMultiplier:=0;
//MAXDWORD;
ComTimeouts.WriteTotalTimeoutConstant:=0;
//MAXDWORD;
if SetComTimeouts
then begin
iOldComOpen:=iComNum;
iOldComBaud:=iComBaud;
if Mode
then begin
sleep(75);
EscapeComFunction(SETRTS);
sleep(25);
EscapeComFunction(SETDTR);
end
else begin
sleep(75);
EscapeComFunction(SETRTS);
end;
// sleep(300);
// PurgeCom(PURGE_TXCLEAR or PURGE_RXCLEAR);
result := TRUE;
end;
end;
end;
end;
end;