SimConnect + WASM combined project using VS2019

Hello @Cerb4ro,

First of all, thanks for your nice words. It gives a good feeling that my tutorial is being appreciated. And there is more to come. Based on this tutorial, I’m adding connectivity with USB connected Serial Port devices (like Arduino). So stay tuned!

1. Issue with setting variables

There are still mysteries in SimConnect and MSFS2020 for me as well. And I also have seen that some variables seem not to be settable for some reason. The KOHLSMAN SETTING variables are a good example. Looking in the SimConnect documentation, they should be settable:

But also if I try to set them, I get the DATA_ERROR. Setting them with execute_calculator_code has no effect neither.

I tried with the FlyByWire A32NX (which is an add-on), but also with the standard A320 neo, and in both cases I get the same issue.

Maybe @MobiFlight has an idea, as they have already expertise for many years? If I would investigate the problem (which I will do later for sure), I would try it first with their tool (MobiFlight has been a bit a “reference” for me). If that works… then it is a problem with my methodology, and then I’m sure I will be able to figure out why. But I’m curious to see if they have issues as well.

2. Where to find information about variables

There are a lot of sources. The ones I’m using are mentioned in my post here.

3. What about "Bool"

Although “Bool” exists as Unit, I think I have read somewhere that it is treated as a normal value such as INT32. A value of 0 is false, and any other value is true. At least, that is what I can read in the documentation here.

I wanted to try it with “CABIN SEATBELTS ALERT SWITCH”, which is a writable bool, but also there I got again the DATA_ERROR. I hope that @MobiFlight might shed some light on setting variables - maybe I’m doing something completely wrong.

1 Like

Let’s prevent a 30 days closure on this… Thanks for this topic… I did some hobbying in 2021 that can be found here changing a an SDK example to show a Dutch compass gauge (silly little change) it is fun to play with, you took it a lot further ! I also have a link for you, that is the github of Nguyễn Quý Hi which shows a very well structured example of a flight recorder using SimConnect from C#

Hi
First of all, congratulations for all you´ve done, it looks great and I´m sure that lots of people out there are going to make good use of your tool. It could work for me, at least I´m hopping that it will, but, I had the same feeling when trying out MobyFlight, and that didn´t work at all, they could find and answer to my issue. I have a A320 complete scaled Throttle that runs on a FTDI board and it work fine with XP11, but no signal whatsoever on MSFS2020. Now my question is, is there any chance of you coming up with a tool that wont need any code writing or any code programing needed? something simple that would recognize the FTDI and would let me tell it what to do?
Thank you again.
Paul

Hello @Xpress690,

I have no clue how your Throttle is communicating - can you be more specific about the brand/type to be able to reveal some technical details? As far as I know, an FTDI board is just converting RS232 into USB, but that doesn’t tell anything about what type of commands or data are required to communicate with your Throttle.

One thing is for sure - if you require a solution in which you don’t need to write code, then my post won’t be a lot of help. Even the second post I wrote (see here) is meant for people who write their own software in the controller (Arduino or other type that supports serial over USB). So I would think you should be more successful with @MobiFlight , but if you say that they couldn’t help, then I’m afraid that it ends here. Maybe there are other forums out there that can help?

Have you looked at Lorby-SI’s Axis and Ohs? It is pretty versatile software, that seems to detect most HID and USB devices out of the box. I believe they have a 15 day free trial - so give it a try.

If that doesn’t help - I don’t know anything specifically about the FTDI devices, so it would help if you give a few more clues by letting us know what kind of device Windows thinks it is. You should be able to see it in Device Manager > Human Interface Devices as either “HID-compliant consumer control device” or “USB Input Device”. If you can, right click on the entry, and click on “Properties”. Then select “Details” . If you get that far, you should be able to get enough information to post here so that someone can help you with the next step. If it’s a HID with a PID and VID, it’s pretty easy to communicate with using something like Axis and Ohs, SpadNext or any generic HID communicating software. It shouldn’t be too complicated once one knows what it is.

1
2
3
4

The answer to your question is, no, I haven´t. Never heard of them before.
I hope this helps, but the guys from MobiFlight tried to help and they couldn´t do anything for me.
The Throttle is the from fscockpit.eu, but they haven´t came up with a driver for MSFS2020 yet.
Thank you for all the help
Paul

Thanks. Axis and Ohs is pretty popular here and they had a huge thread for ages, but had to move it because it was too much Third Party support. It’s now on Avsim. AxisAndOhs Support - The AVSIM Community

Their web site is here: AXIS AND OHS - Home (weebly.com) . It would be well worth while trying, because your device looks like a pretty standard USB/HID device. It shouldn’t need any special MSFS drivers; it’s just a HID device that can be communicated with by something like Axis and Ohs, or SpadNext. Axis and Ohs is very easy to use and low price; SpadNext a tad more difficult and more expensive.

I’ve written my own HID communicator software which can probably communicate with your device OK, but of course I’ve got no means of testing that and it’s not in the sort of state where I’d like it to go public…

The screen you showed is from “Devices and Printers” btw. Useful, but better would be the one next to it “Device Manager”. That should show specifically where the device is located in the devices hierarchy

5

I´ve got into their page, don´t know yet how to use it, but will give a try.

thank you again

Hi @Umberto67,

Is there any way to read/write H:Var in an efficient way like check_named_variable, get_name_variable and set_named_variable?

These gauge functions seem only apply to L:Vars, is it correct?

H: variables can’t be accessed directly with the gauge functions ( except for execute_calculator_code I guess )

all the functions that reference “named vars” are impled to be L: variables

you can use the get_aircraft_var_enum, get_units_enum and aircraft_varget calls to read (read only!! ) A: variables on the USER airplane only, which might be more efficient than making a Simconnect call, especially if you need to read a single variable at once.

Thanks very much @Umberto67.
I plan to read A-vars from external SimConnect API (Standalone executable) and read L-vars/H-vars only (that cannot be read from external) from WASM ‘bridge’ gauge API. Is there performance penalty? Or read the A-vars from the gauge API you mentioned is better?

If most of your program logic is already in the external EXE, since you would need to make a Simconnect call to communicate with the WASM module, and then have the module perform the variable query with a subsequent Gauges API call, it would be best to just request data from Simconnect directly, and use WASM just for L: variables.

The only possible performance benefit ( not really performances as in better fps or latency, but also reduced Simconnect traffic ) of querying A: variables using the Gauges API instead of Simconnect, would be if you moved large portions of your code in the WASM module, so you could possibly skip Simconnect for reading A: variables by doing the logic locally in the module.

However, it would only matter in very specific cases, for example if you need to read the same (few) variables, constantly, at each frame. If you need to read more variables, especially several variables at the same time, it would be better using Simconnect, since you can do that from Simconnect, while the Gauges API can only read a single variable for each call.

And, you can only read A: variables, if you need to write them ( assuming they can be written ), you would have to use Simconnect in any case.

Thank you @Umberto67 for such a detailed explanation. I get much better understanding about SimConnect & WASM.

My project is a small simpit. So I guess keep external SimConnect executable read all it can read, and have WASM module do the H/L-Vars is a do-able solution.

Thanks again, very appreciated.

I had challenges similar to discussed in this topic. Thanks to the explanations here and support from MobiFlight WASM module, I’ve created a port of the classic SimwarWatcher application adding the possibility to access L-vars and execute any code (with the execute_calculator_code). This project can be helpful to those who need to extend their applications beyond a standard SimConnect capabilities. See the code here: https://github.com/rmaryan/SimvarWatcher-MFWASM

2 Likes

This is great, I’ve compiled and executed your WASM app (from github). The last update was 11 months ago, have you made any futher updates.

Is there a way to query MSFS and get a list of all available variables?
I spend more timing searching for vars and events than I do programming and the documentation is often lacking anyway.

thanks

This is one of the most useful theads ever for me, I would like to keep it alive can anyone add anything further.

What I would find useful is the addition of more variables in the example , what we have now is this set … if anyone can add more , it would be very useful:

comboBoxVariables.Items.Add(“A:AUTOPILOT ALTITUDE LOCK VAR:3,feet,FLOAT64”);
comboBoxVariables.Items.Add(“A:KOHLSMAN SETTING HG:1,inHg,FLOAT64”);
comboBoxVariables.Items.Add(“A:LIGHT POTENTIOMETER:84,percent,INT32”);
comboBoxVariables.Items.Add(“L:A32NX_EFIS_L_OPTION,enum”);
comboBoxVariables.Items.Add(“L:A32NX_EFIS_R_OPTION,enum”);
comboBoxVariables.Items.Add(“K:FUELSYSTEM_PUMP_TOGGLE”);
comboBoxVariables.Items.Add(“K:A32NX.FCU_HDG_INC”);

@ZenMusic2 - If you read the SDK, all SimConnect events and variables are listed. To all intents and purposes, SimConnect Events are KVars, and SimConnect Variables are AVars. You could quickly add to your list just by reading those, and working out the “syntax” you need. Or you can use any of them direct of course if you are communicating by SimConnect.

Alternatively - and more reliably if you are communicating through WASM and need LVars or HVars as well - take a look at Mobiflight’s HubHop site, where you’ll find literally thousands of tested data that you can pick from.

1 Like

OK thanks, I guess I’m going to have to (finally) consider Mobiflight … because it so often is recommended to me. I’ll spend today learning about … I’ve already added a WASM module to my msfs addon app, should I remove that to use Mobiflight? Should I rewrite my existing API calls (simconnect) to Mobiflight?

Without knowing how you’ve written your WASM, I can’t really answer that. However - if it works, and you want to continue learning, then - no - you don’t have to use Mobiflight. The RPN codes that are on the HubHop site will work on any valid WASM server so you shouldn’t need to change any of your API calls. It’s just all the RPN scripts that you were looking for. Try a couple and see how/if they work, and if you’re happy with those, then by all means continue writing your own WASM module, and learn more from it!

That said - if you are using SimConnect just as a client you don’t have to go through a WASM at all. Just connect directly to the simulator, and use the SimConnect Events or Variables. The only real drawback to that approach is that you’ll be limited to some extent, as you won’t be able to access LVars or HVars.

Just so you’re clear - most LVars and HVars will only work on a specific aircraft, while most/many of the direct SimConnect calls are generic, and will work on most aircraft. The big exception to that is that most of the generic G1000 events no longer work since MSFS adopted the NXi G1000

1 Like

Hello @ZenMusic2

Option is indeed to use MobiFlight. This is a great tool which offers a lot of flexibility. And the nice thing about MobiFlight is that you don’t need to know anything about coding. It is completely configurable. And on top of that, there is a lot of information found on the internet. I have used MobiFlight in the beginning and learned a lot from it.

But if you really want to experiment with my approach, then I suggest you to go to my other post that contains a next iteration. Tool to connect Serial USB devices to MSFS2020 via SimConnect/WASM using VS2022 - Community Support / Home Cockpit Builders - Microsoft Flight Simulator Forums . I use this tool myself, and already successfully connected it with my PIC-microcontroller driven FCU and MCDU for the FBW A32NX. This tool is used by some other people with success, and according to some feedback it seems pretty stable (some call it “rock solid” :slight_smile:). So far, I haven’t found a single bug since I launched it :crossed_fingers:.

Finding the correct commands/variables is indeed always a struggle. @DeadCertainty gave a good advice to have a look on HubHop. But depending on the airplane you are using, internet provides a lot of useful information. But it’s a struggle sometimes, because there is not a single consistent source that has it all. I call it “part of the fun”. One advice I can give you is to use the execute_calculator_code function in the WASM module, because that is sometimes an easy escape as it accepts all types of variables. For example, I needed to control “H”-variables, and had no clue how to do that. But I simply used the execute_calculator_code, and it works as a charm (all keypresses for my MCDU work like that).

And recently, I have been experimenting with Chat-GPT. I have the feeling that this will create a lot of new possibilities. As an example, I asked it to explain me some complex RPN code string, and it gave me a very good analysis. It even realized that the code was related to MSFS, and it could even identify in what part of the plane this was used. Really amazing!

1 Like