|
发表于 2010-8-28 18:48:03
|
显示全部楼层
Function StrToHexStr(Const S: String): String;
//字符串转换成16进制字符串
Var
I: Integer;
Begin
For I := 1 To Length(S) Do
Begin
If I = 1 Then
Result := IntToHex(Ord(S[1]), 2)
Else Result := Result + ' ' + IntToHex(Ord(S[I]), 2);
End;
End;
Function HexStrToStr(Const S: String): String;
//16进制字符串转换成字符串
Var
t: Integer;
ts: String;
M, Code: Integer;
Begin
t := 1;
Result := '';
While t <= Length(S) Do
Begin
While (t <= Length(S)) And (Not (S[t] In ['0'..'9', 'A'..'F', 'a'..'f'])) Do
Inc(t);
If (t + 1 > Length(S)) Or (Not (S[t + 1] In ['0'..'9', 'A'..'F', 'a'..'f'])) Then
ts := '$' + S[t]
Else
ts := '$' + S[t] + S[t + 1];
Val(ts, M, Code);
If Code = 0 Then
Result := Result + Chr(M);
Inc(t, 2);
End;
End;
发送HEX格式的字串,随手搞的, 不知对不对.
edit1.text:='1234'; //把文本字符当做HEX来发送, 收到的也就是1234了.
cport1.WriteStr(HexStrToStr(edit1.text));
//////////////////
var i:Integer; s:string;
begin
s:='12';
i:=StrToInt(s);
comport1.Write(I, SizeOf(byte));
end;
单片机里例如是
uchar ch;
那么ch收到的内容就是0x0C
很头晕,,,不玩了. 不明要求.自已都糊涂了... |
|