C
chrong
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我的程序地写串口线程:
procedure TWriteThread.Execute;
var
i : integer;
Str :string;
begin
//haha
while MainFrm.ConChk.Checked do begin
Str := MainFrm.SendEdt.Text + MainFrm.SendEndFlagEdt.Text;
for i:=0 to length(Str)-1 do
buff := str[i+1];
pchToSend :=buff;
PurgeComm(hCom, PURGE_TXCLEAR or PURGE_TXABORT);
if WriteData(length(pchToSend))=length(pchToSend) then
MainFrm.SendMM.Lines.Add(MainFrm.SendEdt.Text)
else
MainFrm.SendMM.Lines.Add('发送失败!');
sleep(strtoint(Mainfrm.IntervalEdt.text));
end;
end;
写串口函数:
function TWriteThread.WriteData(length: integer): integer;
var
Sended : boolean;
dwLength, dwErr, dwError: DWORD;
comStat : TComStat;
strInfo : string;
begin
//send data
Sended := WriteFile(hCom, pchToSend^, length, dwLength, @MainFrm.writeOl);
if not Sended then begin
dwErr := GetLastError;
if dwErr=ERROR_IO_PENDING then begin
……
昨天还好好的,今天就总是发送失败,
发送返回的长度总是0,错误就是ERROR_IO_PENDING,
什么I/O操作正在进行中
请问这是怎么回事?
十分着急,请指教!
procedure TWriteThread.Execute;
var
i : integer;
Str :string;
begin
//haha
while MainFrm.ConChk.Checked do begin
Str := MainFrm.SendEdt.Text + MainFrm.SendEndFlagEdt.Text;
for i:=0 to length(Str)-1 do
buff := str[i+1];
pchToSend :=buff;
PurgeComm(hCom, PURGE_TXCLEAR or PURGE_TXABORT);
if WriteData(length(pchToSend))=length(pchToSend) then
MainFrm.SendMM.Lines.Add(MainFrm.SendEdt.Text)
else
MainFrm.SendMM.Lines.Add('发送失败!');
sleep(strtoint(Mainfrm.IntervalEdt.text));
end;
end;
写串口函数:
function TWriteThread.WriteData(length: integer): integer;
var
Sended : boolean;
dwLength, dwErr, dwError: DWORD;
comStat : TComStat;
strInfo : string;
begin
//send data
Sended := WriteFile(hCom, pchToSend^, length, dwLength, @MainFrm.writeOl);
if not Sended then begin
dwErr := GetLastError;
if dwErr=ERROR_IO_PENDING then begin
……
昨天还好好的,今天就总是发送失败,
发送返回的长度总是0,错误就是ERROR_IO_PENDING,
什么I/O操作正在进行中
请问这是怎么回事?
十分着急,请指教!