L
lzmling
Unregistered / Unconfirmed
GUEST, unregistred user!
我在dll中这样写的:
function TComm.InitCommdial(ThisCommName: string; BaudRate,DataByte,StopByte,ParityByte: integer): Boolean;
var
dcb: Tdcb;
begin
//Are we already doing comm?
if hCommFile<>0 then
begin
InitCommdial := False;
exit;
end;
hCommFile := CreateFile( PChar(ThisCommName),
GENERIC_READ or GENERIC_WRITE,
0, //not shared
nil, //no security ??
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_OVERLAPPED,
0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
hCommFile := 0;
InitCommdial := False;
exit;
end;
//Is this a valid comm handle?
if GetFileType(hCommFile)<>FILE_TYPE_CHAR then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
if not SetupComm(hCommFile, INQUESIZE, OUTQUESIZE) then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
//Querying then setting the comm port configurations.
GetCommState(hCommFile, dcb);
dcb.BaudRate := BaudRate;
dcb.ByteSize := DataByte; //number of bits/byte, 4-8
dcb.Parity := ParityByte; //0-4=no,odd,even,mark,space
dcb.StopBits := StopByte; //0,1,2 = 1,1.5,2
if not SetCommState(hCommFile, dcb) then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
//purge any information in the buffer
PurgeComm(hCommFile, PURGE_TXABORT or PURGE_RXABORT or
PURGE_TXCLEAR or PURGE_RXCLEAR);
InitCommdial := True;
end;
总是在SetCommState(hCommFile, dcb)时返回false,为什么呢?
function TComm.InitCommdial(ThisCommName: string; BaudRate,DataByte,StopByte,ParityByte: integer): Boolean;
var
dcb: Tdcb;
begin
//Are we already doing comm?
if hCommFile<>0 then
begin
InitCommdial := False;
exit;
end;
hCommFile := CreateFile( PChar(ThisCommName),
GENERIC_READ or GENERIC_WRITE,
0, //not shared
nil, //no security ??
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_OVERLAPPED,
0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
hCommFile := 0;
InitCommdial := False;
exit;
end;
//Is this a valid comm handle?
if GetFileType(hCommFile)<>FILE_TYPE_CHAR then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
if not SetupComm(hCommFile, INQUESIZE, OUTQUESIZE) then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
//Querying then setting the comm port configurations.
GetCommState(hCommFile, dcb);
dcb.BaudRate := BaudRate;
dcb.ByteSize := DataByte; //number of bits/byte, 4-8
dcb.Parity := ParityByte; //0-4=no,odd,even,mark,space
dcb.StopBits := StopByte; //0,1,2 = 1,1.5,2
if not SetCommState(hCommFile, dcb) then
begin
CloseHandle(hCommFile);
hCommFile := 0;
InitCommdial := False;
exit;
end;
//purge any information in the buffer
PurgeComm(hCommFile, PURGE_TXABORT or PURGE_RXABORT or
PURGE_TXCLEAR or PURGE_RXCLEAR);
InitCommdial := True;
end;
总是在SetCommState(hCommFile, dcb)时返回false,为什么呢?