怎样使用Spcomm控件发送十六进制数???

解决方案 »

  1.   

    procedure TForm1.SendHex(S: String);
    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;
      

  2.   

    遇上10 到 15,转换成0xA 到 0xF就行了。