Jump to content
Sign in to follow this  
Guest 2002cbr600f4i

Need a simple "push data/command" example in c#

Recommended Posts

Guest 2002cbr600f4i

Hey gang,Ok, I think I get how to pull data out of FSX using SimConnect and C#. The three examples provided in the SDK in the beta are pretty straightforward. What I don't see is an example or set of examples showing how to send commands or data INTO the simulator from your client. For instance, how can I (from my client) instruct the sim to turn the landing lights on? Or how do I tell it to change the view or do anything else in the sim?I think we need a similar set of examples for doing this sort of thing.If anyone working on some SimConnect code in C# has managed to do this, I think we all would appreciate seeing some simple examples to get us moving.Thanks!--2002cbr600f4i

Share this post


Link to post
Share on other sites

>For instance, how can I (from my>client) instruct the sim to turn the landing lights on? Or how>do I tell it to change the view or do anything else in the>sim?Sorry, I don't know C# and I'm not going to do the programming for you in any case, but perhaps these notes will point you in the right direction:Most of the normal switches and so on will be controlled by Events, which is MS-speak for what I've always called Controls (bercause they are subject to Controls-Assignments in the menus, and are tabulated in the Controls.DLL). The "event" name was also used in the "Trigger Key Event" calls used by Gauges.I publish a list of FSX controls which is installed when you install FSUIPC4. FSUIPC4 will also log them, optionally.To send an event through SimConnect you need to use: SimConnect_MapClientEventToSimEventto map an ID to a named event (there's a list in the SDK), then, whenever you want to invoke it use: SimConnect_TransmitClientEventMake sure you use a high priority for this -- some of the lower priorities don't reach the parts of FS which action some of the events.There are some SimConnect Variables (SimVars) which can be written. The SDK documentation is a bit sparse on those. If you check my FSUIPC Offsets Status document you would be able to derive those by a little detective work. To write to SimVars is similar to reading them, but using: SimConnect_SetDataOnSimObjectAlways check the SimConnect log when debugging. You'll get an exception on anything which is wrong. Of course you should be checking for exceptions in your code in any case.Regards,Pete


Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites

To set values try this: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(DEFINE_ID.FLAPS);Struct2 Flaps = new Struct2();Flaps.Flaps = 2;FSData.SetDataOnSimObject(DEFINE_ID.FLAPS, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, Flaps);

Share this post


Link to post
Share on other sites

For the eventsFSData.MapClientEventToSimEven(EVENT_ID.LIGHTS, "ALL_LIGHTS_TOGGLE");FSData.SetNotificationGroupPriority(GROUP_ID.GROUP0, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);FSData.TransmitClientEvent(1,EVENT_ID.LIGHTS, 0, GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);

Share this post


Link to post
Share on other sites

Hi Jose,Just one little correction here, I think. You probably have it working because of coincidence of defined values, but:>FSData.SetNotificationGroupPriority(GROUP_ID.GROUP0,>SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);You only really need a Notification group if you want to be notified of the events in it.And:>FSData.TransmitClientEvent(1,EVENT_ID.LIGHTS, 0,>GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);The Flag "SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY" means that the previous parameter, which you have set to the GROUP ID, is in actual fact a Priority -- so the value used there SHOULD be one of the priorities -- in this case your SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST.That is also what you'd do when sending an event which is not part of a Notification group.If you want the Notification Group priority to be used (which in this example doesn't matter) then don't give any flags -- set the last parameter to 0.Regards,Pete


Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites

Hi PeteThanks for spotting. It was a copy paste error, SetNotificationGroupPriority was there because I also have a brake event notification, not because of the Lights.Didn't spot that the SIMCONNECT_EVENT_FLAG.DEFAULT is the 0 in non managed simconnect. The fact is that GROUPID_IS_PRIORITY and 0 work at least in Light_togle and in managed interface.RegardsJos

Share this post


Link to post
Share on other sites

>Didn't spot that the SIMCONNECT_EVENT_FLAG.DEFAULT is the 0 in>non managed simconnect. The fact is that GROUPID_IS_PRIORITY>and 0 work at least in Light_togle and in managed interface.They work simply because of a coincidence. The PRIORITY_HIGHEST value is 1 and the Group ID you are using is probably a number like 1 or 2 or so, especially if you've ENUM'd these -- such priority values are between PRIORITY_HIGHEST (1)and PRIORITY_HIGHEST_MASKABLE (10000000). You are simply asking for the event to be sent at whatever priority you've equated that Group ID to be, numerically speaking. Logically it makes no sense, but the practical result is that it works -- in this case. Best to correct the visible logic to show what you really intended.RegardsPete


Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites
Guest 2002cbr600f4i

Thanks guys!Yeah, I certainly wasn't looking for anyone to "write the code" for me... Just point me in the right direction with an example of how to do this since the documentation didn't have any examples for C#.I'm a Java programmer by trade, and I've done a tiny bit of C# in the past, so I'm a bit lost with the "MS" way of doing thing like event handling and their terminology and such. It all works quite a bit differently (at least in terminology) than Java does. Hence why I needed the pointer....Ok, I'll putter with this today and see what I can make it do.Thanks again!--2002cbr600f4i

Share this post


Link to post
Share on other sites
Guest qurious

The key to what you want to do is the SetDataOnSimObject function in the SDK. In order to use it you will need to create a structure to hold the value you want to set and an enum that defines the id of that structure. For example:// define the data idenum DEFINITIONS{ HDGINFO,}// define the structure for the var you want to set[structLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]struct SetHdg{ public double hdg;};// tell it which var you want to set// (the var names are in a different document in the sdk)simconnect.AddToDataDefinition(DEFINITIONS.HDGINFO, "Plane Heading Degrees True", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);// register the var you want to set with SimConnectsimconnect.RegisterDataDefineStruct(DEFINITIONS.HDGINFO);// create a struct so that you can set the varSetHdg hdgdata = new SetHdg();// set the var to the value you want it to behdgdata.hdg = 270;// and finally, tell SimConnect to set the variablesimconnect.SetDataOnSimObject(DEFINITIONS.HDGINFO, SIMCONNECT_SIMOBJECT_TYPE.USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, hdgdata);It's a bit convoluted but not too bad once you get the hang of it.

Share this post


Link to post
Share on other sites
Guest

Thats a good example, I was wondering the same thing and it managed to confuse the heck out of me. If your going to use this thing you really should write your own wrapper methods.

Share this post


Link to post
Share on other sites

I was thinking something similar. It really seems to me that there's only a few procedures that I would want to better automate. For the most part, outside of some interop issues I'm looking at, it all seems pretty clear cut when you get the hang of it.

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...