cannot read the data from arduino to the c#

when i click on the button..it says "The port is already open". However there is no data appeared on the WPF.

Are you trying to run my application and the serial monitor at the same time?

If my application can't open the serial port, is it any wonder why no serial data appear on the form?

there's an error " Couldn't find input file"Properties\Resources.resx.what thats mean?

there's an error " Couldn't find input file"Properties\Resources.resx.what thats mean?

p
The file is in the zip file I attached.

yes.i have extracted the file..

the result of the code is appeared in the serial monitor of the arduino and on the console application...however the data is not appeared on the windows form? is there any wrong with my code?

Program.zip (318 KB)

When I click on the zip file, I get:

Error 503 Service Unavailable

Service Unavailable
Guru Meditation:

XID: 1078454701

Varnish cache server

So, if you could please varnish the cache server again, that would be good.

hi PaulS, attached is my code that will received the arduino data.

FloodDetection.csproj (3.76 KB)

Program.cs (509 Bytes)

Form1.cs (17 KB)

Form1.Designer.cs (13.3 KB)

Can't read them, either. I posted in Website and Forum about the problem. When the new coat of varnish dries, I'll try again.

Let me make sure I understand correctly.

  1. Your Arduino is running code outputting data to serial port.
  2. You want the data Arduino is sending to serial port to be read into your C# program and displayed on a Windows Form.

I think you have your read and write backwards. You aren't trying to WRITE the output from serial to your C# GUI, you want to READ the output from Arduino, into your C# program and then display it in the GUI.

set a string variable in C# = sp1.readline()

Then set the GUI element ".TEXT" field = to the string variable you created to display it.

Simple serial monitor test code that sends back what is sent to the arduino. If this works, then the issue is with your pc code. If your pc code opens/closes the pc com port on each write, that will cause the arduino to reset each write.

// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    readString="";
  } 
}

you are right ,jjspierx

im just receiving the latitude sent by the transmitter and display on GUI.does the code for dispalying the latlong making any sense?

At a quick glance it looks ok to me, is it working?

it is not working for serial part..n the latlong transmitted cannot be displayed in the label in c# winform.

this is my snippet of coding for arduino..

float rate, waterlevel,longitude,latitude;
...if (latitude== 3.8463 && longitude==103.3059)
{serial.print("latitude:");
serial.println(latitude,4);
serial.print("longitude:");
serial.println(longitude,4);

why i cannot pun the value of latitude and longitude into the label on the winform?

Without seeing your C# code or a more detailed description of the problem, I cannot help you as I do not understand what the problem is.

why i cannot pun the value of latitude and longitude into the label on the winform?

You can, if you do it right. Are you (properly) using separate threads for the serial and UI activities?

There are some examples on stackexchange and perhaps also on the arduino forum. That being said, I attached a small project with a multiline textbox that receives messages from the serial interface (as well as a dropdown to select and connect with the proper COM) It should be easily modifiable for your purposes.

commsapp.7z (33.6 KB)

how to seperate the the thread from UI, PaulS?sorry for asking as im new in c#...from the search in the tutorial, it seems that i have to use the backgroundworker code..how i use that in proper manner?

I've attached a C# application that communicates with the Arduino, using separate threads for the UI and the serial data handling.

It should give you some clues.

CommunicateWithArduino.zip (54 KB)