L
lizhi79
Unregistered / Unconfirmed
GUEST, unregistred user!
function TComm.BytesInInQueWord;
var
stat:TCOMSTAT;
errsWord;
begin
ClearCommError(hCommFile,errs,@stat);
Result:=stat.cbInQue;
end;
//读数据
function Tcomm.ReadData(pBufferChar;BufferSizeWord):boolean;
var
nReadWord;
begin
Result:=ReadFile(hCommFile,pBuffer^,BufferSize,nRead,Nil);
end;
//写数据
function TComm.WriteData(pDataToWriteChar;dwSizeofDataToWriteWord):boolean;
var
nSentWord;
begin
Result:=WriteFile(hCommFile,pDataToWrite^,dwSizeofDataToWrite,nSent,Nil);
end;
读线程
procedure TCheckThread.Execute;
var
TempByte:Byte;
begin
while bCheckThread do
begin
//如果输入队列中有数据,读入并在队列中显示出来
if (frmPCDownload.TestComm<>Nil) and (frmPCDownload.TestComm.BytesInInQue>=1) then
begin
frmPCDownload.TestComm.ReadData(@TempByte,1);
TempString:=TempString+Chr(TempByte);
end;
if TempString=chr($23)+chr($AA)+chr($23)+chr($75) then //接收到PC联机信号
begin
TempString:='';
frmPCDownload.TestComm.WriteData(chr($23)+chr($55)+chr($23)+chr($7A),4); //发送联机应答
end;
end;
end;
发送接收都一切正常,但是如果碰到字节 $00 就会停止接收,但是在传输过程中的备用字符就是用 $00 表示的,请问该如何解决?
var
stat:TCOMSTAT;
errsWord;
begin
ClearCommError(hCommFile,errs,@stat);
Result:=stat.cbInQue;
end;
//读数据
function Tcomm.ReadData(pBufferChar;BufferSizeWord):boolean;
var
nReadWord;
begin
Result:=ReadFile(hCommFile,pBuffer^,BufferSize,nRead,Nil);
end;
//写数据
function TComm.WriteData(pDataToWriteChar;dwSizeofDataToWriteWord):boolean;
var
nSentWord;
begin
Result:=WriteFile(hCommFile,pDataToWrite^,dwSizeofDataToWrite,nSent,Nil);
end;
读线程
procedure TCheckThread.Execute;
var
TempByte:Byte;
begin
while bCheckThread do
begin
//如果输入队列中有数据,读入并在队列中显示出来
if (frmPCDownload.TestComm<>Nil) and (frmPCDownload.TestComm.BytesInInQue>=1) then
begin
frmPCDownload.TestComm.ReadData(@TempByte,1);
TempString:=TempString+Chr(TempByte);
end;
if TempString=chr($23)+chr($AA)+chr($23)+chr($75) then //接收到PC联机信号
begin
TempString:='';
frmPCDownload.TestComm.WriteData(chr($23)+chr($55)+chr($23)+chr($7A),4); //发送联机应答
end;
end;
end;
发送接收都一切正常,但是如果碰到字节 $00 就会停止接收,但是在传输过程中的备用字符就是用 $00 表示的,请问该如何解决?