Jump to content
The simFlight Network Forums

Efficiently Reading A Bunch of Offsets


Recommended Posts

Good day,

I am successfully able to read as many offsets as I want, but I realize I'm not doing so correctly. If I need data from 30 offsets, I run the following code 30 times, which means I'm also doing 30 reads and 30 process calls on EVERY loop iteration. This is really slowing things down once I try to read 10 or more offsets.

private void getData(int FSUIPC_Offset, int Offset_Length)
{
     result = fsuipc.FSUIPC_Read(FSUIPC_Offset, Offset_Length, ref token, ref dwResult);
     result = fsuipc.FSUIPC_Process(ref dwResult);
     result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
}

What's the best way to efficiently read a bunch of offsets at the same time? Are there any sample code snippets that show reading, then outputting multiple (maybe 5 or more) offsets? I realize Paul's .net example accesses many values at the same time, but what about from C, C# or others?

If, for instance, I'm reading 30 offsets using a loop, do I have to have to do all the FSUIPC_Read on every loop iteration, or do I just do all the FSUIPC_Read one time, then run FSUIPC_Process once on every loop iteration?

Thanks,

Robert

Link to comment
Share on other sites

You really need to ask in Paul Henty's subforum above. I'm sure he's implemented an efficient method.

For a C/C++ program written directly to the FSUIPC interface you would do as many FSUIPC_Read and FSUIPC_Write calls as you wished (and the can be mixed), providing you reserve sufficient space, then one Process call. You only need separate process calls for updates at timed intervals) or getting results of written requests. So, the answer to your question  Each Process call does process all the queued requests, so the requests are made again each time (there may well be different requests of course). Paul may have implemented an easier way as a layer on top of this.

Pete

 

Link to comment
Share on other sites

Hi Robert,

As Pete mentioned, with this old-style C# SDK you make multiple calls to Read(), then Process(), then multiple Get()s to get the values.

The key is the 'token' value which is assigned during the Read() and then used to by the Get() to return the correct value.

So to give you a real example...

// Declare 'tokens'
int tasToken;
int iasToken;
int verticalSpeedToken;

// Declare variables to hold the incomming values
int tasValue;
int iasValue
int verticalSpeedValue;

// Variable to check is everything was okay
int dwResult;

// Stack all your reads first (writes can also be stacked)
// Tokens will be assigned a value by the Read() method.
fsuipc.FSUIPC_Read(0x02B8, 4, ref tasToken, ref dwResult);
fsuipc.FSUIPC_Read(0x02BC, 4, ref iasToken, ref dwResult);
fsuipc.FSUIPC_Read(0x02C8, 4, ref verticalSpeedToken, ref dwResult);

// Single process will get all the stacked offsets
fsuipc.FSUIPC_Process(ref dwResult);

// Get the values
fsuipc.FSUIPC_Get(ref tasToken, ref tasValue);
fsuipc.FSUIPC_Get(ref iasToken, ref iasValue);
fsuipc.FSUIPC_Get(ref verticalSpeedToken, ref verticalSpeedValue);

// 'Value' variables are now filled.
double tasKnots = (double)tasValue / 128d;
// ... etc

It's not pretty, which is why I wrote my DLL.

I think the original C interface is cleaner than this. The 'Tokens' seem to be unique to the old C# and VB.NET SDKs because those languages don't have the concept of 'pointers' like C.

Paul

Link to comment
Share on other sites

This is very helpful. Thanks very much!

So the big difference from what I was doing is I still need to use do all the FSUIPC_Read(s) during every loop iteration, but I only need to call FSUIPC_Process, once.

I can see where keeping track of the tokens can get messy quickly. I thought about doing a token array, then tracking the elements, but I may look into switching to Paul's .net code, which seems a lot cleaner.

Thanks!

Robert

Link to comment
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
×
×
  • 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.