Author Topic: Problem for sending hexa data  (Read 842 times)

egavoille

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problem for sending hexa data
« on: November 20, 2013, 09:47:39 am »
Hello form France,

i search to send hexa data in Port Comm but it fail...
i try this code :
i want to send in hex 63 FF FF FF


 Const
  sizeData = 4;
var
  myData:array[0.. sizeData-1] of byte = ($63,$FF,$FF,$FF);
begin
    nrComm1.SendData(@myData[0], sizeData);
end;

it doesn't work ERROR, i work on DELPHI XE 3.

And my problem is that my sequence in hex is string and how to convert it to send.
Ex : sData := '64FF00FF';

Thank you for help me and if you have some sample, many thanks
« Last Edit: November 24, 2013, 03:05:31 pm by egavoille »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Problem for sending hexa data
« Reply #1 on: January 16, 2014, 07:05:38 am »
Hello

You need create original function for convert string with HEX dump into string with char codes.
Possible something like following:

Code: [Select]
function Deserialize(s:string):string;
var i:integer;
begin
  Result := '';
  i := 1;
  while i < Length(s) do begin
    try
      Result := Result + Char(Byte(StrToInt('$' + Copy(s, i, 2))));
    except
      break;
    end;
    Inc(i, 2);
  end;
end;

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.