• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Problem with Mags

Messages
4
Country
australia
Hi All,

I have been developing a panel for a C152, and am having a small problem. All the switches, trim and throttle work fine. The only thing I can't get working is the mag switch. The following is my code.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.FlightSimulator.SimConnect;
using System.Runtime.InteropServices;
using System.IO.Ports;
using VolumeControl.Library.Constants;
using VolumeControl.Library.Structs;
using VolumeControl.Library.Win32;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        enum GROUP_PRIORITIES : uint
        {
            SIMCONNECT_GROUP_PRIORITY_HIGHEST = 1,
            SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE = 10000000,
            SIMCONNECT_GROUP_PRIORITY_STANDARD = 1900000000,
            SIMCONNECT_GROUP_PRIORITY_DEFAULT = 2000000000,
            SIMCONNECT_GROUP_PRIORITY_LOWEST = 4000000000
        }

        enum Event
        {   
            MAGNETO1_OFF,
            MAGNETO1_RIGHT,
            MAGNETO1_LEFT,
            MAGNETO1_BOTH,
            MAGNETO1_START
        }                                                                          

        SimConnect simconnect;

        const int WM_USER_SIMCONNECT = 0x0402;

        public Form1()
        {
            InitializeComponent();
            init();
        }

        private void init()
        {
            /////////////////Connect to SimConnect server
            try
            {
                simconnect = new SimConnect("SimConnect Tutorial", this.Handle, WM_USER_SIMCONNECT, null, 0);

                simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
                simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);

                simconnect.MapClientEventToSimEvent(Event.MAGNETO1_OFF, "MAGNETO1_OFF");
                simconnect.MapClientEventToSimEvent(Event.MAGNETO1_RIGHT, "MAGNETO1_RIGHT");
                simconnect.MapClientEventToSimEvent(Event.MAGNETO1_LEFT, "MAGNETO1_LEFT");
                simconnect.MapClientEventToSimEvent(Event.MAGNETO1_BOTH, "MAGNETO1_BOTH");
                simconnect.MapClientEventToSimEvent(Event.MAGNETO1_START, "MAGNETO1_START");
  

                textBox2.Text = "Connected";
            }

            catch (COMException)
            {
                textBox2.Text = "Unable to Connect";
            }
            /////////////////////////////////////////////
        }


        void simconnect_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data)
        {
            textBox2.Text = "Connected to SimConnect";
        }


        void simconnect_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data)
        {
            simconnect.Dispose();
            Application.Exit(); 
        }


        protected override void DefWndProc(ref Message m)
        {
            if (m.Msg == WM_USER_SIMCONNECT)
            {
                if (simconnect != null)
                {
                    simconnect.ReceiveMessage();
                }
            }
            else
            {
                base.DefWndProc(ref m);
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            simconnect.TransmitClientEvent(0, Event.MAGNETO1_OFF, 0, GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            simconnect.TransmitClientEvent(0, Event.MAGNETO1_RIGHT, 0, GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            simconnect.TransmitClientEvent(0, Event.MAGNETO1_LEFT, 0, GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            simconnect.TransmitClientEvent(0, Event.MAGNETO1_BOTH, 0, GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            simconnect.TransmitClientEvent(0, Event.MAGNETO1_START, 0, GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }

       }
}

The problem I am having is that when I click the 3rd button(MAGNETO1_LEFT), the mag in the simulator will go to both. If I click it again, it will select right in the sim. All the other positions work fine. I just don't understand what is going on here.
Can anyone see what I am doing wrong?

Thanks

Mark
 
Problem solved.

It looks like it is a bug in the simulator. I used magnto1_set, and it all works OK now.

Mark
 
Back
Top