• 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.

MSFS20 I'm not receiving simobjectdata

Messages
2
Country
brazil
I follow the developer documentation to create a simvar whatcher but it doesn't work, when I connect and request data my handler isn't receiving calls.

Follow my code.

C#:
using System;

using Microsoft.FlightSimulator.SimConnect;
using System.Runtime.InteropServices;

namespace MFSSimConnectFirst.SimIntegration
{
    public class RetrieveSimData
    {

        private readonly SimConnect simConnect;

        public RetrieveSimData(SimConnect simConnect)
        {
            this.simConnect = simConnect;
        }

        public void RegisterDataDefinition()
        {
            simConnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(this.RecvSimobjectDataEventHandler);

            simConnect.AddToDataDefinition(DATA_DEFINITION_ID.PLANE_ALTITUDE,
                "PLANE ALTITUDE", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);

            simConnect.RegisterDataDefineStruct<AircraftPositionDirectionSpeed>(DATA_DEFINITION_ID.PLANE_ALTITUDE);

            simConnect.RequestDataOnSimObject(
                DATA_REQUEST_ID.AIRCRAFT_POSITION_DIRECTION_SPEED,
                DATA_DEFINITION_ID.PLANE_ALTITUDE,
                SimConnect.SIMCONNECT_OBJECT_ID_USER,
                SIMCONNECT_PERIOD.SECOND,
                SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0);
        }

        private void RecvSimobjectDataEventHandler(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
        {
            Console.WriteLine("Recv");
            var requestId = (DATA_REQUEST_ID)data.dwRequestID;
            if (requestId == DATA_REQUEST_ID.AIRCRAFT_POSITION_DIRECTION_SPEED)
            {
                AircraftPositionDirectionSpeed aircraftPositionDirectionSpeed = (AircraftPositionDirectionSpeed)data.dwData[0];
                Console.WriteLine("altitude: " + aircraftPositionDirectionSpeed.altitude.ToString());
            }
        }

    }

    enum DATA_DEFINITION_ID
    {
        PLANE_ALTITUDE
    };

    enum DATA_REQUEST_ID
    {
        AIRCRAFT_POSITION_DIRECTION_SPEED
    };

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    struct AircraftPositionDirectionSpeed
    {
        public double altitude;
    }

}

Can anyone help me?
 
Last edited:
Just an educated guess, my first hunch:
fsd_run_as_administrator_menu_option.jpg

1 - What happens when you BOTH start your Flightsimulator and your Simconnect client, under the [Run as Adminstrator] option?
Why? Sometimes an application can have not enough FILE_ACCESS_RIGHTS to get to the other application (your flightsimulator.exe)
When you startup both applications [As Administrator] you eliminate this limitation.

2 - Does your PC (operating system) run some sort of (network_level) firewall software on your pc ?
Some pc-based-applications communicate inside our pc internally via the IP_Address of 127.0.0.1 (aka "The Local Host") (see article on the link below for more background)
-https://www.ionos.com/digitalguide/server/know-how/localhost/
Why? If you do not allow your SimConnect executable to use 127.0.0.1 to pass through your network_level firewall, you wil never gain acces to your flightsimulator.exe files (and all her publiser interfaces) ever.
And no access means that your Simconnect client will never get any data back, since its requests will be blocked by the firewall and thus never reach your flightsimulator.exe, running inside RAM-memory.


3 - Is your PC (Operating System) equipped with some sort of application-behavioral-tracking and preventing software / application-firewall? (as in "Antivirus" / "Anti-spyware" tools / Windows Defender)
Why? These tools monitor all (I/O, RAM- memory acces / disk) behaviour of any application installed on your pc,
They do this to make sure that (potentially infected other) applications are not able to seek access to certain mission-critical operating system parts (such as everything inside the C:\windows\*.* and lower directories)
So if your SimConnect executabe has no application_level access into your flightsimulator.exe, the same result applies >> Zero responses back.

I hope this information helps to get Sim-Connect-ing again.
 
I tested part of your code it worked (I just modified it and dropped in into my working C# app)

simconnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimobjectData);

public void RequestTestData()
{
if (true)
{
simconnect.AddToDataDefinition(DEFINITIONS.Test_Altitude, "PLANE ALTITUDE", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.RegisterDataDefineStruct<AircraftPositionDirectionSpeedStr>(DEFINITIONS.Test_Altitude);
}
simconnect.RequestDataOnSimObject(DATA_REQUESTS.TestAltitude_REQ, DEFINITIONS.Test_Altitude, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0);

}



then received data via

void SimConnect_OnRecvSimobjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
{
switch ((DATA_REQUESTS)data.dwRequestID)

case DATA_REQUESTS.TestAltitude_REQ:
AircraftPositionDirectionSpeedStr test = (AircraftPositionDirectionSpeedStr)data.dwData[0];
double alt = test.altitude;
break;


this alt correctly returned 19.74 feet and I'm sitting on the ground at KSAN


modified it

simconnect.RequestDataOnSimObject(DATA_REQUESTS.TestAltitude_REQ, DEFINITIONS.Test_Altitude, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, 0, 0, 0);

and just got data when it changed
 
Last edited:
I figured out why I wasn't receiving the objects.

When I created my sim connection I didn't put the wind32 handler. After put this in my class I starting receiving the data.

I put this code on my classe where I create the sim connection

C#:
simConnect = new SimConnect("Managed Data Request", this.Handle, WM_USER_SIMCONNECT, null, 0);

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

Thank you!
 
Back
Top