你看看我的代码哪儿有问题
procedure TFormMain.Comm1ReceiveData(Sender: TObject;
Buffer: Pointer;
BufferLength: Word);
var
i,Count,num:integer;
TemStr:String;
rbuf:array of byte;
//rbuf:array of byte;
ReTurnByteArr : TByteArr;
TemByteArr : array of byte;
begin
try
setLength(rbuf,BufferLength);
Move(Buffer^, PChar(@rbuf)^,BufferLength);
if ( rbuf[0] = 192 ) and ( rbuf[high(rbuf)] = 192 ) then
//两端都是'C0'表示一帧信息
ReTurnByteArr := ReNewReceiveData(rbuf)
else
exit;
TemStr:='';
for i:=0 to length(ReTurnByteArr)-1do
//
TemStr := TemStr + inttohex(ReTurnByteArr,2);
SetLength(ByteArrForReCrc,length(ReTurnByteArr)-8);
ByteArrForReCrc[0] := ReTurnByteArr[5];
ByteArrForReCrc[1] := ReTurnByteArr[6];
ByteArrForReCrc[2] := ReTurnByteArr[7];
ByteArrForReCrc[3] := ReTurnByteArr[8];
for i:=0 to length(rbuf)-13do
//只算消息字的
ByteArrForReCrc[i+4] := ReTurnByteArr[i +11 ];
Self.CRC16(ByteArrForReCrc);
TemStr := AnsiLowerCase(TemStr);
Self.DisplayReceiveData(TemStr);
except
ShowError('串口接收数据错误!');
end;
end;