接受代码如下:procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
    strRecv,MyData: string;
    MWei,Wei1,Wei2,Wei3: string;
begin
    SetLength(strRecv,BufferLength);
    Move(Buffer^,PChar(strRecv)^,BufferLength);
    if strRecv=#$E5 then     //发送确认码
    begin
      PLCEnter;
    end
    else
    begin                   //处理接受的有效数据
      if (Length(strRecv)=35) or (Length(strRecv)=127) and (SendType<>3) then
      begin
         if Length(strRecv)=35 then
         begin
          try
            MyData:=Copy(strRecv,26,8);          except          end;         end;
         if Length(strRecv)=127 then
         begin         end;
      end;
    end ;
end ;串口监控的数据如下:01 00 00 00 00 00 00 00
转化为字符串时怎么变成了 #1 #0 #0 #0 #0 #0 #0 #0,求解?
另请教怎么让 #1 #0 #0 #0 #0 #0 #0 #0转化为10进制。

解决方案 »

  1.   

    转换成ASC码
    var
      Ss: array of byte;  for i:=1 to BufferLength do
        Ss[i-1]:=ord(strRecv[i]);
      

  2.   

    代码调试没通过!procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    var
        StrRecv: string;
        i:integer;
    begin
      SetLength(strRecv,BufferLength);
      Move(Buffer^,PChar(strRecv)^,BufferLength);
    //---------------转化为ASCII码开始---------------求代码。。//---------------转化为ASCII码结束---------------end;
      

  3.   

    procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    var
        StrRecv: string;
        iAsc: array of Byte;
        i:integer;
    begin
      SetLength(strRecv,BufferLength);
      SetLength(iAsc,BufferLength);
      Move(Buffer^,PChar(strRecv)^,BufferLength);
    //---------------转化为ASCII码开始---------------
      for i:=1 to BufferLength do
        iAsc[i-1]:= Ord(strRecv[i]);
    //---------------转化为ASCII码结束---------------
     
    end;
      

  4.   

    这个就自动转成10进制数据存在iAsc数组里,可以直接调用了。比如,要判断首字符是不是$E5,就是十进制的229if (iAsc[0]<>229) then Exit;