Send data form multiple sensors to PC via serial Connection C# form

I am sending multiple data to C# using the serial port. I want to convert the string[] into integers and use them in an if statement:

here is my arduino code

#define sensor1 A0
#define sensor2 A1
int gled=8;
int val1=0;
int val2=0;

void setup (){

pinMode(gled,OUTPUT);
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);

Serial.begin(9600);
}

void loop(){
val1= analogRead(sensor1);
val2= analogRead(sensor2);


val1=map(val1,0,1023,0,255); //pot değerini  0,255 arası sınırlandır ve değişkene ata.
val2=map(val2,0,1023,0,255); //pot değerini  0,255 arası sınırlandır ve değişkene ata.

 Serial.print(val1);
 Serial.print(",");  //a  değişkenini seri porta gönder.
 Serial.println(val2);   //a  değişkenini seri porta gönder.
 

 delay(3); 

if (val1<224){
digitalWrite(gled,HIGH);

}
else {

digitalWrite(gled,LOW);
}

delay(10);

}

here is my c# code

namespace WindowsFormsApplication21
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
         SerialPort port = new SerialPort("COM11", 9600);
           string rawdata;
           string[] data;
       }


       private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
       {


         this.Invoke(new EventHandler(DoUpdate));

        
       }


       private void DoUpdate(object s, EventArgs e)
       {
          
         
               string[] data = serialPort1.ReadLine().Split(',');

               textBox1.Text = data[0];
               textBox2.Text = data[1];


           

           textBox1.Text = c[0];
            textBox2.Text = c[1];


              int b;
              int d;

              bool result = Int32.TryParse(data[0], out b);
              bool sonuc = Int32.TryParse(data[1], out d);
              if (result)
              {
                  if (b < 224)
                  {

                      button1.BackColor = Color.Red;
                      label1.Text = " OCCUPIED";
                  }
                  else
                  {
                      button1.BackColor = Color.Lime;
                      label1.Text = "AVAILABLE";
                  }
              }




              if (sonuc)
              {
                  if (d< 224)
                  {

                      button1.BackColor = Color.Red;
                      label1.Text = " OCCUPIED";
                  }
                  else
                  {
                      button1.BackColor = Color.Lime;
                      label1.Text = "AVAILABLE";
                  }
              }



           




           










       private void button3_Click(object sender, EventArgs e)
       {
           listBox1.Visible = true;

           listBox1.Items.Add("Değerler alınıyor!");
        

           if (!serialPort1.IsOpen)

           {

               serialPort1.PortName = "COM11";

               serialPort1.Open();
               
              
           }

         

       }

       private void button4_Click(object sender, EventArgs e)
       {
           serialPort1.Close();
           listBox1.Items.Add("Durduruldu!");
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           listBox1.Visible = false;
       }

       private void label3_Click(object sender, EventArgs e)
       {

       }
   }
}

here are my code please help me out l have been struggling for days now.

Moderator: Code tags added

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

If your problem is with your C# code then you should ask on a C# Forum. This Forum is for problems with Arduino code.

...R

I want to convert the string[] into integers and use them in an if statement:

Permission granted.

If you have problems, be sure to let us know.

The OP decided to post yet again at http://forum.arduino.cc/index.php?topic=543535.msg3704479#msg3704479 , so don't waste time here.

Sheesh!

In addition the question is a C# one.

th3codeguy:
I want to convert the string[] into integers

That's a C# question. Go ask at a C# forum.

By the way, I have done this with VB.NET.

.

l asked on a c# forum they said l must ask here ohh God what can l do now......do you have the code now and are you able to send it to me on my email?

@th3codeguy, please do not cross-post. Threads merged.

th3codeguy:
l asked on a c# forum they said l must ask here ... what can l do now

You assume @ieee488 meant "go away". I suspect that was not the message.

In any case, there is a section for such questions. Thread moved.

If the Arduino is sending the data properly which can be verified via the use of the Serial Monitor, then the Arduino has done it's job.
Then it is absolutely a C# question.
I suspect that those folks at the C# forum have no freaking clue what an Arduino is!

Anyway, a C# question no matter how you slice it.

As I wrote above, I have written the Arduino code to send information out its serial port, and have a corresponding VB.NET program reading in that information.

.

what is the problem with your code?
if you are not sure a technique works write a simple test, e.g. arduino

void setup() {
    Serial.begin(115200);
    while(!Serial);
    Serial.println("567,890");
}

void loop() {
}

and a C# console program

  using System;
using System.IO.Ports;

namespace ConsoleTerminal
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort serialPort = new SerialPort() ;
            serialPort.PortName = "COM10";
            serialPort.BaudRate = 115200;
            serialPort.Open();
            string s=serialPort.ReadLine();
            Console.WriteLine("data received " + s);
            string[] data = s.Split(',');
            int b, d;
            Int32.TryParse(data[0], out b);
            Int32.TryParse(data[1], out d);
            Console.WriteLine("b = " + b);
            Console.WriteLine("d = " + d);
        }
    }
}

result

data received 567,890
b = 567
d = 890
Press any key to continue . . .