Jump to content
The simFlight Network Forums

Byte array to double


Recommended Posts

Hi Pete and all!

Just firstly want to thank you for FSUIPC!! It has opened up a whole new and exciting chapter in my life of programming and electronics!

I have gotten stuck at one point. I have managed to read all the values that I wanted and converted them correctly.

However, I cannot for the life of me get the correct value of any of the deflection values for elevator, aileron, etc. My difficulty is trying to convert the value to a double. It might sound elementary but I just can't get it right. I am using delphi 7.

I would really appreciate your and anyone else's help on this matter.

Regards,

Francois

Link to comment
Share on other sites

However, I cannot for the life of me get the correct value of any of the deflection values for elevator, aileron, etc. My difficulty is trying to convert the value to a double. It might sound elementary but I just can't get it right. I am using delphi 7.

If you mean the values in offsets 03B0, 03B8, 2E98 - 2EC0, then no conversion is needed -- as stated in the offsets list, they are already in double form! Simply read them into a double variable and you are done. No conversion.

Pete

Link to comment
Share on other sites

Do I just add all these values in order to get the result then?

Add all what values? It makes no sense to add different deflection values, surely? Why would you add elevator deflection to airleron deflection to rudder deflection, etc?

Please tell me what you are trying to do with these values, as it seems I cannot understand your problem at all at present!

Pete

Link to comment
Share on other sites

Sorry, I was looking at the incorrect value.

Here is an example for how I have been extracting and using the values. I am sure there is a much better way of doing it, but I don't know how.

Read:

FSUIPC_Read($02B4, 4, @groundSpeedAR, dwResult);

After processing:

A_GroundSpeed := (((groundSpeedAR[1] + (groundSpeedAR[2]*256) + (groundSpeedAR[3]*256*256) + (groundSpeedAR[4]*256*256*256))));

A_GroundSpeed := (A_GroundSpeed*3600/65536/1852)*3.6;

This method has consistently given me accurate readings (I always check with FSInterrogate).

What would be a better way to assign the byte array to the double variable? The above is of course a 4 byte array wheras the segment at 2E98 is 8 bytes.

I would like to read the values that change as the AP flies. I got the 2E98 address as well as others from another post on the forum that someone asked for getting force feedback to work.

I hope this makes sense.

Thanks

Francois

Link to comment
Share on other sites

FSUIPC_Read($02B4, 4, @groundSpeedAR, dwResult);

After processing:

A_GroundSpeed := (((groundSpeedAR[1] + (groundSpeedAR[2]*256) + (groundSpeedAR[3]*256*256) + (groundSpeedAR[4]*256*256*256))));

A_GroundSpeed := (A_GroundSpeed*3600/65536/1852)*3.6;

Good gracious! How extraordinary! Why are you using arrays for single numerical values?

Since the groundspeed is a simple 32 bit integer why not simply read it into a 32-bit integer and use it directly?

i.e delete that first "after processing" line and simply change the read to:

FSUIPC_Read($02B4, 4, A_GroundSpeed, dwResult);

What would be a better way to assign the byte array to the double variable? The above is of course a 4 byte array wheras the segment at 2E98 is 8 bytes.

I don't understand why you are using byte arrays in the first place. What gave you such an idea? Why not just define the values you are reading into to a variable of the type they actually are? You are making life extremely complicated for yourself, and quite ineffiicent.

I got the 2E98 address as well as others from another post on the forum that someone asked for getting force feedback to work.

You should ONLY be getting offsets and their definitions from the documentation which lists and defines them !!!

Pete

Link to comment
Share on other sites

Thanks for the help Pete

I changed the code as you recommended. However, for some reason I am getting a tiny value (10^-301)? A_GroundSpeed is a real. I tested it with a double and extended. I don't know what I am doing wrong. Also, if I don't have the @ in front of the variable, it does not take it. It gives me a compiler error [Error] MainForm.pas(194): Incompatible types: 'Extended' and 'Pointer'.

Thanks in advance for your help.

Link to comment
Share on other sites

I changed the code as you recommended. However, for some reason I am getting a tiny value (10^-301)? A_GroundSpeed is a real. I tested it with a double and extended.

I've no idea what a "real" or an "extended" is. If a "double" in the language you use is a 64-bit standard floating point vaslue, then that is the correct type to read values from offsets defined as doubles (i.e. 8 byte or 64-bit floating point numbers) in the offsets list.

However, as i said, the groundspeed is a simple 32 bit integer, so the receiving value should be defined as such. An "Integer" most likely. Don't you have any references for your language. 32-bit integers are the most common numbers in current 32-bit programs of course.

Also, if I don't have the @ in front of the variable, it does not take it.

What does the "@" do? Take the address? If so, why don't you have one in front of "dwResult"? Why doesn't that fail? That should be the address of a 32-bit integer to receive the error number if the call should fail -- likewise the parameter before it receives the value you are reading. Why would one need an @ and not the other? Maybe you are still defining it as an array, so need to take its address? I don't know. If you don't know the language -- and I'm afraid I certainly don't -- you need to talk to someone who does or refer to a book on it.

Why not at least paste the code here so that those who know can at least check what you've done? You need to post the declarations and well as the function calls.

[LATER]

Checking here: http://www.delphibasics.co.uk/Article.asp?Name=Numbers I see that "double" is certainly the right type for 8-byte 64-bit floating point numbers. I couldn't see a "real"..and it certainly isn't an "extended" with it an 80 bit (10 byte) floating point value.

For 32-bit integers it shows "LongWord" or "Integer" or "LongInt".

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.