Author Topic: codes_demo works incorrect in Delphi2010  (Read 1401 times)

crestxa

  • Newbie
  • *
  • Posts: 15
    • View Profile
codes_demo works incorrect in Delphi2010
« on: November 15, 2010, 04:21:07 pm »
which I send HEX “ED 7E 98 0C 6E 19 32 30” by RS232
but  what I get is $ED $98 $6E $32 $00 $00 $00 $00
WHY

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: codes_demo works incorrect in Delphi2010
« Reply #1 on: November 15, 2010, 04:34:33 pm »
Hello

Please show me your code that sends and receive data.
Possible you use unicode string type that is default for new delphi versions.

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

crestxa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: codes_demo works incorrect in Delphi2010
« Reply #2 on: November 16, 2010, 03:10:43 am »
I know something wrong about unicode string ,but how  can I fix it,thanks
(In delphi7 it's work well)

receive data I use X:\Program Files\nrComm Lib\Demos\Codes\codes_demo.dproj
Delphi2010

crestxa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: codes_demo works incorrect in Delphi2010
« Reply #3 on: November 16, 2010, 03:14:54 am »
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(PChar(Buffer)))+' ';
    1:  for i:=0 to Received-1
          do s:=s+'$'+IntToHex(Byte(PChar(Buffer)),2)+' ';
  end;

  Memo1.Text:=Memo1.Text+s;
end;

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: codes_demo works incorrect in Delphi2010
« Reply #4 on: November 16, 2010, 11:59:50 am »
Hello

Thank you for your information.
The Codes Demo receives data only. It does not send anything.
We tested Codes demo again under Delphi XE and it works fine.

Please show me code that sends data.

Also please check that both applications have same serial port settings (baud rate parity and etc.).

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

crestxa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: codes_demo works incorrect in Delphi2010
« Reply #5 on: November 16, 2010, 03:49:29 pm »
I fixed it by change
s:=s+'$'+IntToHex(Byte(PChar(Buffer)),2)+' ';
to
s:=s+'$'+IntToHex(Byte(PAnsiChar(Buffer)),2)+' ';
It's work fine!

thanks,but Send data from hardware,
How to use nrcomm send,thanks
I use nrComm1.SendString(edit1.Text); But it's not work,It's my first time to use nrcomm,I look for help file,and demo ,but can not find answer,
procedure TForm1.Button2Click(Sender: TObject);
begin
  nrComm1.SendString(edit1.Text);
end;

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: codes_demo works incorrect in Delphi2010
« Reply #6 on: November 16, 2010, 04:43:07 pm »
Hello

Thank you for your information. Yes, your solution is correct.

Also you can try to send string as following:

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrComm1.SendString(AnsiString(edit1.Text));
end;

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