arduino and c# wierd problem

frnds i am facing a wierd problem with interfacing arduino with c#. When i try to control the led on arduino using serial with c# the program attatched here having an event serialport1_datareceived is being called twice due to which the textbox which shows commands sent and received on serial is printing the serial data twice. With respect to my code attached like when i press 1 the textbox on c# program prints HIGH and LOW for only entering just 1 and led lits then turn off swiftly. I dnt know why my serialport_datareceived event is being called twice… for entering 1 only one time… Please help please…

arduino code.txt (3.4 KB)

arduino code.txt (3.4 KB)

Your Arduino code look a lot like C# code. Try again.

adeshGautam:
frnds i am facing a wierd problem with interfacing arduino with c#. When i try to control the led on arduino using serial with c# the program attatched here having an event serialport1_datareceived is being called twice due to which the textbox which shows commands sent and received on serial is printing the serial data twice. With respect to my code attached like when i press 1 the textbox on c# program prints HIGH and LOW for only entering just 1 and led lits then turn off swiftly. I dnt know why my serialport_datareceived event is being called twice… for entering 1 only one time… Please help please…

sorry for that wrong arduino code attachment this one is the right one

arduino code.txt (449 Bytes)

PaulS please see the above code attached

Is your C# code sending a LineFeed or CarriageReturn as well as the character ? That would make the Arduino send back two replies.

Have a look at the examples in serial input basics. They are simple reliable ways to receive data.

Please post Arduino code as a .ino file.

...R

No, its only sending the characters i am entering the textbox using this line serialport1.WriteLine(sendbox1.Text);

oh i figured out the problem thanks for your post. The data receiving variable was supposed to get char data but i was using int type. But one thing more how to send and receive strings ?

adeshGautam: But one thing more how to send and receive strings ?

The code I gave you a link to will receive anything

Sending strings is as simple as Serial.println("This is a test");

...R

thank you very much robin2

No, its only sending the characters i am entering the textbox using this line serialport1.WriteLine(sendbox1.Text);

What do you suppose the difference(s) are between WriteLine() and Write()?