我想你的问题是SLEEP的问题,你SLEEP后程序无法响应,当然无法
所以你应该采用另外的延时方法。
比如:
function SetDoorTime(DoorID:Integer;DoorCom:TComm):Integer;
function ParseSetTimeCommand(DoorID:Integer):Integer;
begin
result:=-1;
if DoorRequest=nil then exit;
if DoorRequest[0]<>#$EB then exit;
if (Ord(DoorRequest[3]) <> DoorID) or (DoorRequest[4] <> #$F5)
or (DoorRequest[1]<> #$04) or (DoorRequest[2]<> #$02) then begin
result:=1;
exit;
end;
result:=0;
end;
var
cmd:array[0..9] of char;
FirstTickCount: longint;
TimeOut:longint;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
result:=-1;
if not IsConnectioned(DoorID,DoorCom) then exit;
fillchar(DoorRequest,Sizeof(DoorRequest),#0);
DecodeDate(now, Year, Month, Day);
DecodeTime(now, Hour, Min, Sec, MSec);
Year:=Strtoint(copy(inttostr(Year),3,2));
cmd[0]:=Chr($eb);
cmd[1]:=Chr(8);
cmd[2]:=Chr(2);
cmd[3]:=Chr(DoorID); //DoorID
cmd[4]:=Chr(ConverTime(Year));
cmd[5]:=Chr(ConverTime(Month));
cmd[6]:=Chr(ConverTime(Day));
cmd[7]:=Chr(ConverTime(Hour)); //13
cmd[8]:=Chr(ConverTime(Min)); //30
cmd[9]:=Chr(Ord(cmd[1]) xor Ord(cmd[2]) xor Ord(cmd[3]) xor Ord(cmd[4]) xor Ord(cmd[5]) xor
Ord(cmd[6]) xor Ord(cmd[7]) xor Ord(cmd[8]));
DoorCom.WriteCommData(cmd,length(cmd));
// frmDebugCom.memo1.Lines.add('校对时间');
FirstTickCount := GetTickCount;
repeat
Application.ProcessMessages;
TimeOut:=GetTickCount - FirstTickCount;
result:=ParseSetTimeCommand(DoorID);
until (result = 0) or (result = 1) or (TimeOut > DelayTime);
end;