I developed a app that send data for arduino by serial port, but i can understand how i can recevied in arduino. Because i send a string by serial port for arduino and the arduino recevied anything but don't work my code (in arduino i recevied byte a byte).
Update: it's work ;)
The code in C# that send data:
using System;
using System.Windows.Forms;
//
using System.Threading;
using System.IO;
using System.IO.Ports;
pulic class senddata(){
private void Form1_Load(object sender, System.EventArgs e)
{
//Define a Porta Serial
serialPort1.PortName = textBox2.Text;
serialPort1.BaudRate = 9600;
serialPort1.Open();
}
private void button1_Click(object sender, System.EventArgs e)
{
serialPort1.Write("10"); //This is a string The 1 is a comand 0 is interpeter
}
}
The Arduino Code: I have Update the Code
#include <Servo.h>
Servo servo;
String incomingString;
int pos;
void setup()
{
servo.attach(9);
Serial.begin(9600);
incomingString = "";
}
void loop()
{
if(Serial.available())
{
// Read a byte from the serial buffer.
char incomingByte = (char)Serial.read();
incomingString += incomingByte;
// Checks for null termination of the string.
if (incomingByte == '0') { //When 0 execute de code, the last byte is 0
if(incomingString == "10"){ //The string is 1 and the last byte 0... beacause incomingString += incomingByte
servo.write(90);
}
incomingString = "";
}
}
}