I'm building a flight simulator where i have a program called fsuipc that allows you to connect to microsoft flight simulator x and you can read and write data in c# - very handy!
I have built a vertical speed gauge that is simply a servo with a needle on it.This connects to an arduino which runs a modded version of c++. I want c# to send the current vertical speed to the arduino but have encountered issues and have tried for the past 2 days.
The issue is that what the arduino sends back is mostly -1 with the odd 49 thrown in when it should be sending back something like 1566 (feet per min).
Help!
here is the section of c# code that deals with the vertical speed (ignore airspeed that works). The value that shows the current airspeed works fine but the sent then received is totally wrong
private void timer1_Tick(object sender, EventArgs e)
{
// Process the default group
try
{
FSUIPCConnection.Process();
// IAS - Simple integer returned so just divide as per the
// FSUIPC documentation for this offset and display the result.
double airpeedKnots = ((double)airspeed.Value / 128d);
this.txtIAS.Text = airpeedKnots.ToString("f1");
double verticalspeedfpm = ((double)verticalspeed.Value * 60 * 3.28084 / 256); //gets vertical speed in meters per sec and converts it to feeet per min.
this.txtvsi.Text = verticalspeedfpm.ToString("f1"); //outputs it to a test box so i can see what the vertical speed is.
serialPort1.Open(); //opens serial port (com 4) - arduino
serialPort1.WriteLine(verticalspeedfpm.ToString("f1")); //sends the vertical speed data
read = (serialPort1.ReadLine()); // reads what the arduino sent back
serialPort1.Close();//closes the serial port
txtrecieved.Clear();//cleares the text box
this.txtrecieved.Text = read;//writes what was recieved
// Avionics Master Switch
this.chkAvionics.Checked = (avionics.Value > 0); // 0 = Off, 1 = On.
here is the arduino code that simply pings back the message:
int vsint;
String vsstring;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
vsstring = Serial.read();
delay(10);
Serial.println(vsstring);
}
the windows form - the call back box should be equal to the vs box.