Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I started to program a C# app but I have a problem with the vertical speed of the aircraft with offset 030C : when the vertical speed is positive there is no problem but when the aircraft starts descending the vertical speed displayed is around 4294967300... I tried to convert it to int value because I think this is a uint value but it does not work.

Anyone have a solution for that ?

Thanks, Thomas

Posted

The code below is taken from the 'Example Code' solution. It works fine for vertical speed (02C8). You can download this from the website:

http://fsuipc.paulhenty.com/#downloads

private Offset<int> verticalSpeed = new Offset<int>(0x02C8);          // 4-byte offset - Signed integer 
  
protected override void timerMain_Tick(object sender, EventArgs e)
{
      // Call Process() to get the data from FSUIPC
      FSUIPCConnection.Process();
  
      // --------------------
      // VERTICAL SPEED
      // --------------------
      // FSUIPC Documentation says this offset is 4 bytes, signed (int) and holds the speed as metres/second * 256
      // We need to convert back to metres/second by / 256
      // Offset is 'int' so cast to double for conversion.
      double verticalSpeedMPS = (double)this.verticalSpeed.Value / 256d;
      // If you want to display as feet/minute a further conversion is required:
      double verticalSpeedFPM = verticalSpeedMPS * 60d * 3.28084d;
      // Display one of these on the form (this time rounded to 0dp)
      // this.txtVerticalSpeed.Text = verticalSpeedMPS.ToString("F0");
      this.txtVerticalSpeed.Text = verticalSpeedFPM.ToString("F0");
}

030C is a copy of this offset, but it's not updated on the ground. It should work exactly the same as 02C8. Just change the offset in the declaration.

Paul

Posted

The code I posted works fine with FSUIPC4. I've test both 02C8 and 030C.

Are you using the code above unchanged? If not, I'll need to see your offset declaration and the code where you read, convert and display the value.

You should also try running the Example Code application and going to the form called "BC003: Reading and Using Offsets" under the Basic Concepts node.

If this shows large values instead of negatives then you'll need to contact Pete in the main forum as something is wrong with your FSUIPC.

Paul

Posted

You can post in the main support forum here:

https://forum.simflight.com/forum/30-fsuipc-support-pete-dowson-modules/

BUT: There would be no point if my Example Application shows the correct value. Please try that first. If that works then your code is wrong, not FSUIPC.

If you post the relevant parts of your code here I can check it very quickly. I can't help much without seeing the code.

Paul

Posted
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FSUIPC;
using System.Windows.Threading;
using MySql.Data.MySqlClient;

namespace WpfApp5
{
    /// <summary>
    /// Logique d'interaction pour Page2.xaml
    /// </summary>
    public partial class Page2 : Page
    {
        // Set up a timer
        private DispatcherTimer timerMain = new DispatcherTimer();

        // =====================================
        // DECLARE OFFSETS YOU WANT TO USE HERE
        // =====================================
        private Offset<uint> parkingbrakes = new Offset<uint>(0x0BC8);
        private Offset<uint> verticalspeed = new Offset<uint>(0x02C8);
        private Offset<uint> avionicsMaster = new Offset<uint>(0x2E80);

        

        public Page2()
        {
            InitializeComponent();
            configureForm();
            timerMain.Interval = TimeSpan.FromMilliseconds(50);
            timerMain.Tick += timerMain_Tick;
        }



        // The connect/disconnect buton
        private void btnToggleConnection_Click(object sender, RoutedEventArgs e)
        {
            if (FSUIPCConnection.IsOpen)
            {
                // Connection is currently open
                // Stop the main timer
                this.timerMain.Stop();
                // Close the connection
                FSUIPCConnection.Close();
            }
            else
            {
                // Try to open the connection
                try
                {
                    this.lblConnectionStatus.Text = "Looking for a flight simulator...";
                    this.lblConnectionStatus.Foreground = Brushes.Goldenrod;
                    FSUIPCConnection.Open();
                    // If there was no problem, start the main timer
                    this.timerMain.Start();
                }
                catch (Exception ex)
                {
                    // An error occured. Tell the user.
                    MessageBox.Show("Connection Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
            configureForm();
        }

        // This method runs 20 times per second (every 50ms). This is set in the form constructor above.
        private void timerMain_Tick(object sender, EventArgs e)
        {
            // Call process() to read/write data to/from FSUIPC
            // We do this in a Try/Catch block incase something goes wrong
            try
            {
                FSUIPCConnection.Process();

                // Update the information on the form
                // (See the Examples Application for more information on using Offsets).

                // 1. Airspeed        
                double parking_brakes = (double)this.parkingbrakes.Value;
                if (parking_brakes > 0)
                {
                    this.txtAirspeed.Text = "Set";
                    //MySqlCommand command = conn.CreateCommand(); conn.Open();
                    //command.CommandText = "UPDATE va_system SET value=1 WHERE id=1;";
                    //MySqlDataReader reader = command.ExecuteReader();
                }
                else
                {
                    this.txtAirspeed.Text = "Off";
                }

                //Touch

                            
                double verticalSpeedMPS = (double)this.verticalspeed.Value / 256d;
                double vertical_speedFPM = verticalSpeedMPS * 60d * 3.28084d;
                this.txttouch.Text = vertical_speedFPM.ToString("F0");
                

                // 2. Master Avionics
                this.chkAvionicsMaster.IsChecked = avionicsMaster.Value > 0;
            }

            catch (Exception ex)
            {
                // An error occured. Tell the user and stop this timer.
                this.timerMain.Stop();
                MessageBox.Show("Communication with FSUIPC Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                // Update the connection status
                configureForm();
            }
        }



        // This runs when the master avionics tick has been changed
        private void chkAvionicsMaster_Click(object sender, RoutedEventArgs e)
        {
            // Update the FSUIPC offset with the new value (1 = Checked/On, 0 = Unchecked/Off)
            this.avionicsMaster.Value = (uint)(this.chkAvionicsMaster.IsChecked.Value ? 1 : 0);
        }



        // Configures the button and status label depending on if we're connected or not 
        private void configureForm()
        {
            if (FSUIPCConnection.IsOpen)
            {
                this.btnToggleConnection.Content = "Disconnect";
                this.lblConnectionStatus.Text = "Connected to " + FSUIPCConnection.FlightSimVersionConnected.ToString();
                this.lblConnectionStatus.Foreground = Brushes.Green;
            }
            else
            {
                this.btnToggleConnection.Content = "Connect";
                this.lblConnectionStatus.Text = "Disconnected";
                this.lblConnectionStatus.Foreground = Brushes.Red;
            }
        }

        // Window closing so stop the timer and close the connection
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.timerMain.Stop();
            FSUIPCConnection.Close();
        }
    }
}

 

Posted

You've declared the offset as an unsigned integer. That's why you are not getting negative values.

      private Offset<uint> verticalspeed = new Offset<uint>(0x02C8); 

My code again:

private Offset<int> verticalSpeed = new Offset<int>(0x02C8);          // 4-byte offset - Signed integer 

That will fix it.

Paul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.