using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using FSUIPC;
namespace FSClient
{
//---------------------------------------------------------------------------------//
public partial class FSClient : Form
{
private static readonly string AppTitle = "FSClient";
private Offset<long> playerLongitude = new Offset<long>(0x0568);
private Offset<long> playerLatitude = new Offset<long>(0x0560);
private Offset<int> verticalSpeed = new Offset<int>(0x02C8);
private Offset<long> altitude = new Offset<long>(0x0570);
private Offset<int> airspeed = new Offset<int>(0x02BC);
//---------------------------------------------------------------------------------//
public FSClient()
{
InitializeComponent();
FsLatitude lat = new FsLatitude(playerLatitude.Value);
FsLongitude lon = new FsLongitude(playerLongitude.Value);
FsLatLonPoint currentPosition = new FsLatLonPoint(lat, lon);
}
//---------------------------------------------------------------------------------//
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.endfl.Enabled = false;
this.label2.Text = ("We expect connection!");
}
//---------------------------------------------------------------------------------//
private void startfl_Click(object sender, EventArgs e)
{
try {
FSUIPCConnection.Open();
this.startfl.Enabled = false;
this.endfl.Enabled = true;
this.timer1.Interval = 100;
this.timer1.Enabled = true;
this.label2.Text = ("Connection is established!");
} catch (Exception ex) {
MessageBox.Show(ex.Message,
AppTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
//---------------------------------------------------------------------------------//
private void endfl_Click(object sender, EventArgs e)
{
try {
FSUIPCConnection.Close();
this.startfl.Enabled = true;
this.endfl.Enabled = false;
this.timer1.Interval = 100;
this.timer1.Enabled = false;
this.label2.Text = ("Flight is completed, the data is saved!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,
AppTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
//---------------------------------------------------------------------------------//
public void displayLocation()
{
FSUIPCConnection.Process();
FsLatitude lat = new FsLatitude(playerLatitude.Value);
FsLongitude lon = new FsLongitude(playerLongitude.Value);
this.label13.Text = lon.ToString();
this.label12.Text = lat.ToString();
FsLatLonPoint currentPosition = new FsLatLonPoint(lat, lon);
}
//---------------------------------------------------------------------------------//
private void timer1_Tick(object sender, EventArgs e)
{
try
{
//---------------------------------------------------------------------------------//
FSUIPCConnection.Process();
//---------------------------------------------------------------------------------//
//Verticall speed in meters
double verticalSpeed_MetresPerSecond = (double)verticalSpeed.Value / 256d;
//---------------------------------------------------------------------------------//
//Vertical speed in feets
double verticalSpeed_FeetPerMinute = (double)verticalSpeed.Value * 60d * 3.28084d / 256d;
//---------------------------------------------------------------------------------//
//Altitude in meters
double altitude_Metres = (double)altitude.Value / (65536d * 65536d);
//---------------------------------------------------------------------------------//
//Altitude in feets
double altitude_Feet = (double)altitude.Value / (65536d * 65536d) * 3.28084d;
//---------------------------------------------------------------------------------//
//Airspeed in knots
double airpeedKnots = ((double)airspeed.Value / 128d);
//---------------------------------------------------------------------------------//
this.displayLocation();
}
catch (FSUIPCException ex)
{
if (ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)
{
this.timer1.Enabled = false;
this.startfl.Enabled = true;
FSUIPCConnection.Close();
MessageBox.Show("The connection to Flight Sim has been lost.",
AppTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
{
throw ex;
}
}
}
//---------------------------------------------------------------------------------//
}
}
This is my new code, but it is not working((((!!!!!
How does all this display?
Do as in the example, but does not work!