1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Something to start TakeII

Discussion in 'SimConnect' started by jcboliveira, 25/9/06.

  1. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    Another managed example.

    This one has several things and doesn't serve any real purpose. Use of

    OnRecvWeatherObservation - Get the metar but strip all FS extended Information

    OnRecvSimobjectData - A simple struct with 17 values

    OnRecvException - The usual

    OnRecvEvent - brakes, Plane crash

    OnRecvQuit - FS Quit

    AICreateSimulatedObject - Create a truck

    OnRecvAssignedObjectId - After creating the truck

    SetDataOnSimObject - Set flaps to 2

    TransmitClientEvent - Toggle lights

    The example encapsulates all Simconnect in a class and uses it in a BackGroundWorker. I have doubts if separated threads is a good approach due to the overhead introduced but this is an exercise. :)

    José

    Attached Files:

    • thr.zip
      File size:
      12.9 KB
      Views:
      284
  2. ziporama

    ziporama

    Joined:
    28/9/06
    Messages:
    203
    Country:
    unitedstates
    Hi JC!

    Looks good! Can't wait for October 17...

    Etienne
  3. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    Using background tasks is something that I am very interested in testing. I'm building a tutorial for the avsim site right now, but I'll take a look at your code in a bit.
  4. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    I wanted to get some info on this part of the code:


    Code:
            public void SetFlaps()
            {
                // Set up data for writing, must be read to get objectID since 0 doesn't work :|
                FSData.AddToDataDefinition(DEFINE_ID.FLAPS, "FLAPS HANDLE INDEX", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                // register it with the simconnect managed wrapper marshaller
                FSData.RegisterDataDefineStruct<SIMConnectFlightDataValues>(DEFINE_ID.FLAPS);
    
                Struct2 Flaps = new Struct2();
                Flaps.Flaps = 2;
                FSData.SetDataOnSimObject(DEFINE_ID.FLAPS, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, Flaps);
            }
    I get it, however, there's one line that confused me that might actually help me out quite a bit. And that was your comment:
    " // Set up data for writing, must be read to get objectID since 0 doesn't work :|"

    What exactly did you mean by that?
  5. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    It's a commment leftover from previous experiments. First time I tried the SetDataOnSimObject this was the code


    private void ReceiveSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
    {
    switch (data.dwDefineID)
    {
    case (uint)DEFINE_ID.STRUCT2:
    // I'm not sure if I need the objectID to write a var
    ObjectId = data.dwObjectID;
    break;
    case (uint)DEFINE_ID.STRUCT1:
    Struct1 RValues = (Struct1)data.dwData[0];
    textBox1.Text = RValues.altitude.ToString();
    break;
    }
    }


    uint ObjectId;
    private void button1_Click(object sender, EventArgs e)
    {
    Struct2 Flaps = new Struct2();
    Flaps.Flaps = 2;
    // Set up data for writing, must be read to get objectID since 0 doesn't work :|
    FSData.SetDataOnSimObject((uint)DEFINE_ID.STRUCT2, ObjectId, Flaps);
    }

    In the SDK it states for C++ SIMCONNECT_OBJECT_ID_USER so maybe the line in the example should be changed to:

    FSData.SetDataOnSimObject(DEFINE_ID.FLAPS, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, Flaps);

    José
  6. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    I'm getting an odd error when trying to set data to the user aircraft. For some reason, it's sending me SIMCONNECT_EXCEPTION_CREATE_OBJECT_FAILED.

    I've tried user SimConnect.SIMCONNECT_OBJECT_ID_USER and getting the id manually from the data return.

    Now I built and ran your program, and it worked fine, so I'm just digging through to find what I did wrong.
  7. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    Maybe that's why I had a 1 instead. I will check at home. What plane are you using?
    José
  8. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    I've only tried it with the default 737. I've been playing with it on and off between work. What got me was that I could create an AI plane and send that data flawlessly, but when I tried to send to the user aircraft, it balked.

    I've tried 0 and 1 as well, same issue.

    What's funny was that this was all supposed to be for a tutorial. :p
  9. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    It works over here with 738 and C172 both SimConnect.SIMCONNECT_OBJECT_ID_USER and 1.

    BTW found out that couldn't change the flaps in the Beaver :confused:

    José
  10. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    I just plugged it into some existing code and haven't really taken the time to track down the bug.

    I'll see what I can find now that I'm home. I appreciate the assistance.
  11. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    Ok, I found the problem.
    Code:
    SimC.AddToDataDefinition(DEFINITIONS.BARO, "KOHLSMAN SETTING MB", "millibars", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
    When I use that, I get the same error every time I try to set data:

    < 494.92414 [63] >>>>> EXCEPTION=20, SendID=7, Index=1 <<<<<

    So I knew it wasn't about the ID, because it was referring to index 1, meaning the first parameter of the SetDataOnSimObject method, which is the data definition.

    Just for testing, I changed the variable to Vertical Speed Indicator and tried again and it worked great. So I tried a variable listed as non-writable and got the same exception.

    So I suppose there's just an issue with that part of the wrapper, as the documentation does say that the millibars barometic pressure should be writable.
  12. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    You can't use Sim Vars to change the flaps in any aircraft. You have to use the FLAPS_SET event.

    I've tested almost every SimVar for writability, and published lists of those which can and those which can't be written. The FSUIPC4 SDK fragemtn for FSX available on my Support forum contains an "Offsets status" document which also helps -- those written via Events are annotated "SimE". those by direct simconnect means (usually Sim Vars) "SimC".

    I don't think the lists i published are available outside the original FSX beta testers, so if you think they'll be useful I'll see about putting tham on my Forum for download.

    Mostly, however, MS have followed the logic that if something can be done well enough using the Event system (I call them Controls, they were called KEY_EVENTS in older SDKs) then they don't duplicate the option via SimVars.

    There are some where I'd strongly disagree -- those with only Toggle variants mainly.

    Regards,

    Pete
  13. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    Yes, Error 20's are returned when trying to write any of the non-writeable Sim Vars. You will need to use the Events instead for all those.

    Does it? You surely don't mean the actual (atmospheric) QNH? If you mean the "KOHLSMAN SETTING MB", that's the Altimeter setting, and is not writable. You have to use the Event "KOHLSMAN_SET".

    Regards,

    Pete
  14. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    Pete

    I usually use the 172 during testing and the "FLAPS HANDLE INDEX" is indeed working for this plane. However isn't working in the Beaver.

    The List will be great.

    José
  15. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    Er ... and you got an Error 20 on the Beaver? Or simply no reaction?

    It makes quite a bit of difference. Different aircraft implementations may or may not react to different variables, but this would be a function of the aircraft not of SimConnect.

    On the other hand, non-writability is a function of SimConnect.

    I'm now thinking it won't be any use. I am only listing those things I did or didn't get an Error 20 for -- it was generated semi-automatically. I need to know whether this was different for your 172 vs Beaver.

    Regards,

    Pete
  16. jcboliveira

    jcboliveira

    Joined:
    8/6/04
    Messages:
    150
    Country:
    portugal
    In the Beaver is simply a no reaction. I wasn't expecting a plane dependent reaction in the flaps index.

    José
  17. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    Peter, you are a god.

    I had completely missed the kohlsman set event.

    That's perfect. Thank you.
  18. NotASenator

    NotASenator

    Joined:
    28/9/06
    Messages:
    22
    Country:
    us-virginia
    Pete,

    KOHLSMAN SETTING MB Altimeter setting Millibars Y

    That's the line in the documentation I was looking at. I noticed the inHg was not settable, so it made sense to me that this one would be. But I guess they just mean through the event.

    Thanks again.
  19. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    No. That's definitely either an error in the documentation (the Y shouldn't be there), or one in the code (it should work). I think the former is the more likely, and in fact it will be the 'solution'. There are actually a lot of discrepancies in the writeability as documented -- as soon as the FS team added that column in the SimVars list I sent them a note about it (and bugged it), with lists of those which I could write without error and those I couldn't. I didn't get to test every single one, but I did many.

    Regards,

    Pete
  20. cyourth

    cyourth

    Joined:
    7/2/07
    Messages:
    7
    Country:
    canada
    Good Example, but what about some work-arounds!

    Good job JC!

    The example shows some of the C# methods that are currently working in SimConnect. ;) What about possible work-arounds for the CompleteCustomMissionAction() and ExecuteMissionAction() methods in C#...

    I'm trying to use C#, SimConnect and the Mission Builder to create training missions... It's pretty hard to do this without the CompleteCustomMissionAction() and ExecuteMissionAction() methods working under the C# environment.

    Refer to the post: Converting Guid to _GUID using C#.NET
    Last edited: 4/7/07

Share This Page