odwdinc / Python-SimConnect

Python interface for MSFS2020 SimConnect.dll
GNU Affero General Public License v3.0
270 stars 107 forks source link

K Variables with two values #87

Open artlazza opened 3 years ago

artlazza commented 3 years ago

I came across an issue while programming using the library.

The command:

event_to_trigger = Event(b'TURBINE_IGNITION_SWITCH_SET1', sm)
event_to_trigger(2)

Works fine and the switch moves accordingly. The variable is K:TURBINE_IGNITION_SWITCH_SET1 requires one value.

However, when dealing with a K variable that requires two values the program crashes, K:ELECTRICAL_BUS_TO_CIRCUIT_CONNECTION_TOGGLE variable for example.

If I try:

event_to_trigger = Event(b'ELECTRICAL_BUS_TO_CIRCUIT_CONNECTION_TOGGLE', sm)
event_to_trigger(11, 1)

It catches and exception and crashes.

Is there any way to pass two values for a K variable? Passing them in a row didn't work (two separate event_to_trigger commands with different values).

odwdinc commented 3 years ago

Not 100% where you are geting the variable from, more info is needed. You are not able to pass more then on value to any event. Though some have indexs that can be set.

Example Pseudocode:

event_to_trigger = Event(b'GENERAL_ENG_THROTTLE_LEVER_POSITION:index', sm)
# Need to set index befor read/write
event_to_trigger.setIndex(1)
# Note to set index 2 vs 1 just re-run
# event_to_trigger.setIndex(2)

event_to_trigger(1)

This is the same to SimConnect as:

event_to_trigger = Event(b'GENERAL_ENG_THROTTLE_LEVER_POSITION:1', sm)
event_to_trigger(1)

By passing in the 'index' string the lib will handle switching as need, using the setIndex()

artlazza commented 3 years ago

Hi odwdinc, thanks for your reply. I tried your approach but I get "SIMCONNECT_EXCEPTION_NAME_UNRECOGNIZED" and "SIMCONNECT_EXCEPTION_ERROR", which is a different error (not crashing anymore). I suspect this variable doesn't accept the :1 or :2 index as you suggested. My code now is:

event_to_trigger = Event(b'ELECTRICAL_BUS_TO_CIRCUIT_CONNECTION_TOGGLE:1', sm)
event_to_trigger(11)
event_to_trigger = Event(b'ELECTRICAL_BUS_TO_CIRCUIT_CONNECTION_TOGGLE:2', sm)
event_to_trigger(1)

I attached two screenshots of my source. I'm trying to mimic the External Power Switch for the Cessna Grand Caravan EX. The standard "Toggle External Power" didn't do the trick, so I'm trying to figure out the commands of the xml file.

Any thoughts?

Captura de tela 2021-04-04 202950 Captura de tela 2021-04-04 203741

FS2020-USER-TESTER commented 3 years ago

A K: value is internal variable visible to WASM code. Some of them are hooked up to Simconnect external interface but unfortunately many of the most interesting new variables are not. Especially those related to modern avionics. So far the MSFS2020 developers have shown no urgency to modernize Simconnect which they consider seem to consider a legacy interface.

There are a couple of opensource projects using Simconnect to tunnel new commands into a stub running in WASM. These are all very aircraft-model specific as the K: variables are not consistent across models.