Forum > General

how to convert BitConverter.GetBytes for lazarus

<< < (4/4)

bobc:
"\001\r\n" is a string in C style languages. "\" is an escape, \001 is octal encoding of the character code 1, a non-printable control character in ASCII. "\r" means carriage return, value 13 or ASCII CR. "\n" means end-of-line in C standard, which is sometimes treated as equivalent to value 10, ASCII LF.

So what you have is 3 unprintable characters, which can not be displayed as normal characters. The only thing you can do is convert them to an encoded representation. If you want to display it C style you could write a function to do that, you would need to look at the C standard to see what the various escape sequences are.

ahmetnurideniz:
very very thanks for help. now i am understand my problem and slove it.
i want to explain it for another user. becuse i am spend 3 days for this.

1- this function give me hex. data in the string. when the plc send data i write it in the buf
like BuftoString(PChar(buffer),50)



--- Code: ---function BuftoString (buf: pchar; len: integer): string;
var
  j : integer;
  b: byte;
begin
  result := '';
  for j := 0 to len-1 do
  begin
    b := buf[j];
    if (b>=32) and (b<=126) then
       result := result + chr(b)
    else
       result := result + '$'+IntToHex(b,2);
  end;
end;

--- End code ---

2- i write all data in the memo
and i see when plc send me 9999999 i see it on the memo
"$7F$96$98$00$0D$0A> "
i chek it what is hex  9999999  from http://easycalculation.com/decimal-converter.php
it say "98967F"= 9999999
then i understant the function give me hex opposite.
i reverse  it. now i can read data from my plc.
bobc thanks a lot :)

Navigation

[0] Message Index

[*] Previous page

Go to full version