procedure TDeviceMonitor.WriteLn(const Data; Count: Integer);
var
P : PByteArray;
B : Byte;
C : Char;
S : String;
I : Integer;
J : Integer;
begin
P := @Data;
for I := 0 to (Count+15) div 16 -1 do
begin
S := Format(' %0.8X ', [I*$10]);
for J := 0 to $F do //每行以十六进制数显示16个字节
begin
if I*$10+J < Count then
begin
B := P^[I*$10+J];
if J = 7 then //第8个字符后显示一个分隔符
S := S + IntToHex(B, 2) + '-'
else
S := S + IntToHex(B, 2) + ' ';
end
else
S := S + ' '; //没有数据时以空格填充
end;
for J := 0 to $F do //显示16个字节对应的字符
begin
C := ' ';
if I*$10+J < Count then C := Chr(P^[I*$10+J]);
if (C < ' ') or (C > '~') then C := '.'; //不可见字符以"."显示
S := S + C;
end;
Memo.Lines.Add(S);
end;
end;