Jump to content
The simFlight Network Forums

Recommended Posts

Posted
       private static async Task StartSimInputOutputLoop()
       {
           Console.WriteLine("Starting Input/Output loop...");

           await Task.Run(async () =>
           {
               try
               {
                   FSUIPCConnection.Open(); // Open connection ONCE

                   while (!stopSimLoop)
                   {
                       try
                       {
                           Console.WriteLine("Checking FSUIPC data...");

                           // Process pending inputs (Write to LVARs)
                           if (simdata_input_pending != null)
                           {
                               foreach (string input in simdata_input_pending)
                               {
                                   string[] i = input.Split(',');
                                   if (i.Length >= 2)
                                   {
                                       string lvar = i[0].Trim();
                                       if (float.TryParse(i[1].Trim(), out float newValue))
                                       {
                                           // Send command to update LVAR
                                           Offset<string> setLvar = new Offset<string>(0x0D70, 256);
                                           setLvar.Value = $"L:{lvar}={newValue}";
                                           FSUIPCConnection.Process();

                                           Console.WriteLine($" Updated LVAR: {lvar} = {newValue}");
                                       }
                                   }
                               }
                               simdata_input_pending = null;
                           }

                           // Read LVAR values properly
                           if (simdata_lvars != null)
                           {
                               simdata_output = new string[simdata_lvars.Length];

                               for (int j = 0; j < simdata_lvars.Length; j++)
                               {
                                   string lvarName = simdata_lvars[j];

                                   // Send request to get LVAR value
                                   Offset<string> getLvarRequest = new Offset<string>(0x0D70, 256);
                                   getLvarRequest.Value = $"L:{lvarName}";
                                   FSUIPCConnection.Process();

                                   // Wait a bit for FSUIPC to process the request
                                   await Task.Delay(100);

                                   // Retrieve the actual LVAR value from offset 0x66C0 (example offset)
                                   Offset<float> getLvarResponse = new Offset<float>(0x66C0);
                                   FSUIPCConnection.Process(); // Fetch updated value
                                   // Store and print result
                                   float lvarValue = getLvarResponse.Value;
                                   simdata_output[j] = $"{lvarName}: {lvarValue}";

                                   Console.WriteLine($" [TEST] Read LVAR: {lvarName} = {lvarValue}"); // Debugging output
                               }
                           }
                       }
                       catch (Exception ex)
                       {
                           Console.WriteLine($" FSUIPC Read/Write Error: {ex.Message}");
                       }

                       await Task.Delay(5000); // Wait 5 seconds before next update
                   }
               }
               catch (Exception ex)
               {
                   Console.WriteLine($" FSUIPC Connection Error: {ex.Message}");
               }
               finally
               {
                   FSUIPCConnection.Close(); // Close connection when stopping
               }
           });
       }



i run this task,  to read out about 80ish. lvars. 
" ? FSUIPC Read/Write Error: FSUIPC Error #15: FSUIPC_ERR_SIZE. The amount of data requested exceeded the maximum allowed in one Process()." 

this is the result. is their a limit to the ammount of lvar data in a procces??  

also @Pete Dowson is their anyway we can turn process into a Task? so we can use a await?

Posted

Which SDK are you using? If using Paul Henty's client dll then you should post in that forum (I can move this post id you like).
Other than that, the error should be obvious (as indicated by the message), but as your process calls are in the loop and process one read/write at a time,  I don't know why the data limit is exceeded. But I am not familiar with the SDK you are using.

22 hours ago, michielsweb said:

also @Pete Dowson is their anyway we can turn process into a Task? so we can use a await?

Pete retired more than 5 years ago now. There are various wrappers around the basic FSUIPC SDK, some of which provide an event-driven interface. with Pai; Henty's dll being the most advanced.
 

Posted

I am not familiar with the SDK you are using, but this:

On 2/3/2025 at 11:24 AM, michielsweb said:
                                   Offset<string> getLvarRequest = new Offset<string>(0x0D70, 256);

Offset 0x0D70 is only 128 bytes, not 256. This also doesn't seem correct:

On 2/3/2025 at 11:24 AM, michielsweb said:
setLvar.Value = $"L:{lvar}={newValue}";

To update an lvar, the value must first be written to offset 0x0D6C. But I am not familiar with the SDK you are using, or which FS you are using (there is probably an easier API to access lvars if using MSFS). Maybe @Paul Henty could comment as I presume this is using his dll.

Posted

Yes, it's my DLL.

To michielsweb:

If you're only targeting MSFS2020 or MSFS2024 then you should look at the MSFSVariableServices class. This is way more efficient at dealing with LVARs than the FSUIPC interface. There is a demo project on the website. http://fsuipc.paulhenty.com/#downloads

You're exceeding the FSUIPC data limit because you keep declaring a new copy of the offset every time the loop goes round...

	foreach (string input in simdata_input_pending)
                               {
                                   string[] i = input.Split(',');
                                   if (i.Length >= 2)
                                   {
                                       string lvar = i[0].Trim();
                                       if (float.TryParse(i[1].Trim(), out float newValue))
                                       {
                                           // Send command to update LVAR
                                           Offset<string> setLvar = new Offset<string>(0x0D70, 256);

You'll end up with hundred of these, all being processed at the same time which will easily exceed the data limit for FSUIPC.

Offsets should only be declared once, usually at the class level, and then reused.

Quote

 is their anyway we can turn process into a Task? so we can use a await?

I have no immediate plans to make the library async. If you want async behaviour on the Process() call you can create and await a new Task...

await Task.Run(() => FSUIPCConnection.Process());

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.