Connecting arduino with comport Delphi XE2

Hai :slight_smile:
I got problem with my arduino connecting with comport delphi XE2.
My code could running but no data is displayed on delphi interface..
this is my code on arduino:
int numero;

void setup() {
Serial.begin(9600);
numero=0;
}

void loop() {
Serial.println(numero);
delay(200);
numero=numero+1;
}

and this is code in delphi xe2:
unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CPort;

type
TForm1 = class(TForm)
ComPort1: TComPort;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
procedure ComPort1RxChar(Sender: TObject; Count: Integer);
procedure Button2Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Str: String;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin

ComPort1.ReadStr(Str, Count);
label1.Caption:=Str;

end;

end.

it's simple program to test that my arduino could connect and show the data on my pc with delphi xe2.
I have tried to fix but still nothing.. :confused:
anyone could help me?

Thanks

Does your Arduino program work properly with the Arduino Serial Monitor?

If not, get that working first.

I know nothing about Delphi code and I can't understand yours. A common problem with PC programs is that they are not designed to allow time for the Arduino to reset when the PC program opens the serial port.

What Arduino are you using?

It is often a good idea to put something like

Serial.println("Arduino is ready");

in setup();

Please use the code button </>

so your code looks like this

and is easy to copy to a text editor

...R

rezhart:
Hai :slight_smile:
I got problem with my arduino connecting with comport delphi XE2.
My code could running but no data is displayed on delphi interface..
this is my code on arduino:

int numero;

void setup() {
Serial.begin(9600);
numero=0;
}

void loop() {
Serial.println(numero);
delay(200);
numero=numero+1;
}





and this is code in delphi xe2:


unit Unit1;

interface

uses
 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CPort;

type
 TForm1 = class(TForm)
   ComPort1: TComPort;
   Label1: TLabel;
   Button1: TButton;
   Button2: TButton;
   procedure ComPort1RxChar(Sender: TObject; Count: Integer);
   procedure Button2Click(Sender: TObject);

private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;
 Str: String;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin

ComPort1.ReadStr(Str, Count);
label1.Caption:=Str;

end;

end.




it's simple program to test that my arduino could connect and show the data on my pc with delphi xe2.
I have tried to fix but still nothing.. :confused: 
anyone could help me?

Thanks

Default Windows expects DSR, CTS to be set before communications will happen.
Make sure you turn off flow control.

Chuck.

Thanks all, my arduino get connected

but, ive got another problem at this picture
here output appear in arduino :

http://postimg.org/image/89ux8vzyn

here output appear in delphi:

http://postimg.org/image/eim1fxnkz
my delphi code:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CPort;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;

    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Rx(Sender: TObject; Count: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Str: String;
  serin: String;
  implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

    ComPort1.Open;
      button1.Caption:='Connected';
      ComPort1.Connected:=True;


end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ComPort1.ShowSetupDialog;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if Comport1.Connected then comport1.Connected:=False;
 application.Terminate;
end;


procedure TForm1.Rx(Sender: TObject; Count: Integer);
begin
  ComPort1.ReadStr(Str, Count);
  Memo1.Lines.Add(Str);
 end;



end.

why data appear so messy at delphi?

rezhart:
why data appear so messy at delphi?

Sounds like a problem for a Delphi Forum ?

...R

I gave rezhart a detailed description how to make it work in Delphi but got no response over days. So I deleted that post yesterday what seems to early :slight_smile:

Rezharts Delphi code will never work cause a lack of understanding serial communication.

I will not repeat all the steps necessary to make things running but he should try out the command processor component (ComDataPacket) in addition to the comport component. For that component he should set startstring to asc10 and stop string to asc13 within the code and handle the ready to use incomming strings within the OnPacket event. Nothing more to do and just a few lines of code.

http://www.serialcominstruments.com/

Albert_M:
So I deleted that post yesterday

Please don't delete posts. People other than the OP may benefit from them.

...R

Albert_M:
I gave rezhart a detailed description how to make it work in Delphi but got no response over days. So I deleted that post yesterday what seems to early :slight_smile:

Rezharts Delphi code will never work cause a lack of understanding serial communication.

I will not repeat all the steps necessary to make things running but he should try out the command processor component (ComDataPacket) in addition to the comport component. For that component he should set startstring to asc10 and stop string to asc13 within the code and handle the ready to use incomming strings within the OnPacket event. Nothing more to do and just a few lines of code.

http://www.serialcominstruments.com/

I'm sorry if i missed your replies before, i'll try this. thanks for your advice