读书人

SPCOMM字符转换的有关问题字符串#1

发布时间: 2013-03-25 15:43:04 作者: rapoo

SPCOMM字符转换的问题,字符串#1 转换为10进制
接受代码如下:

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进制。
[解决办法]
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;

读书人网 >.NET

热点推荐