Koseng/MSFSPythonSimConnectMobiFlightExtension

Single (one-off) LVar call, outputs 0

Closed this issue · 7 comments

Calling an LVar only once will always output 0. It seems we have to include the LVar call within a loop (i.e. while True: as in the example) in order to fill up a stack and obtain the wanted output, but this is not practical in many cases.

Not sure if I might be doing something wrong but I need to be able to do the following:

from simconnect_mobiflight import SimConnectMobiFlight
from mobiflight_variable_requests import MobiFlightVariableRequests

sm = SimConnectMobiFlight()
vr = MobiFlightVariableRequests(sm)
vr.clear_sim_variables()

ap1 = vr.get("(L:A32NX_AUTOPILOT_1_ACTIVE)")
print(ap1)

And obtain as output 1 or 0.

Hi,
you're right it always returns 0 at first, which makes it quite useless for a single read.
I made changes to fix it, but it is tricky because the Mobiflight WASM also returns 0 in its first callback.
Try the new main and please give feedback whether that works well for you:
https://github.com/Koseng/MSFSPythonSimConnectMobiFlightExtension/blob/main/src/mobiflight_variable_requests.py

And thanks for your work on FlyByWire!

Wait with testing, at the moment it will work only starting with second run of the python client application. The callbacks behave differently whether the simconnect shared memory was in its initial state or whether it already was used in the past. I need to think whether there is a solution.

Wait with testing, at the moment it will work only starting with second run of the python client application. The callbacks behave differently whether the simconnect shared memory was in its initial state or whether it already was used in the past. I need to think whether there is a solution.

Thank you! I'll wait then for a potential solution.

And by the way, thank you for the alternative of working with LVars through Python. :)

Should work now. Please try and give feedback. https://github.com/Koseng/MSFSPythonSimConnectMobiFlightExtension/blob/main/src/mobiflight_variable_requests.py

Hey! It works great now! I tried with continuously updated variables, such as EGT or N1 and works like a charm. The only thing I need to check is why I get the following exception:

WARNING:SimConnect.SimConnect:SIMCONNECT_EXCEPTION_ALREADY_CREATED

My guess is because during test, I am calling SimConnectMobiFlight once and again ... but will check and let you know. No biggy!

Thank you!

Hi,
that warning can be ignored, it is all fine.

Details:
Creation of the shared memory areas between the WASM-Simconnect-Client and the Python-Simconnect-Client is done on both sides, to be sure whoever is first, not tries to access a non existing shared memory.

Usually the WASM-Simconnect-Client is first, therefore the ALREADY_CREATED warning on the Python side. Probably WASM is always first and it can be safely removed on the Python side. Initially I just did it the same way as the mobiflight client.

So if you want to get rid of the warning, just remove the 3 CreateClientData code lines similar to.
self.sm.dll.CreateClientData(self.sm.hSimConnect, self.CLIENT_DATA_AREA_LVARS, 4096, self.FLAG_DEFAULT)

Hi, that warning can be ignored, it is all fine.

Details: Creation of the shared memory areas between the WASM-Simconnect-Client and the Python-Simconnect-Client is done on both sides, to be sure whoever is first, not tries to access a non existing shared memory.

Usually the WASM-Simconnect-Client is first, therefore the ALREADY_CREATED warning on the Python side. Probably WASM is always first and it can be safely removed on the Python side. Initially I just did it the same way as the mobiflight client.

So if you want to get rid of the warning, just remove the 3 CreateClientData code lines similar to. self.sm.dll.CreateClientData(self.sm.hSimConnect, self.CLIENT_DATA_AREA_LVARS, 4096, self.FLAG_DEFAULT)

Understood, thank you so much.