Jump to content
The simFlight Network Forums

How to use SimVars / Events 2 indicies in Lua (e.g. ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE)


Recommended Posts

Posted

In attempting to control the C510 Mustang with a Honeycomb Alpha, Bravo and a 12 Key input pad (with keystrokes) I have 3 Lua modules, Alpha_Buttons.lua, Bravo_Buttons.lua and Sayo-12Keys.lua. I have been successful so far with the cockpit controls. I have used the Events and Lua Logging capability of FSUIPC7 to determine which controls and variables are used to fly the aitcraft. There are two controls that have me confused.

  • Avionics Switch
  •  229641 *** EVENT: Cntrl= 67073 (0x00010601), Param= 1 (0x00000001) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE
  •  229656 *** EVENT: Cntrl= 67073 (0x00010601), Param= 1 (0x00000001) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE
  • Battery Switch
  • 331609 *** EVENT: Cntrl= 66241 (0x000102c1), Param= 1 (0x00000001) TOGGLE_MASTER_BATTERY
  • 331609 *** EVENT: Cntrl= 67073 (0x00010601), Param= 3 (0x00000003) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE

The TOGGLE_MASTER_BATTERY switch is obvious but what about the connections. The Offsets that I found that may be used are:

  • 0x0C71 1 BUS LOOKUP INDEX                        No offset Comments
  • 0x0C72 1 BUS CONNECTION ON:6                 No offset Comments
  • 0x281C 4 ELECTRICAL MASTER BATTERY        Master battery switch (1=On, 0=Off). Currently not working 
                                                                            for the 747-8: always shows on. Can switch off, but not 
                                                                            back on

In addition, External Power (GPU) is available but the Offsets I found are:

  • 0x07AA 1 EXTERNAL_POWER_AVAILABLE     This will be true if the given external power source is available. 
  • 0x07AB 1 EXTERNAL_POWER_ON                 The external power switch position, true if the switch is ON    

I would like to also code a button to attach external power.

ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE    (MSFS SimVar)
[0]: Source bus index
[1]: bus index
Toggle bus connection state with a bus. Takes two indices, the initial bus and 
the second bus (see SimVars And Keys for more information). The bus index is 
the N index of the bus.N definition in both cases.

ELECTRICAL_BUS_TO_EXTERNAL_POWER_CONNECTION_TOGGLE    (MSFS SimVar)    
[0]: Source bus index
[1]: external power index
Toggle external power connection state with a bus. Takes two indices, the bus and 
the external power source (see SimVars And Keys for more information). The bus 
index is the N index of the bus.N definition, and the external power index is the 
N index of the externalpower.N definition.

The System.cfg entries for the connections in the C510 Mustang are:

  • [ELECTRICAL]
    bus.1 = Name:Main_BUS
    bus.2 = Connections:bus.1#Name:Essential_BUS
    bus.3 = Connections:bus.1, bus.2#Name:Hot_Battery_BUS
    bus.4 = Connections:bus.2#Name:Avionics_BUS
    battery.1 = Connections:bus.1, bus2, bus.3#Capacity:44#Voltage:curve.1#Name:Main_Battery ; Main Battery
    alternator.1 = Connections:bus.3#iEng:0#RatedVoltage:28.5#Load:curve.2#Name:LH_Alternator
    alternator.2 = Connections:bus.3#iEng:1#RatedVoltage:28.5#Load:curve.2#Name:RH_Alternator
    externalpower.1 = Connections:bus.1#RatedVoltage:28#Load:2500

    circuit.23 = Type:CIRCUIT_AVIONICS:1    #Connections:bus.1#    Power:20,25,20.0#    Name:Avionics_1 ; avionics 1
    circuit.24 = Type:CIRCUIT_AVIONICS:2    #Connections:bus.4#    Power:20,25,20.0#    Name:Avionics_Essential ; avionics 1

The MSFS SDK instructions for the dual indexed SimVars are:

SimVars permit you to get the state of a component, or the state of something in the 
simulation, and they are generally accesed using the following RPN format:
(A:[simvar_name]:[simvar_index], [units])

Sometimes a SimVar will require two additional index values, for example the SimVar 
CIRCUIT CONNECTION ON requires a circuit index and a bus index. Normally this would 
be written like this:
2 (>A:BUS LOOKUP INDEX, Number) (A:CIRCUIT CONNECTION ON:45, Bool)

However, some SimVars will permit an alterative "shorthand" method of using the two 
indices, like this:
2 (A:1:CIRCUIT CONNECTION ON:45, Bool)

Here, the 1: after the A: is used to tell the sim to send the top value on the stack
to the SimVar. This shorthand method is ONLY applicable to the following SimVars:

BUS CONNECTION                     ON
BATTERY CONNECTION             ON
ALTERNATOR CONNECTION      ON
CIRCUIT CONNECTION              ON
EXTERNAL POWER CONNECTION     ON
BUS BREAKER PULLED
BATTERY BREAKER PULLED
ALTERNATOR BREAKER PULLED
CIRCUIT BREAKER PULLED
EXTERNAL POWER BREAKER PULLED
 

Finally it should be noted that sometimes you will see simulation variables written using snake case, 
and prefixed with SIMVAR_, as that is how they appear in the simulation code itself. However when 
using them in RPN, you should omit the SIMVAR part as well as the _. For example:
SIMVAR_CIRCUIT_ON -> (A:CIRCUIT ON:1, Bool)

For the life of me, I cannot figure out how to code these activites in Lua:

  • Use the avionics switch to connect the bus to bus (dual index) 
  • Connect the battery to the bus (dual index)
  • Connect external power to the bus (dual index) while disconnecting the battery until the aircraft is started

A lot of data but probably a simple anser.

Posted

As to the question that is the title of this topic ('How to use SimVars / Events 2 indicies in Lua'), you have already given the answer - you would use the RPN calculator code and send it via ipc.execCalcCode

12 hours ago, DrDave- said:
  • Use the avionics switch to connect the bus to bus (dual index) 
  • Connect the battery to the bus (dual index)
  • Connect external power to the bus (dual index) while disconnecting the battery until the aircraft is started

Can you perform each of these activities in the VC (i.e. what buttons/switches/etc do you ? If so, how? Have you tried the following Input Events:

Quote

ELECTRICAL_Battery_1<;FLOAT64>
ELECTRICAL_Avionics_Bus_1<>
ELECTRICAL_Circuit_5<>
ELECTRICAL_Alternator_1<>
ELECTRICAL_Alternator_2<>

?
Not sure what they do, but maybe worth playing around with. Note that just because these are logged without a parameter, it doesn't necessarily mean that a parameter is not needed. And also remember that some input events have still not been exposed for external use, but more should be available in future SDK updates. You can check using the MSFS dev tools yo see what other    Input Events are avalalable, and also how they work if they look appropriate.

Other than that, I cannot really help you much with this. FSUIPC provides the tools to enable you to control an aircraft, but it is up to you to decide how these are used. I know very little about how the electrical systems work or are implemented for any specific aircraft (and don't understand how the system.cfg relates to the events/code that you would use to control the aircraft).  You should maybe try asking these questions on the aircraft support forums.

I can take a look in more detail at some point, but I do not have time for this at the moment. I still have quite a bit of work to do on the next release (Input Events), but can maybe take a deeper look once this has been released.

Please update  if you get any further with this or have further information (what UI/VC controls do you want to replicate?).

Posted
13 hours ago, DrDave- said:
  • Avionics Switch
  •  229641 *** EVENT: Cntrl= 67073 (0x00010601), Param= 1 (0x00000001) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE
  •  229656 *** EVENT: Cntrl= 67073 (0x00010601), Param= 1 (0x00000001) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE

For avionics power switch. you can use the ELECTRICAL_Avionics_Bus_1 input event, with a parameter of 1 for pwr, 0 for off.

13 hours ago, DrDave- said:
  • Battery Switch
  • 331609 *** EVENT: Cntrl= 66241 (0x000102c1), Param= 1 (0x00000001) TOGGLE_MASTER_BATTERY
  • 331609 *** EVENT: Cntrl= 67073 (0x00010601), Param= 3 (0x00000003) ELECTRICAL_BUS_TO_BUS_CONNECTION_TOGGLE

For the battery switch, you  can use the input event ELECTRICAL_Battery_1, with a parameter of 2 for EMER, 1 for Off and 0 for On.

Why can't you just use those rather than messing around with the bus connections?

As for external power, how would you do that in the VC? If this is via ground services, I am not sure this can be implemented, unless it is possible to assign a key combination for this (in MSFS).

Posted

Thank you for a comprehensive answer.

The thing I am concerned with is twofold. The input events may not have been used in this aircraft and Cockspur is not consistent in their answers. Let me please be specific.

I have downloaded the beta version. Is there any new document that covers input events in Lua?

Could you provide specific examples of Lua code to set an input event?

How would you code the following in Lua?  2 (>A:BUS LOOKUP INDEX, Number) (A:CIRCUIT CONNECTION ON:45, Bool) or 2 (A:1:CIRCUIT CONNECTION ON:45, Bool)

Thanks

Posted
1 minute ago, DrDave- said:

I have downloaded the beta version. Is there any new document that covers input events in Lua?

No - I will update the documentation for the official release. But there is just one additional function: ipc.execInputEvent(name, param), where name is the name of the input event (string) and param is the parameter (number/double float).

3 minutes ago, DrDave- said:

Could you provide specific examples of Lua code to set an input event?

As an example, to move the left condition lever in the King Air to low idle, use 
    ipc.execInputEvent("FUEL_1_Condition_Lever", 1 )
(change the parameter to 0 for high idle and 2 for cut-off).

7 minutes ago, DrDave- said:

How would you code the following in Lua?  2 (>A:BUS LOOKUP INDEX, Number) (A:CIRCUIT CONNECTION ON:45, Bool) or 2 (A:1:CIRCUIT CONNECTION ON:45, Bool)

    ipc.execCalcCode("2 (>A:BUS LOOKUP INDEX, Number) (A:CIRCUIT CONNECTION ON:45, Bool)")
or
    ipc.execCalcCode("2 (A:1:CIRCUIT CONNECTION ON:45, Bool)")

Isn't this all pretty obvious?

 

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.