Jump to content
The simFlight Network Forums

Problem with writing large number


Recommended Posts

Hi All

 

Firstly, thanks Pete for the awesome module of FSUIPC that you have written and documented so well.

 

I am, however, stuck on something. I have been struggeling for days to get this to work but to no avail. I am trying to write the AP Altitude value into offset 07D4. From the numerous examples for C#, the values written are inserted statically. So for writing 30000, I used your provided calculations and got to the 32bit value of 599261164.8236427, rounded off to 599261165. When I put this into the write function it works like a charm and updates the AP altitude to 30000 as expected. However, I can't get it to accept a variable.

 

What I've tried so far is to convert the double variable to a byte array and then write each of the 4 bytes seperately to each offset, i.e. alt[0] for offset 07D4, alt[1] for offset 07D5, etc.

 

That didnt work. When I try to assign the double to a byte, it gives me an overflow error (which I expected) cause the value is way too large for a byte.

 

How do I get around this? I would really appreciate any help on this.

 

Here is a code snippet:

double apaltset;
byte temp2;
byte[] temp3;
apaltset = (30000 / 3.28084) * 65536.0;
apaltset = Math.Round(apaltset);
temp3 = BitConverter.GetBytes(apaltset);
temp2 = (byte) apaltset //value too large for byte

//result = fsuipc.FSUIPC_Write(0x07D4, 599261164, ref token, ref dwResult);  //this works
result = fsuipc.FSUIPC_Write(0x07D4, temp3, ref token, ref dwResult); //doesn't except a byte[]
result = fsuipc.FSUIPC_Process(ref dwResult);


Regards,

Francois

Link to comment
Share on other sites

I am, however, stuck on something. I have been struggeling for days to get this to work but to no avail. I am trying to write the AP Altitude value into offset 07D4. From the numerous examples for C#, the values written are inserted statically. So for writing 30000, I used your provided calculations and got to the 32bit value of 599261164.8236427, rounded off to 599261165. When I put this into the write function it works like a charm and updates the AP altitude to 30000 as expected. However, I can't get it to accept a variable.

 

 

I'm afraid I don't know C# -- it is really nothing like C at all. Perhaps you can explain some things to me:

 

What is "ref token"? Apart from in the calls to FSUIPC_Write I don't see it defined anywhere.  The value at that position should surely be a literal number, the length of the write, in bytes (4 in the case of offset 07D4)?

 

I don't understand how this following line can work at all desptite your comment:

 

fsuipc.FSUIPC_Write(0x07D4, 599261164, ref token, ref dwResult); //this works

 

 

 

because the 2nd parameter for the Write is normally a POINTER to the place in memory containing the data.  I would have though that number would be an invalid address and cause a crash.

 

As for the rest, I'm sorry, but it makes no sense to me.

 

Perhaps someone else here uses C# and can help? If you are using Paul Henty's .NET interface then he may help you.

 

Regards

Pete

Link to comment
Share on other sites

Thanks for getting back so quickly.

 

It works because it is an exact copy from the C# example in your FSUIPC SDK folder, apart from the offset and value of course.

 

Here is the example code from the C# solution:

            // Set latitude
            result = fsuipc.FSUIPC_Write(0x0564, 4454206, ref token, ref dwResult);
            result = fsuipc.FSUIPC_Write(0x0560, 901120000, ref token, ref dwResult);

I'm also not sure wat ref token is as I have not used it and is not required for my pusposes. All other methods work well and I'm able to extract data perfectly.

 

That number is from this equation: (30000 / 3.28084) * 65536.0.

 

You're right, maybe someone with C# knowledge could help.

 

It is true in the reasoning that it could be an issues with an address, but when that value is explicitly passed as in the examples, it works because it 'converts' to a byte of 32bit length and writes the value to the correct offset.

 

My issue is that I can't put a variable in the write function because that function can only accept a byte and a byte is too small for the value that needs to be passed.

Link to comment
Share on other sites

Hi Francois,

 

If you've not written too much code already you might want to take a look at my fsuipc interface dll for .NET.

 

It's much easier to use and has many more features than the old C# SDK that you are currently using.

 

Info and download here:

 

http://forum.simflight.com/topic/40989-fsuipc-client-dll-for-net-version-20/

 

The package contains the DLL, a reference manual, a user guide and sample projects in C# and VB.

 

Paul

 

 


 

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.