June 30, 201510 yr Hi Ed, I'm looking for a code snippet (preferably C# but I can manage [pun intended] to read other languages) that shows how to use a couple of simconnect functions when I have defined a hex event code in the .ini file. I've scoured Google yesterday looking for an example of how to use a hex number versus the usual predefined enums (e.g., KEY_GPS_POWER_BUTTON) but couldn't find anything. For example, if I have defined this in the following in the .ini file: GPS1_COM_FREQ_TOGGLE=0x11000 how would I setup and call the simconnect functions of: TransmitClientEvent() MapClientEventToSimEvent() Thanks for the help, Dirk
June 30, 201510 yr Commercial Member I'm confused. Why would you need to call these functions? Not certain how this falls into support for our software, so bear with me. :smile: Ed Wilson Mindstar AviationMy Playland - I69
June 30, 201510 yr Author Hi Ed, Well your guide to your software says: Method 2: Triggering GNS Events with SImConnectSimConnect was introduced by Microsoft in FSX, and continues to be in use by Lockheed-Martin in Prepar3D. It is the preferred method of controlling the GNS from hardware. SimConnect events are generated by your hardware driver software that is programmed to connect to Flight Sim using the SimConnect interface. This means either you, or your hardware vendor, must have written a program that interfaces your hardware to flight simulator. SimConnect events for the GNS use any hex number between and inclusive of 0x11000 to 0x11FFF. The number must be coded in the INI file with the 0x prefix in order to be recognized as a SimConnect event. The GNS will monitor the SimConnect event stream for the specified event, and if that event appears, the GNS will execute the action to which the event number was assigned. Formatting Example for SimConnect Events: GPS1_COM_FREQ_TOGGLE=0x11000 I'm looking to implement what you have written. But I can't find any sort of documentation in the P3D SDK that shows how to do what you are suggesting. Lots of examples of how to use all the simconnect predefined enums, but nothing that would let me use the hex numbers to trigger the event. So I'm looking for a small code snippet from you that demonstrates using simconnect to trigger an event that will pass over to the GNS. That make sense? - Dirk
June 30, 201510 yr Commercial Member This is designed to work with hardware, so... are you building your own custom hardware with drivers and the lot? Ed Wilson Mindstar AviationMy Playland - I69
June 30, 201510 yr Author Hi Ed, Yes, I've designed an Arduino controller that manages all the button, switches, knob events for various instruments around the cockpit panel. I'm planning on laying out a circuit board for your GNS unit that also contains all the necessary knobs and buttons for a Garmin. I'll hook this up to my existing C# driver code that communicates with P3D using simconnect. So, for example, I have a knob that controls the airspeed indicator instrument. Some code snippets for controlling that device are: public void OpenConection(IntPtr handle) { do { try { // open connection to FS _FSData = new SimConnect("Managed Data Request", handle, WM_USER_SIMCONNECT, null, 0); // Simevents _FSData.MapClientEventToSimEvent(EVENT_ID.AIRSPEED_DEC, "TRUE_AIRSPEED_CAL_DEC"); _FSData.MapClientEventToSimEvent(EVENT_ID.AIRSPEED_INC, "TRUE_AIRSPEED_CAL_INC"); // handler for events notification _FSData.OnRecvEvent += new SimConnect.RecvEventEventHandler(ReceiveEvent); } catch (Exception ex) { Console.WriteLine("cSimconnect.OpenConnection(): " + ex.Message); Thread.Sleep(1000); } } while (!_bHasFSConnection); return; } //Set Airspeed Calibration Knob public void SetAirspeedCalibration(bool bInc) { if (bInc) { _FSData.TransmitClientEvent(1, EVENT_ID.AIRSPEED_INC, 0, GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT); _FSData.TransmitClientEvent(1, EVENT_ID.AIRSPEED_INC, 0, GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT); //run twice to speed it up } else { _FSData.TransmitClientEvent(1, EVENT_ID.AIRSPEED_DEC, 0, GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT); _FSData.TransmitClientEvent(1, EVENT_ID.AIRSPEED_DEC, 0, GROUP_ID.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT); //run twice to speed it up } } In both of these code snippets, to receive an event or transmit an event to the sim, they are using the predefined enums of EVENT_ID.AIRSPEED_INC and EVENT_ID.AIRSPEED_DEC But your guide says to map to events that are hex numbers (e.g., GPS1_COM_FREQ_TOGGLE=0x11000). I guess when I'm looking at the SDK, I'm not following how one would do that? I'm not seeing any spot where you can trigger an event using a hex number. So, how does one implement what you are suggesting in your guide? - Dirk
June 30, 201510 yr Commercial Member Read up on SimConnect_MapClientEventToSimEvent in the SDK. Ed Wilson Mindstar AviationMy Playland - I69
June 30, 201510 yr Author Hi Ed, Read up on SimConnect_MapClientEventToSimEvent in the SDK. Pardon my frustration, but from my first post above I made it amply clear that I know and have read the SDK. I know how this function works. I've used it over and over and over again in my code. But you have yet to give me a simple one line snippet of how to actually use what is written in your guide to call the function using your hex numbers. SimConnect_MapClientEventToSimEvent doesn't take a hex number it takes a constant char event name. From the SDK this is the syntax for the call: HRESULT SimConnect_MapClientEventToSimEvent( HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char* EventName ); All I'm looking for is the one line of code to merge what your guide says and this function. Can I pass in the 0x11000 as a char and have it work?? - Dirk
June 30, 201510 yr Commercial Member While you have posted the 'syntax', it is quite clear you haven't read anything. SimConnect_MapClientEventToSimEvent The SimConnect_MapClientEventToSimEvent function associates a client defined event ID with a Flight Simulator event name. Syntax HRESULT SimConnect_MapClientEventToSimEvent( HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char* EventName ); Parameters hSimConnect [in] Handle to a SimConnect object. EventID [in] Specifies the ID of the client event. EventName [in] Specifies the Flight Simulator event name. Refer to the Event IDs document for a list of event names (listed under String Name). If the event name includes one or more periods (such as "Custom.Event" in the example below) then they are custom events specified by the client, and will only be recognized by another client (and not Flight Simulator) that has been coded to receive such events. No Flight Simulator events include periods. If no entry is made for this parameter, the event is private to the client. Alternatively enter a decimal number in the format "#nnnn" or a hex number in the format "#0xnnnn", where these numbers are in the range THIRD_PARTY_EVENT_ID_MIN and THIRD_PARTY_EVENT_ID_MAX, in order to receive events from third-party add-ons to Flight Simulator X. Ed Wilson Mindstar AviationMy Playland - I69
June 30, 201510 yr Author While you have posted the 'syntax', it is quite clear you haven't read anything. Ed, you are SO right. My bad. I can't tell you how many times I've read that section of the SDK and yet missed that little gem. Thanks for the help and have a great day. - Dirk
Create an account or sign in to comment