예제 #1
0
        private void BtnGetFromXP_Click(object sender, EventArgs e)
        {
            try
            {
                using (XPlaneConnect xpc = new XPlaneConnect(100))
                {
                    // Ensure connection established.
                    float[] tanks = xpc.getDREF("sim/flightmodel/weight/m_fuel"); // float[9] in kgs
                    if (tanks.Length >= 8)
                    {
                        MainTank    = new long[4];
                        ReserveTank = new long[2];
                        switch (cmbAircraft.SelectedIndex)
                        {
                        case 0:     //SSG B747-8I
                        case 1:     //SSG B747-8F
                            MainTank[0]    = (int)(tanks[0] * 10);
                            MainTank[1]    = (int)(tanks[1] * 10);
                            CenterTank     = (int)(tanks[2] * 10);
                            StabelizerTank = (int)(tanks[3] * 10);
                            MainTank[2]    = (int)(tanks[4] * 10);
                            MainTank[3]    = (int)(tanks[5] * 10);
                            ReserveTank[0] = (int)(tanks[6] * 10);
                            ReserveTank[1] = (int)(tanks[7] * 10);
                            break;

                        default:     //mSparks 747-400 and Laminar B747-400
                            MainTank[0]    = (int)(tanks[1] * 10);
                            MainTank[1]    = (int)(tanks[2] * 10);
                            CenterTank     = (int)(tanks[0] * 10);
                            StabelizerTank = (int)(tanks[7] * 10);
                            MainTank[2]    = (int)(tanks[3] * 10);
                            MainTank[3]    = (int)(tanks[4] * 10);
                            ReserveTank[0] = (int)(tanks[5] * 10);
                            ReserveTank[1] = (int)(tanks[6] * 10);
                            break;
                        }
                        DisplayFormatedValues();
                    }
                }
            }
            catch (SocketException ex)
            {
                Console.WriteLine("Unable to set up the connection. (Error message was '" + ex.Message + "'.)");
                Console.WriteLine(ex.StackTrace.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong with one of the commands. (Error message was '" + ex.Message + "'.)");
                Console.WriteLine(ex.StackTrace.ToString());
            }
        }
예제 #2
0
        private void BtnSetToXP_Click(object sender, EventArgs e)
        {
            if (!calculated)
            {
                return;
            }
            try
            {
                using (XPlaneConnect xpc = new XPlaneConnect(100))
                {
                    // Ensure connection established.
                    float[] tanks;
                    switch (cmbAircraft.SelectedIndex)
                    {
                    case 0:     //SSG B747-8I
                        tanks = new float[] { (float)MainTank[0] / 10, (float)MainTank[1] / 10, (float)CenterTank / 10, (float)StabelizerTank / 10, (float)MainTank[2] / 10, (float)MainTank[3] / 10, (float)ReserveTank[0] / 10, (float)ReserveTank[1] / 10, 0F };
                        break;

                    case 1:     //SSG B747-8F
                        tanks = new float[] { (float)MainTank[0] / 10, (float)MainTank[1] / 10, (float)CenterTank / 10, 0F, (float)MainTank[2] / 10, (float)MainTank[3] / 10, (float)ReserveTank[0] / 10, (float)ReserveTank[1] / 10, 0F };
                        break;

                    default:     //mSparks 747-400 and Laminar B747-400
                        tanks = new float[] { (float)CenterTank / 10, (float)MainTank[0] / 10, (float)MainTank[1] / 10, (float)MainTank[2] / 10, (float)MainTank[3] / 10, (float)ReserveTank[0] / 10, (float)ReserveTank[1] / 10, (float)StabelizerTank / 10, 0F };
                        break;
                    }

                    xpc.sendDREF("sim/flightmodel/weight/m_fuel", tanks); // float[9] in kgs
                }
            }
            catch (SocketException ex)
            {
                Console.WriteLine("Unable to set up the connection. (Error message was '" + ex.Message + "'.)");
                Console.WriteLine(ex.StackTrace.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong with one of the commands. (Error message was '" + ex.Message + "'.)");
                Console.WriteLine(ex.StackTrace.ToString());
            }
        }