public bool Connect()
{
button1.Enabled = false;
try
{
SP1.Open();
}
catch (Exception)
{
MessageBox.Show("Invalid Serial Port");
return false;
}
if (SP1.IsOpen)
{
System.Threading.Thread.Sleep(500);
string data = SP1.ReadExisting();
SP1.WriteLine(data);
System.Threading.Thread.Sleep(500);
however i cannot receive the data from arduino through serial port into the c#..how the readexisting functions?does the writeline function enable the data to be write into the c#?sorry,im new in c# and arduino.hope all of u can help.
Not done any C# myself but I can't help but notice that no where do you specify the baud rate. You need to do that so look at the C# manure to tell you how to do it.
so the coding for writeline and readline cannot read the data from arduino?
I don't understand this statement/question. Of course it is possible to write to the serial port that the Arduino is connected to, and read from that serial port.
Of course, the Arduino must be sending data for there to be something to read and the Arduino must be reading the data for there to be a reason to send it.
You seem to have nothing on the PC end more than an echoer of what the Arduino sent, so, how do you know it isn't working?
i am able to receive the da ta on the arduino because i have check it using the SerialMonitor of the arduino.however, i cannot get those data received to be transferred to my GUI using c#.nothing appeared on the GUI side.
i cannot get those data received to be transferred to my GUI using c#.nothing appeared on the GUI side.
That is MUCH different that what you were first complaining about. The serial data is handled in one thread. The GUI is handled in another thread.
The attached application creates a new thread to handle the serial data, and appropriate methods to share data between threads. Perhaps you could study it.
PaulS, my problem now, the serialport is open..however the data cannnot be uploaded in the WPF?
if every function im doing the threading part..is it works to received the data in synchronous manner?
im handle the serial port class in one threads and the data in another threads..
yes.n i have take a look on the threading..when i click on the button..it says "The port is already open". However there is no data appeared on the WPF.it appeared in the console application and arduino serial monitor but not in the WPF C# application.