A
aimarli
Unregistered / Unconfirmed
GUEST, unregistred user!
我用这个接受了串口消息
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceive: string;
begin
memo1.Clear;
setLength(StrReceive,BufferLength);
Move(Buffer^,PChar(strReceive)^,BufferLength);
Memo1.Lines.Add(strReceive);
Memo1.Invalidate;
end;
然后我又这样对数据进行了处理
procedure TForm1.Memo1Change(Sender: TObject);
var
j:integer;
str1,str2,bcc1,bcc2:string;
checksum,NUM,NNAME,LAMPP,ALARMT:integer;
bcc3,bcc4,bcc5,bcc6:integer;
begin
str1:=memo1.Text;
j:=pos('55AA',str1);
str2:=copy(str1,j,20);
NUM:=strtonint(copy(str2,5,2));
NNAME:=strtonint(copy(str2,7,2));
LAMPP:=strtonint(copy(str2,9,2));
ALARMT:=strtonint(copy(str2,11,2));
bcc1:=copy(str2,13,2);
bcc2:=copy(str2,15,2);
bcc5:=strtonint(bcc1);
bcc6:=strtonint(bcc2);
checksum:= NUM xor NNAME xor LAMPP xor ALARMT;
bcc3:=checksum shr 4;
if bcc3>9
then
bcc3:=bcc3+$37
else bcc3:=bcc3+$30;
bcc4:=checksum and $0f;
if bcc4>9 then
bcc4:=bcc4+$37
else bcc4:=bcc4+$30;
if (bcc3<>bcc5) or (bcc4<>bcc6)
then
begin
showmessage('bad');
end
else
begin
showmessage('good');
end;
end;
这个程序运行没有错误,memo1一有数据就异常,'类型不对'.
我只是想把截取的字符串根据我的方法进行个异或操作.
为什么这么痛苦``````````
肯请各位大侠,英雄路过看看
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceive: string;
begin
memo1.Clear;
setLength(StrReceive,BufferLength);
Move(Buffer^,PChar(strReceive)^,BufferLength);
Memo1.Lines.Add(strReceive);
Memo1.Invalidate;
end;
然后我又这样对数据进行了处理
procedure TForm1.Memo1Change(Sender: TObject);
var
j:integer;
str1,str2,bcc1,bcc2:string;
checksum,NUM,NNAME,LAMPP,ALARMT:integer;
bcc3,bcc4,bcc5,bcc6:integer;
begin
str1:=memo1.Text;
j:=pos('55AA',str1);
str2:=copy(str1,j,20);
NUM:=strtonint(copy(str2,5,2));
NNAME:=strtonint(copy(str2,7,2));
LAMPP:=strtonint(copy(str2,9,2));
ALARMT:=strtonint(copy(str2,11,2));
bcc1:=copy(str2,13,2);
bcc2:=copy(str2,15,2);
bcc5:=strtonint(bcc1);
bcc6:=strtonint(bcc2);
checksum:= NUM xor NNAME xor LAMPP xor ALARMT;
bcc3:=checksum shr 4;
if bcc3>9
then
bcc3:=bcc3+$37
else bcc3:=bcc3+$30;
bcc4:=checksum and $0f;
if bcc4>9 then
bcc4:=bcc4+$37
else bcc4:=bcc4+$30;
if (bcc3<>bcc5) or (bcc4<>bcc6)
then
begin
showmessage('bad');
end
else
begin
showmessage('good');
end;
end;
这个程序运行没有错误,memo1一有数据就异常,'类型不对'.
我只是想把截取的字符串根据我的方法进行个异或操作.
为什么这么痛苦``````````
肯请各位大侠,英雄路过看看