Jump to content
The simFlight Network Forums

FSUIPC WASM module + client-side API + lvar/hvar discussion topic


John Dowson
 Share

Recommended Posts

5 minutes ago, d147 said:

I had missed the new way to enumerate Lvars and Hvars, rather than using map's.

Yes, sorry - had to switch to using basic types and remove the need for the c/c++ headers for use with other languages.

Link to comment
Share on other sites

7 hours ago, John Dowson said:

Thats interesting...even the list functions?

 

7 hours ago, jaxx said:

Could you share how you are using the DLL from C#? Because I still cannot read or log data via the DLL...

So, first I rebuilt the FSUIPC_WDLL with the latest WAPI lib (that's not necessary now that John have done it for you ūüôā). Then I have the DLL functions declared like this (the ones I'm using in my app):

[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void fsuipcw_init(IntPtr hWnd);

[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void fsuipcw_start();

[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void fsuipcw_end();

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void lvarValueRecvFunc(string lvarName, double value);

[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void fsuipcw_getLvarValues(lvarValueRecvFunc callback);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void lvarIDRecvFunc(string lvarName, int id);

[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void fsuipcw_getLvarList(lvarIDRecvFunc callback);


[DllImport("FSUIPC_WAPID.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void fsuipcw_setLvarAsShort(int id, int value);

Calling the functions fsuipcw_init, fsuipcw_getLvarValues and fsuipcw_getLvarList with:

fsuipcw_init(this.Handle);

var result = new Dictionary<string, double>();
fsuipcw_getLvarValues(result.Add);

var lvars = new Dictionary<string, int>();
fsuipcw_getLvarList(lvars.Add);

NOTE:
I modified the code for fsuipcw_getLvarList so that it takes (const char*, int) instead of (int, const char*). Since there's no function to set an Lvar by name I use this function to get the Lvar ID for the fsuipcw_setLvarAs...(). Having a Dictionary/map with the name as key and id as value serves that purpose much better.

 

Hope this helps. It's my first C# application ever so I had to google it all up, but if it seems to work¬†ūüôā

 

6 hours ago, John Dowson said:

If you can't access let me know and I'll PM you the details.

I'm not part of the¬†VIP cabal with access to that part of the forum ūüôā, so it would be super appreciated if you could do that.

Link to comment
Share on other sites

51 minutes ago, John Dowson said:

Yes, but you can just use fsuipcw_getLvarNameFromId first to get the name.

My application is based around an .ini file with the names of the variables the user like to save/load, so I guess I'm using your API in the opposite direction from what you intended ūüôā

Link to comment
Share on other sites

Really looking forward to this. I used the test client to interrogate and change Lvars in the H135 helicopter (MSFS 2020). Would love to use FSUIPC and/or Air Manager to operate all the soft keys in this aircraft (3 Helionix displays, 24 keys each).

Link to comment
Share on other sites

13 hours ago, andhog said:
14 hours ago, John Dowson said:

Yes, but you can just use fsuipcw_getLvarNameFromId first to get the name.

My application is based around an .ini file with the names of the variables the user like to save/load, so I guess I'm using your API in the opposite direction from what you intended ūüôā

Sorry, I meant that you can use fsuipcw_getLvarIdFromName first to get the id.

You should be able to use the API either on name or id really. I think I'll also add some convenience methods to let you use the name directly.

 

Link to comment
Share on other sites

12 minutes ago, Helibrewer said:

Should the "Create Aircraft LVAR file" be functional yet in the test client? It is the only thing that doesn't seem to generate an output.

Yes its working - although I don't know why you would want to use this function. Its a hangover from a previous implementation. The files are created under your AppData\Roaming\Microsoft Flight Simulator\Packages\fsuipc-lvar-module\work folder (which is the WASM persistent storage area for the FSUIPC WASM module).

Link to comment
Share on other sites

11 minutes ago, John Dowson said:

Yes its working - although I don't know why you would want to use this function. Its a hangover from a previous implementation. The files are created under your AppData\Roaming\Microsoft Flight Simulator\Packages\fsuipc-lvar-module\work folder (which is the WASM persistent storage area for the FSUIPC WASM module).

Found it, yes, it's an incomplete list compared to the "List  LVARS". The main reason I was interested is because I thought it would be easier than trimming the values out of the listing windows to create my file of LVAR names.

Thanks for pointing me in the right direction, found it here:

C:\Users\MyUserName\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalState\packages\fsuipc-lvar-module

 

  • Like 1
Link to comment
Share on other sites

4 minutes ago, Helibrewer said:

Found it, yes, it's an incomplete list compared to the "List  LVARS". The main reason I was interested is because I thought it would be easier than trimming the values out of the listing windows to create my file of LVAR names.

There are (or should be) multiple files there - only 146 lvars per file, which is how many each Client Data Area created can hold, again a hangover from a previous implementation.

You usually actually get more lvars when you create lvar files, as it re-scans for lvars when doing this so you can get more than the initial scan. If you find that you get more, you can issue a reload command to the WASM to reload all the current lvars back to the client/WAPI.

Link to comment
Share on other sites

18 minutes ago, John Dowson said:

There are (or should be) multiple files there - only 146 lvars per file, which is how many each Client Data Area created can hold, again a hangover from a previous implementation.

You usually actually get more lvars when you create lvar files, as it re-scans for lvars when doing this so you can get more than the initial scan. If you find that you get more, you can issue a reload command to the WASM to reload all the current lvars back to the client/WAPI.

Ah, I see that now, thanks again and thanks for all the work on this. Looking forward to figuring out how to utilize this in lua scripts in the future.

Link to comment
Share on other sites

3 hours ago, John Dowson said:

You should be able to use the API either on name or id really

Exactly, but that's only half true now. You can get LVar values by name but you can only set them by ID.

Link to comment
Share on other sites

1 minute ago, andhog said:

but you can only set them by ID.

At the moment, yes, but as I said, you can do:
     setLvar(getHvarIdFromName("My lvar"), myLvarValue);
(or similar if using the dll). And, as I also said, I will add some convenience functions (at some point, low priority) to do this directly, i.e.
     setLvar("MyLvar", my/lvarValue);

(overloaded in the WAPI, I will have to give different names in the dll, eg setLvarByName).

 

Link to comment
Share on other sites

I've added hvar support via lua and macros in the attached version (v7.1.0e)
Note that the hvar name argument for the new lua function activateHvar must be preceded by 'H:'.
For Lvars, no 'L:'. This is due to the fact that the internal hvars are stored with the H:, but lvars are not stored with the L:.
I may change this - it was done so I could easily tell the difference between L and H variables while developing.

For using lvars/havrs in macros, they are always proceeded by L:/H:. 

FSUIPC7.exe

 

Link to comment
Share on other sites

Unfortunately there's apparently something seriously wrong with the latest world update. Having a standalone WASM module in your community folder causes CTD when starting MSFS ūüėē

Link to comment
Share on other sites

22 minutes ago, andhog said:

Unfortunately there's apparently something seriously wrong with the latest world update. Having a standalone WASM module in your community folder causes CTD when starting MSFS ūüėē

I can confirm this also.

Link to comment
Share on other sites

Quote
11 hours ago, andhog said:

Unfortunately there's apparently something seriously wrong with the latest world update. Having a standalone WASM module in your community folder causes CTD when starting MSFS ūüėē

I can confirm this also.

So do I.

I have installed the updated SDK, SimConnect.dll and SimConnect.h have not changed. Maybe WASM?

Link to comment
Share on other sites

12 minutes ago, d147 said:

Maybe WASM?

Asobo seems to have broken the WASM module facility.

https://forums.flightsimulator.com/t/standalone-wasm-modules-crash-the-simulator-after-latest-1-15-7-0-update/390552/4

https://forums.flightsimulator.com/t/wasm-module-connection-broken-after-wu4/390841

We're stuck until this is fixed I'm afraid.

Pete

 

  • Like 1
Link to comment
Share on other sites

For info, I was able to load FSUIPC7_WASM module using hack described in the post:


WASM standalone Module causing CTD on launch after World Update 4 patch - Bugs & Issues / Performance, Graphics & CTDs - Microsoft Flight Simulator Forums

But ūüė≠¬†I was not able to connect to it from the outside (neither WASMClient nor FSUIPC beta find it). Here are the log from WASM:

Thu Apr 15 21:59:49 2021  [ALWAYS]: <=============================== START OF PROGRAM ===============================>
Thu Apr 15 21:59:49 2021    [INFO]: Ini file loaded from add-on package
Thu Apr 15 21:59:49 2021    [INFO]: Ini file loaded from persistant storage
Thu Apr 15 21:59:49 2021   [DEBUG]: SimConnect connection opened ok
Thu Apr 15 21:59:49 2021  [ALWAYS]: Maximum number of lvars/hvars per Client Data Area is 146
Thu Apr 15 21:59:49 2021    [INFO]: Config Client Data Area mapped to ID 1
Thu Apr 15 21:59:49 2021    [INFO]: Data Definition 1 added for Config Client Data Area definition
Thu Apr 15 21:59:49 2021    [INFO]: Config Client Data Area created.
Thu Apr 15 21:59:49 2021    [INFO]: Lvar Value Client Data Area mapped to ID 2
Thu Apr 15 21:59:49 2021    [INFO]: Data Definition 2 added for Lvar Set Request Client Data Area definition
Thu Apr 15 21:59:49 2021    [INFO]: Lvar Value Client Data Area created.
Thu Apr 15 21:59:49 2021    [INFO]: Calculator Code Client Data Area mapped to ID 3
Thu Apr 15 21:59:49 2021    [INFO]: Data Definition 3 added for Lvar Set Request Client Data Area definition
Thu Apr 15 21:59:49 2021    [INFO]: Exec Calculator Code Client Data Area created.
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values CDA with id=4 mapped to name FSUIPC_lvalues0 [requestId=18]
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values Client data definition 4 added [requestID=19]
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values CDA created with id=4, (size=8192 for 1024 values), mapped to name FSUIPC_lvalues0 [requestId=20]
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values CDA with id=5 mapped to name FSUIPC_lvalues1 [requestId=21]
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values Client data definition 5 added [requestID=22]
Thu Apr 15 21:59:49 2021    [INFO]: Lvar values CDA created with id=5, (size=8192 for 1024 values), mapped to name FSUIPC_lvalues1 [requestId=23]

And here from FSUIPC7

     610 *** FSUIPC WASM module not detected - not adding WASM menu

And WASM Client

Fri Apr 16 2021 00:09:50.346   [DEBUG]: SIMCONNECT_RECV_ID_CLIENT_DATA received: EVENT_CONFIG_RECEIVED
Fri Apr 16 2021 00:09:50.346   [TRACE]: Empty config data received - requesting again
Fri Apr 16 2021 00:09:50.842   [TRACE]: Config data requested...
Edited by Nenad Bogojevic
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • 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.