Jump to content
The simFlight Network Forums

C# app integration for hardware


brandonharwood14

Recommended Posts

Hi Pete, 

Firstly wanted to thank you for all the work you've put in over the years for the flight sim community.


I have recently been trying to integrate my C# application with your FSUIPC and WASM module. Reason being, I have started up a company that develops GPS, Autopilot, Radios and Intercom panels for use with both XPlane and FS2020.

I'm focusing now completely on FS2020 dev and cant seem to figure out if FSUIPC will allow me to integrate my hardware functionality through FSUIPC to send to the simulator. To make matters worse I'm not that good at coding and also don't understand FS2020 side of things as much as I would like.

I have tried to access the Hvar's to send to the simulator but it seems that this is aircraft specific and a file required for each different set of Hvar's?
So how can I make the program try and send events to the simulator that are not aircraft specific, I know I can just use offsets for most things (which is similar to SimConnect events?) however items such as FMS knob presses on GNS530 or g1000 for example are not just generic commands but I believe Hvar's?
Just in need of a little guidance :)
Thank you!

Regards - Brandon

Link to comment
Share on other sites

10 hours ago, brandonharwood14 said:

I have tried to access the Hvar's to send to the simulator but it seems that this is aircraft specific and a file required for each different set of Hvar's?

Yes, that is correct. However, it is far easier, and recommended, to access hvars using either presets or calculator code directly rather than using *.hvar files to make the hvars known to FSUIPC7.

10 hours ago, brandonharwood14 said:

So how can I make the program try and send events to the simulator that are not aircraft specific, I know I can just use offsets for most things (which is similar to SimConnect events?) however items such as FMS knob presses on GNS530 or g1000 for example are not just generic commands but I believe Hvar's?

You should use the available presets. Even though most are aircraft-specific, the ones for the GN530, G1000 etc, are specific to the model and valid in all aircraft that use them. They are also valid for both the default/Asob versions as well as the Working Title mods.

If developing using C#, you should check-out Paul Henty's client dll for .Net. This provides a higher level interface to both FSUIPC offsets as well as the WASM API / WAPI. See
    https://forum.simflight.com/forum/167-fsuipc-client-dll-for-net/

John

Link to comment
Share on other sites

Quote

Yes, that is correct. However, it is far easier, and recommended, to access hvars using either presets or calculator code directly rather than using *.hvar files to make the hvars known to FSUIPC7.

Hi John, 

Thanks for the information! has definitely got me on the right track and have since found the Events.txt file and documentation about this too.
A few questions on this if you don't mind please:

  • From reading the documentation it seems the events.txt file is used to execute calculator code, this code is corresponding to an H:event (such as (>H:KNOB_ALT_SEL_100_DEC))?
  • when you say "use the available presets" how do you actually use this? I see the execute calculator code section in the FSUIPC menu but not sure exactly what to write or copy & paste into there to execute the appropriate event. Do you just paste the the complete line written as is in the events.txt file. or do you place just the "Calculator Code" part of the "<PresetName>#<Calculator Code>" or even just the "Preset Name"?
  • documentation mentions offset 0x7C50. How is this then used in C# or even just in your FSUIPC7 app that opens with FS2020? All I have dealt with Offsets are these but a very basic understanding I have of this:
        // =====================================
        // DECLARE OFFSETS YOU WANT TO USE HERE
        // =====================================
        private readonly Offset<uint> airspeed = new Offset<uint>(0x02BC); // Airspeed
        private Offset<uint> avionicsMaster = new Offset<uint>(0x2E80); // Avionics Master status
        private Offset<ushort> simPaused = new Offset<ushort>(0x0264);  // 2-byte offset - Unsigned Short  
        private Offset<ushort> pauseControl = new Offset<ushort>(0x0262);// 2-byte offset - Unsigned Short  

        private Offset<uint> GpsDrivesNav = new Offset<uint>(0x132C); // Toggle which source the GPS drives, 0 for Nav and 1 for GPS

                if (this.GpsDrivesNav.Value == 1)
                {
                    this.chkGpsSource.Checked = true;
                    this.chkGpsSource.Text = "GPS";
                }
                else if (this.GpsDrivesNav.Value == 0)
                {
                    this.chkGpsSource.Checked = false;
                    this.chkGpsSource.Text = "NAV";
                }
  • In the event files folder in root directory of FSUIPC7 install there are also mobiflight presets. How can I use this in my code? as this is probably the way I would like to go given the extensive amount of information and updates from HubHop?

That is a few questions on the functions of FSUIPC7. I do apologise if they are mundane - I have not used FSUIPC7 much before this. 

As far as C# goes and I understand the above. I just have a simple button in my C# form for testing with the following code written for the Click event:
 

private void DctBtn_Click(object sender, EventArgs e)
        {
            FSUIPCConnection.SendControlToFS(FsControl.GPS_DIRECTTO_BUTTON, 0);
        }

To execute the Calculator Code, would I still use the SendControlToFS function and substitute appropriate information in after FsControl.*?
 

I am currently shifting through the massive amount of information in the example code given by Paul. Amazing work just need to try and find the right information in the Sln.
Once again thanks for the information you have provided already. I will continue to look into it. Cheers

- Brandon

Link to comment
Share on other sites

11 hours ago, brandonharwood14 said:

From reading the documentation it seems the events.txt file is used to execute calculator code, this code is corresponding to an H:event (such as (>H:KNOB_ALT_SEL_100_DEC))?

It is just a txt file, it does not execute anything.  It just associates a string/preset name to a calculator code string. This file  is provided by MobiFlight and is available from https://hubhop.mobiflight.com/presets/.

12 hours ago, brandonharwood14 said:

when you say "use the available presets" how do you actually use this? I see the execute calculator code section in the FSUIPC menu but not sure exactly what to write or copy & paste into there to execute the appropriate event. Do you just paste the the complete line written as is in the events.txt file. or do you place just the "Calculator Code" part of the "<PresetName>#<Calculator Code>" or even just the "Preset Name"?

Using the Add-ons->WASM->Execute Calc. Code menu option, you would just paste the calculator code to execute it. This method is just used to test if a calc code string is working/has the desired affect.
To execute calculator code from a program, you can use the WAPI (WASM API) interface that I provide. This is a C/C++ API, but a C# wrapper is also provided. And, as I previously said, you can also use Paul Henty's client dll for C#, which is the preferred option fir C# developers.

12 hours ago, brandonharwood14 said:

documentation mentions offset 0x7C50. How is this then used in C# or even just in your FSUIPC7 app that opens with FS2020? All I have dealt with Offsets are these but a very basic understanding I have of this:

To write to offsets using C#, you would need to use the FSUIPC SDK. However, as this is for C/C++, you would be better off using Paul Henty's dll for .Net if using c#. I suggest you look into using this - http://fsuipc.paulhenty.com/#home

12 hours ago, brandonharwood14 said:

In the event files folder in root directory of FSUIPC7 install there are also mobiflight presets. How can I use this in my code? as this is probably the way I would like to go given the extensive amount of information and updates from HubHop?

They are not presets, they are 3rd party custom event files. You use these by copying/moving them to the main FSUIPC7 installation folder, where FSUIPC7 will find and load them when started, and make these custom events available for assignment. Custom events are a distinct and older method than presets. You don't need these if using presets, which is the preferred method these days. See the section Add-on Custom Events on page 38 of the Advanced User guide for further details, but I wouldn't bother with these and just use presets, which can also trigger custom events without the need for using event files.

12 hours ago, brandonharwood14 said:

As far as C# goes and I understand the above. I just have a simple button in my C# form for testing with the following code written for the Click event:
 

private void DctBtn_Click(object sender, EventArgs e)
        {
            FSUIPCConnection.SendControlToFS(FsControl.GPS_DIRECTTO_BUTTON, 0);
        }

To execute the Calculator Code, would I still use the SendControlToFS function and substitute appropriate information in after FsControl.*?
 

I am currently shifting through the massive amount of information in the example code given by Paul. Amazing work just need to try and find the right information in the Sln.
Once again thanks for the information you have provided already. I will continue to look into it. Cheers

Sorry, but I can't help you with using C# or Paul's dll. Please use Paul's sub-forum for any questions on using his dll.

Cheers,

John

 

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.