Author Topic: Receiving HEX characters in BCB  (Read 1176 times)

ReidarS

  • Newbie
  • *
  • Posts: 7
    • View Profile
Receiving HEX characters in BCB
« on: August 09, 2011, 03:47:50 pm »
Hi,

I'm using nrComm to receive hex data from a PIC 16F877A. The microcontroller sends one byte at the time, 0x00 to 0xFF. How can I display this hex value in my terminal? Seems like the nrComm only presents the data as ASCII?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Receiving HEX characters in BCB
« Reply #1 on: August 09, 2011, 04:03:38 pm »
Hello

You can take a look source code of following demo:
Demos\Codes\codes_demo.dpr

It shows all incoming bytes in decimal or hex codes.

Code: [Select]
procedure TForm1.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;  Received: Cardinal);
var i:integer;
    s:string;
begin
  s:='';

  case grpRadix.ItemIndex of
    0:  for i:=0 to Received-1
          do s:=s+IntToStr(Byte(PAnsiChar(Buffer)[i]))+' ';
    1:  for i:=0 to Received-1
          do s:=s+'$'+IntToHex(Byte(PAnsiChar(Buffer)[i]),2)+' ';
  end;

  Memo1.Text:=Memo1.Text+s;
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.

ReidarS

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Receiving HEX characters in BCB
« Reply #2 on: August 09, 2011, 05:51:06 pm »
I've been looking at that example already, but didn't get much out of the pascal code. But I figured it out now, all working now :)

Thanks for the fast reply anyway :)