C # sending data to Arduino

Hi, I need your help !!! ... I'm trying to send data from C # to arduino but it still fails, try to send a float that has values between 0 and 0.5 to generate evidence when the value is greater than 0.3 light a led as it is less off, but the LED lights to generate communication and never goes out ... Help !!!

Arduino code:

int val;
float xVal;

void setup(){
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}
void loop(){
  if(Serial.available() > 1){
    val = Serial.read();
    if(val=='s'){
      xVal=Serial.read();
      Serial.print(xVal);
      if(xVal > 0.3){
        digitalWrite(13, HIGH);
      }else{
        digitalWrite(13, LOW);
      }
      delay(500);
    }
  }
}

C# code (only comunication)

Joint manoD = esqueleto.Joints[JointType.HandRight];
                    Joint codoD = esqueleto.Joints[JointType.ElbowRight];
                    SkeletonPoint posicionMano = manoD.Position;
                    float angX = posicionMano.X;
                    string a = angX.ToString();
                    port.Write("s");
                    port.Write(a);
                    mensaje = string.Format("X{0}",posicionMano.X);

mensaje shows the position value is the float Mano.X I try and send me good screen shows the values but not the arduino reads well: S

Hi Felhip

xVal=Serial.read();

One call to Serial.read() reads one byte from serial, not a whole float (which you are sending as a string of characters, I think).

Have a look at the readOneFloat() function in this post:

http://forum.arduino.cc/index.php?topic=236162.0

Regards

Ray

Why not check if value>0.3 inside C# and send Boolean True/False?

Jim,internally in C # if it works, but the problem is that I need to send to arduino float values to generate inverse kinematics not to light a LED, LEDs are just testing ...

Ray, I did not understand very well how to use the function: S

--- i was just trying to make communication with the serial port of arduino without C # and admit you values like 0.3 (float) and generate a reading Serial.print obsever several values: S 48,53,50 so they would recommend me another protocol communication? I just need to send 3 values float x, y, z.

I think you are making this more difficult than it needs to be.

I would just send the float values as a string.
Serial.print("111.44"); etc.

Felhip3:
Ray, I did not understand very well how to use the function: S

Can you explain what you did not understand?

You might also find this demo useful - it uses Python but the principles will be the same in any programming language.

...R