主题:delphi串口编程求救(做个串口方面程序的请进);
sbuf[0] := $0C;
sbuf[1] := ad1;
sbuf[2] := ad2;
sbuf[3] := $83;
sbuf[4] := hextoint(copy(DelayTime, 1, 2));
sbuf[5] := HexToInt(Copy(DelayTime, 3, 2));
sbuf[6] := HexToInt(NO);
if CtrolType = 1 then sbuf[7] := $81;
if CtrolType = 2 then sbuf[7] := $82;
if CtrolType = 4 then sbuf[7] := $84;
sbuf[8] := check(0, 7);
sbuf[9] := $0E;
OutputByte(sbuf); //----内容和tcomm组件的OutputByte的一样;;
sleep(150);
if ReadInDataCount > 0 then//---内容和tcomm组件的ReadInDataCount 的一样;;
begin
sleep(20);
count := ReadInputByte(pt);//---内容和tcomm组件的ReadInputByte的一样;;
setlength(rbuf, Count + 1);
for t := 0 to count do
begin rbuf[t] := pt^;
inc(pt);
end;
if count > 0 then
begin //<<-0C 00 01 83 00 82 48 0E
if valid(1, count - 2) = 1 then //判判断是否为HEX;
begin
if (rbuf[0] = $0C) and (rbuf[3] = $83) and (rbuf[5] = sbuf[7]) and (rbuf[count] = $0E)
then begin
result := 0;
ClearComm;
exit;
end;
end;
end;
end;
ClearComm;---子定义过程;清除com口的数据;//[b]PurgeComm(tc, PURGE_RXCLEAR)[/b]
result := -1;
end;
//程序第一次执行时正常.在程序不关闭的前提下重新调用此代码;追踪发现
ReadInDataCount
count := ReadInputByte(pt).
的值和上次执行到此语句时的值一样;;;;;
好像是没有清除com口的数据;;;;
而我自定义的过程:
procedure ClearComm;
begin
PurgeComm(tc, PURGE_RXCLEAR);
end;
是专门有做清除com口的;(摘自tcomm);
请教:上述问题如何解决??????
sbuf[1] := ad1;
sbuf[2] := ad2;
sbuf[3] := $83;
sbuf[4] := hextoint(copy(DelayTime, 1, 2));
sbuf[5] := HexToInt(Copy(DelayTime, 3, 2));
sbuf[6] := HexToInt(NO);
if CtrolType = 1 then sbuf[7] := $81;
if CtrolType = 2 then sbuf[7] := $82;
if CtrolType = 4 then sbuf[7] := $84;
sbuf[8] := check(0, 7);
sbuf[9] := $0E;
OutputByte(sbuf); //----内容和tcomm组件的OutputByte的一样;;
sleep(150);
if ReadInDataCount > 0 then//---内容和tcomm组件的ReadInDataCount 的一样;;
begin
sleep(20);
count := ReadInputByte(pt);//---内容和tcomm组件的ReadInputByte的一样;;
setlength(rbuf, Count + 1);
for t := 0 to count do
begin rbuf[t] := pt^;
inc(pt);
end;
if count > 0 then
begin //<<-0C 00 01 83 00 82 48 0E
if valid(1, count - 2) = 1 then //判判断是否为HEX;
begin
if (rbuf[0] = $0C) and (rbuf[3] = $83) and (rbuf[5] = sbuf[7]) and (rbuf[count] = $0E)
then begin
result := 0;
ClearComm;
exit;
end;
end;
end;
end;
ClearComm;---子定义过程;清除com口的数据;//[b]PurgeComm(tc, PURGE_RXCLEAR)[/b]
result := -1;
end;
//程序第一次执行时正常.在程序不关闭的前提下重新调用此代码;追踪发现
ReadInDataCount
count := ReadInputByte(pt).
的值和上次执行到此语句时的值一样;;;;;
好像是没有清除com口的数据;;;;
而我自定义的过程:
procedure ClearComm;
begin
PurgeComm(tc, PURGE_RXCLEAR);
end;
是专门有做清除com口的;(摘自tcomm);
请教:上述问题如何解决??????