Jump to content
The simFlight Network Forums
NaMcO

Reading LVARs through WideFS

Recommended Posts

Hello Paul,

First of all, thank you for your great DLL. It's of major help.

Now, straight to the point... I am trying to read FlightSimLabs A319/A320 lights, and when reading the LVARs directly on the PC with the simulator, everything works smoothly and correctly. When reading them on a remote PC with a properly working WideFS and WideClient, these methods don't seem to work reliably. I can read regular simulator data, but the LVAR values aren't updated correctly.

Sometimes i turn on the strobe, nav and landing lights and nothing happens. Then i decide to turn on the taxi lights and ALL lights turn on. If i turn the taxi lights off again, EVERYTHING turns off. This might happen with taxi lights as the trigger or strobe or nav... it seems to happen randomly.

Do you have any idea of what might be going on here? Some sort of sync failure... Unsupported commands through WideFS maybe?

 

Thank you,

Nuno

 

Share this post


Link to post
Share on other sites

Hi Nuno,

I've had a look at my code. I can't see anything that would be an obvious problem on WideClient rather than a direct connection to the sim. There is nothing that is sensitive to timing in the DLL code.

One thing to note is that DLL uses 'user offsets' 0x66F8 to 0x66FF inclusive to transfer the LVAR value. When you test with WideClient, do you have any other FSUIPC programs running that might use this offset that are not running when you test locally?

@Pete Dowson The documentation for the LVAR read/write says that everything can be done in one process. That's how I've done it to get the best performance. Is there anything about the WideFS connection that could mess this up? Values cached locally in WideClient for example?

Paul

Share this post


Link to post
Share on other sites

Thank you Paul,

I am also calling your method from within an async task so it doesn't lock the main thread AND inside an open FSUIPC connection. I don't know if that affects anything. Let me try to put the relevant parts of the code here...

So, this is the timer:

        private void FlightTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan time = stopwatch.Elapsed;
            LogClock.Text = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);

            if (!ProcessAcarsData.IsBusy)
                ProcessAcarsData.RunWorkerAsync();
        }

This is the task. What it does is simply call the UIPCProcess method below, which is in a helper class for separation:

        private void ProcessAcarsData_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                UIPCQuery.UIPCProcess(Resources.UIPCAcarsData);
            }
            catch (FSUIPCException)
            {
                e.Cancel = true;
            }
        }

       public static void UIPCProcess(string processname)
        {
            FSUIPCConnection.Process(processname);
        }

 

And the work completed method where the checklights function is called, making use of the readLVARS method from your DLL. There is an active FSUIPCConnection at this point.

        private void ProcessAcarsData_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            if (e.Error == null && !e.Cancelled)
            {
               *** Some other things are done here which were removed for clarity, then i check for the lights here:
                    CheckLights();
                }

               *** Some other checks here, removed for clarity
            }
            else
            {
                FlightTimer.Enabled = false;
                OpenFSUIPCTimer.Enabled = true;
                ProcessFSUIPCError(e.Error == null ? Resources.errorSimCommunication : e.Error.ToString());
            }
        }

 

I don't know if this helps trying to figure out what's going on here, if no ideas come up i guess i'll write a new and clean small piece of code just to test read all the data i need to see if everything is working the way it should.

Share this post


Link to post
Share on other sites

The async call looks okay from what you've posted.

Quote

i guess i'll write a new and clean small piece of code just to test read all the data i need to see if everything is working the way it should.

That's probably the best way to proceed with these kind of issues. If you just make a single-thread program that read/writes the lights LVARS and see if there's any difference when you run over WideFS.

That will at least tell you if the problem is with LVARS over WideFS or if it's more to do with the way you're calling the DLL (probably some kind of threading problem).

Paul

Share this post


Link to post
Share on other sites

Hello again,

Unfortunately the outcome is exactly the same...

Here is the simple timer implementation, running every 500ms but even at 2s the outcome is the same.

        private void FSTimer_Tick(object sender, EventArgs e)
        {
            UIPCQuery.UIPCProcess("LightData");

            rbLanding.Checked = UIPCQuery.LandingLights();
            rbNav.Checked = UIPCQuery.NavLights();
            rbBeacon.Checked = UIPCQuery.BeaconLights();
            rbStrobe.Checked = UIPCQuery.StrobeLights();
            rbTaxi.Checked = UIPCQuery.TaxiLights();

        }

Each of the called methods is similar to this. This one is testing specific hardcoded FlightSimLabs and TFDI models for landing lights.

        public static bool LandingLights()
        {
            double fsLabsLLLeft = FSUIPCConnection.ReadLVar("L:VC_OVHD_EXTLT_Land_L_Switch");
            double fsLabsLLRight = FSUIPCConnection.ReadLVar("L:VC_OVHD_EXTLT_Land_R_Switch");
            double tfdiLLLeft = FSUIPCConnection.ReadLVar("L:B717_ovhd_lights_ldgltl");
            double tfdiLLRight = FSUIPCConnection.ReadLVar("L:B717_ovhd_lights_ldgltr");

            return fsLabsLLLeft > 10 && fsLabsLLRight > 10;
        }

In the simulator PC, everything is working perfectly, each switch operates the respective light and it shows correctly on screen. Using WideFS, a single switch (which seems to be the LAST in the sequence, in this case taxi lights - UNCONFIRMED) operates all others and changes all others state as well:

- I switch landing lights to ON, beacon to ON and then operate taxi and change it to OFF and all others turn OFF as well. If i switch it ON, all others switch to ON as well.

If you believe a video would help i can make a short video of what's happening.

Thank you

Share this post


Link to post
Share on other sites

Okay, that rules out threading problems. So it's something to do with WideFS.

Can you clarify a few things...

How are you operating the lights? Directly in the sim? Writing to offsets/controls?

When you say all the lights turn OFF, do you mean in the sim, or just that your program is reading them as OFF but they are really still ON.

Paul

Share this post


Link to post
Share on other sites

I am operating the lights either in the Virtual Cockpit or in a popup 2D panel to make sure i test all possibilities. I just want to read the status, so i am not writing to the simulator.

In the sim, everything stays the same, only what i read is changing which kind of makes sense since i'm not writing data.

Nuno

 

Share this post


Link to post
Share on other sites

Understood. Thanks.

I think I know what the problem is. I'll need to speak to Pete about it and get back to you.

Paul

 

 

Share this post


Link to post
Share on other sites

Okay, thank you very much for looking into this.

If you need any additional information just drop me a line. Cheers!

Nuno

Share this post


Link to post
Share on other sites

I've just seen that Pete's away until Friday. I've posted my question in the main forum, so we'll have to wait until he gets back to see if anything can be done.

Paul

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

So, after reading Pete's reply, i decided to implement my own method and i got it working.

The only way i can think of making this work correctly with FSUIPCClient is if you keep some sort of queue which keeps track of incoming LVARS to read and processing them in different user offsets that can be read and returned. I don't know whether this would work ok over WideFS due to some lag that might exist.

So, receive LVAR, process in 0x66c0, read and send response, then next on 0x66c8, read and send response... Once you get out of free space, loop back to 0x66c0, rinse and repeat.

The method i'm using is similar to that, creating dynamic offsets and deleting them, i still have to fully test this and see if it's good to go, but it seems ok.

 

Anyway, this has helped me a lot solving my problem, can't thank you enough and @Pete Dowson as well. I guess i'll make a donation for your time, nothing like a fresh pint eh 😛

Share this post


Link to post
Share on other sites

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

×

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.