//发送16进制数据
procedure TTest.SendHex(hdata: String);
var
s2:string;
buf1:array[0..50000] of byte;
i:integer;
begin
s2:='';
for i:=1 to length(hdata) do
begin
if ((copy(hdata,i,1)>='0') and (copy(hdata,i,1)<='9'))
or((copy(hdata,i,1)>='a') and (copy(hdata,i,1)<='f'))
or((copy(hdata,i,1)>='A') and (copy(hdata,i,1)<='F')) then
begin
s2:=s2+copy(hdata,i,1);
end;
end;
for i:=0 to (length(s2) div 2-1) do
begin
buf1[i]:=strtoint('$'+copy(s2,i*2+1,2));
end;
ComPort1.PutBlock(buf1,(length(s2) div 2));//SPCOMM来怎么表示这一代码,怎么来实现?
end;
procedure TTest.SendHex(hdata: String);
var
s2:string;
buf1:array[0..50000] of byte;
i:integer;
begin
s2:='';
for i:=1 to length(hdata) do
begin
if ((copy(hdata,i,1)>='0') and (copy(hdata,i,1)<='9'))
or((copy(hdata,i,1)>='a') and (copy(hdata,i,1)<='f'))
or((copy(hdata,i,1)>='A') and (copy(hdata,i,1)<='F')) then
begin
s2:=s2+copy(hdata,i,1);
end;
end;
for i:=0 to (length(s2) div 2-1) do
begin
buf1[i]:=strtoint('$'+copy(s2,i*2+1,2));
end;
ComPort1.PutBlock(buf1,(length(s2) div 2));//SPCOMM来怎么表示这一代码,怎么来实现?
end;
var
s2:string;
buf1:array[0..50000] of char;
i:integer;
begin
s2:='';
for i:=1 to length(s) do
begin
if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((copy(s,i,1)>='a') and (copy(s,i,1)<='f'))
or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
begin
s2:=s2+copy(s,i,1);
end;
end;
for i:=0 to (length(s2) div 2-1) do
buf1[i]:=char(strtoint('$'+copy(s2,i*2+1,2)));
Comm1.WriteCommData(buf1,(length(s2) div 2));
end;
Comm1.WriteCommData(buf1,(length(s2) div 2));//有错!
[Error] Testhand.pas(130): Incompatible types: 'Array' and 'PAnsiChar'