Jump to content
The simFlight Network Forums

How can I used a C# code to read PMDG_737_NGX_Control?


Primo

Recommended Posts

You cannot read controls. They are write-only.

To read data from the PMDG 737 you need to use the offsets provided. See the document called "Offset Mapping for PMDG 737NGX.pdf" in "Modules\FSUIPC Documents". This has a list of PMDG offsets with instructions for enabling the interface.

These offsets are used just like any other.

Paul

 

Link to comment
Share on other sites

19 minutes ago, Paul Henty said:

To read data from the PMDG 737 you need to use the offsets provided. See the document called "Offset Mapping for PMDG 737NGX.pdf" in "Modules\FSUIPC Documents". This has a list of PMDG offsets with instructions for enabling the interface.

Hi Paul,

I have try to use this way, but it doesn't work.

this is my code, maybe my code have some problem

public partial class MainWindow : Window
    {
        // Create the Offsets we're interested in for this Application
        private Offset<Byte> MCP_ATArmSw_Read = new Offset<Byte>(0x6535);  // Basic integer read and write example
        private Offset<Byte> MCP_annunATArm_Read = new Offset<Byte>(0x653A);  // Basic integer read and write example
        private Offset<Byte> MCP_annunCMD_A_Read = new Offset<Byte>(0x6545);  // Basic integer read and write example
        private Offset<Byte> MCP_annunCMD_B_Read = new Offset<Byte>(0x6547);  // Basic integer read and write example

        private readonly BackgroundWorker Worker = new BackgroundWorker();
        private delegate void UIControl();

        public MainWindow()
        {
            InitializeComponent();

            Workerfunction();

            ConnectButton.Click += Connect;
            DisconnectButton.Click += Disconnect;
        }

        private void Connect(object sender, RoutedEventArgs e)
        {
            OpenFSUIPC();
            if (!Worker.IsBusy)
            {
                /// Starts execution of a background operation.
                Worker.RunWorkerAsync();
            }
            ConnectButton.IsEnabled = false;
            DisconnectButton.IsEnabled = true;
        }

        private void Disconnect(object sender, RoutedEventArgs e)
        {
            FSUIPCConnection.Close();
            Worker.CancelAsync();
            ConnectButton.IsEnabled = true;
            DisconnectButton.IsEnabled = false;
        }

        private void Workerfunction()
        {
            Worker.DoWork += Worker_DoWork;
            Worker.WorkerSupportsCancellation = true;
        }

        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                ReadFSUIPC();
            }
        }

        private void OpenFSUIPC()
        {
            try
            {
                // Attempt to open a connection to FSUIPC (running on any version of Flight Sim)
                FSUIPCConnection.Open();
            }
            catch (Exception ex)
            {
                // Badness occurred - show the error message
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FSUIPCConnection.Close();
            }
        }

        private void ReadFSUIPC()
        {
            try
            {
                //Thread.Sleep(50);
                FSUIPCConnection.Process();
                int MCP_ATArmSw = MCP_ATArmSw_Read.Value;
                int MCP_annunATArm = MCP_annunATArm_Read.Value;
                int MCP_annunCMD_A = MCP_annunCMD_A_Read.Value;
                int MCP_annunCMD_B = MCP_annunCMD_B_Read.Value;

                UIControl receiveDatafromTarget = delegate ()
                {
                    MCP_ATArmSwReadTextBox.Text = MCP_ATArmSw.ToString();
                    MCP_annunATArmReadTextBox.Text = MCP_annunATArm.ToString();
                    MCP_annunCMD_AReadTextBox.Text = MCP_annunCMD_A.ToString();
                    MCP_annunCMD_BReadTextBox.Text = MCP_annunCMD_B.ToString();
                };
                this.Dispatcher.Invoke(receiveDatafromTarget);
            }
            catch (FSUIPCException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FSUIPCConnection.Close();
            }
            catch (Exception ex)
            {
                // Sometime when the connection is lost, bad data gets returned 
                // and causes problems with some of the other lines.  
                // This catch block just makes sure the user doesn't see any
                // other Exceptions apart from FSUIPCExceptions.
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

 

Link to comment
Share on other sites

The codes look okay to me. I can't test it though because I don't have any PMDG aircraft.

Have you followed these instructions in the docs to enable the interface?

Quote

To enable the data communication output from the PMDG aircraft, you will need to open the file
737NGX_Options.ini (located in the FSX folder PMDG\PMDG 737 NGX, and add the following lines
to the end of the file:


[SDK]
EnableDataBroadcast=1

 

 

Paul

Link to comment
Share on other sites

12 hours ago, Paul Henty said:

The codes look okay to me. I can't test it though because I don't have any PMDG aircraft.

Have you followed these instructions in the docs to enable the interface?

 

Paul

Yes, I have followed it, but it still doesn't work.

When control MCP panel, I can't see value change.

Link to comment
Share on other sites

Reading the documentation again, I see there is sometimes a problem after reloading the 737. It's fixed by forcing FSUIPC to reconnect to SimConnect.

You can do this from your code by calling:

FSUIPCConnection.SendControlToFS(FSUIPCControl.ReSimConnect, 0);

Try calling this after loading the 737.

Other than that I have no more ideas. I've tested your code with normal offsets and it's fine.

It seems the problem is with the link to PMDG, but I can't help you with that.

Pete might have some suggestions if you ask up in the main forum. Or maybe he'll see this.

Paul

Link to comment
Share on other sites

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.