• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Problem for sending hexa data

Started by egavoille, November 20, 2013, 07:47:39 am

Previous topic - Next topic

egavoille

November 20, 2013, 07:47:39 am Last Edit: November 24, 2013, 01:05:31 pm by egavoille
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

Roman Novgorodov

Hello

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


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.