Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,
I'm trying to use MSFS Variable Services on two forms but when I try to create two events, one on each form gives me an error.
if I test one form at a time everything works fine.
When I call both StartEfisServices() and  StartRmpServices() gives me one error.

What am I doing wrong? 😞


Form1:

private MSFSVariableServices msfsVariableEfisServices = new MSFSVariableServices();
private FsLVar lVarEfisListen = null;

....
public Form1()
{...
InitMSFSEfisServices();
...
}

... StartEfisServices();

private void InitMSFSEfisServices()
{
   msfsVariableEfisServices.Init(Handle); // Initialise by passing in the windows handle of this form
   msfsVariableEfisServices.LVARUpdateFrequency = 10; // Check for changes in lvar values 10 times per second (Hz)
   msfsVariableEfisServices.Start();
}

private void StartEfisServices()
{
   lVarEfisListen = msfsVariableEfisServices.LVars["BTN_CSTR_1_FILTER_ACTIVE"];
   lVarEfisListen.OnValueChanged += lVarListen_OnValueEfisChanged;
   lVarEfisListen = msfsVariableEfisServices.LVars["BTN_VORD_1_FILTER_ACTIVE"];
   lVarEfisListen.OnValueChanged += lVarListen_OnValueEfisChanged;
}

__________________________________________________________________________
Form2:
....
public Form2()
{...
InitMSFSRmpServices();
...
}

... StartRmpServices();

private void InitMSFSRmpServices()
{
   msfsVariableRmpServices.Init(Handle); // Initialise by passing in the windows handle of this form
   msfsVariableRmpServices.LVARUpdateFrequency = 10; // Check for changes in lvar values 10 times per second (Hz)
   msfsVariableRmpServices.Start();
}

private void StartRmpServices()
{
   lVarRmpListen = msfsVariableRmpServices.LVars["A32NX_RMP_L_VHF2_STANDBY_FREQUENCY"];
   lVarRmpListen.OnValueChanged += lVarRmpListen_OnValueChanged;    <--------------------- Exception Thrown
   lVarRmpListen = msfsVariableRmpServices.LVars["A32NX_RMP_L_VHF3_STANDBY_FREQUENCY"];
   lVarRmpListen.OnValueChanged += lVarRmpListen_OnValueChanged;
}

give me the error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'

Posted

Creating multiple instances of MSFSVariableServices isn't going to work unfortunately. This feature relies on John's FSUIPC_WAPID.DLL which only supports one instance of the WASM Client.

With hindsight it was a poor design choice on my part to make MSFSVariableServices a normal class. This implies that it can be instantiated multiple times. I should have made it a static class. I might change this in a later version. Or I might think about forking the FSUIPC_WAPID.DLL and amending it so that it can handle multiple WASM Clients.

For your application I suggest creating a single instance of MSFSVariableServices in your application and use that same instance in any forms you need to. The easiest way to do this would be through a static class or a static property on your main form if you have one.

You can register different listeners inside each form and that will work fine. But the init(), start() and setting update frequencies etc must only be done once for that single instance.  You should also remove any listeners you have registered when your forms close.

Paul 

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.