Jump to content


Photo

Problem with writing large number


  • Please log in to reply
5 replies to this topic

#1 frankwas

frankwas

    Newbie

  • Members
  • Pip
  • 9 posts
  • LocationLondon

Posted 02 July 2013 - 02:14 PM

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


  • 0

#2 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 26,940 posts
  • LocationNear Stoke-on-Trent, UK

Posted 02 July 2013 - 02:27 PM

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.[/quote]

 

 

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


  • 0

#3 frankwas

frankwas

    Newbie

  • Members
  • Pip
  • 9 posts
  • LocationLondon

Posted 02 July 2013 - 02:41 PM

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.


  • 0

#4 frankwas

frankwas

    Newbie

  • Members
  • Pip
  • 9 posts
  • LocationLondon

Posted 02 July 2013 - 02:54 PM

I got it!!!

 

I had a look at the FSUIPC.cs file and noticed a function there that accepts a int32 parameter.

 

Tested it and it worked.

 

Thanks for the help.

 

F


  • 0

#5 Paul Henty

Paul Henty

    Advanced Member

  • Members
  • PipPipPip
  • 422 posts
  • LocationBristol, UK

Posted 02 July 2013 - 04:08 PM

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.simflig...net-version-20/

 

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

 

Paul

 

 


 


  • 0

#6 frankwas

frankwas

    Newbie

  • Members
  • Pip
  • 9 posts
  • LocationLondon

Posted 02 July 2013 - 07:48 PM

Hello Paul

 

I have only started writing.

 

Thank you so much for your input. Whatever makes it easier and more effecient is what I'm after. I will let you know if I get stuck.

 

Thanks again

 

F


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


About simFlight - simflight.com - simflight.de - simflight.fr - simflight.nl - simflight.pt - simflight.es - simflight.it - simflight.jp - simrussia.com - simMarket