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

Receiving HEX characters in BCB

Started by ReidarS, August 09, 2011, 12:47:50 pm

Previous topic - Next topic

ReidarS

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

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.

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

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 :)