Avi Posted September 11, 2005 Report Share Posted September 11, 2005 Hello, this is my first post in this forum, but from what i've seen before, it seems like a nice place to be.. However, I'm experimenting with FSUIPC and C# to get it to export values from the Artificial Horizontal to a C# program, and this is what I've got: public double GetHSIBank() { token = 0; dwResult = 0; dwOffset = 0x2F78; dwSize = 8; result = f.FSUIPC_Read(dwOffset, dwSize, ref token, ref dwResult); //TODO: Error handling result = f.FSUIPC_Process(ref dwResult); //TODO: Error handling result = f.FSUIPC_Get(ref token, ref dwResult); //TODO: Error handling return dwResult; } With this code I get strange values like 1443357819 and such. I know the code shouldn't work either, since it's a 8 bit float value being stored into an int, (It's a total ripoff of the ASI example), but I can't just figure out the right way to do it. If someone gave me a hint/sample on how it's supposed to be done it would be a lot of help. Thanks in advance.[/code] Link to comment Share on other sites More sharing options...
Pete Dowson Posted September 11, 2005 Report Share Posted September 11, 2005 I know the code shouldn't work either, since it's a 8 bit float value being stored into an int Not only can it not work, but it could easily crash the program, since the FSUIPC read will read 8 bytes (you've told it to) but will store them in a 4 byte area. The excess 4 bytes will trample on something else. (It's a total ripoff of the ASI example), but I can't just figure out the right way to do it. I don't know C# at all, but why not simply read an 8-byte double floating point value into an 8-byte double floating point variable. Isn't that logical? I cannot see why that would not be obvious? Regards, Pete Link to comment Share on other sites More sharing options...
Avi Posted September 11, 2005 Author Report Share Posted September 11, 2005 thanks for taking your time pete, as far as I understand, there's no overload of FSUIPC_Get() in the C# SDK that supports ref double, so would it be a better idea to read it into a byte[8] array and converting it to a double? Link to comment Share on other sites More sharing options...
Pete Dowson Posted September 11, 2005 Report Share Posted September 11, 2005 as far as I understand, there's no overload of FSUIPC_Get() in the C# SDK that supports ref double, so would it be a better idea to read it into a byte[8] array and converting it to a double? Ah, C++/C#-speak! ;-) Sorry, terms like "overload" (even "ref".which I assumed meant "the address of" or "a pointer to") are lost on me. I'm strictly C and ASM. But if you mean there's no way of passing a pointer to a double (which seems odd), then I suppose you could pass a pointer to any 8-byte entity, like a "long long" ("_int64") or a DWORD array[2], etc etc, then cast it into a double. Can you cast in C#? You shouldn't really need "conversion" as such, as the value is actually in floating point format -- conversion sounds like (and usually means) actual alteration to the bit pattern, which would be wrong. I suspect you need to talk to someone who knows C# before this gets too confusing! Regards, Pete Link to comment Share on other sites More sharing options...
Avi Posted September 11, 2005 Author Report Share Posted September 11, 2005 alright, thanks for the hints, I will take a look into it and report back with my findings tomorrow :) Link to comment Share on other sites More sharing options...
Avi Posted September 12, 2005 Author Report Share Posted September 12, 2005 got it to work cleanly now :) public double GetHSIBank() { byte[] HSI = {0, 0, 0, 0, 0, 0, 0, 0}; double HSID = 0; token = 0; dwResult = 0; result = f.FSUIPC_Read(0x2f78, 8, ref token, ref dwResult); result = f.FSUIPC_Process(ref dwResult); result = f.FSUIPC_Get(ref token, 8, ref HSI); //TODO: Error handling HSID = System.BitConverter.ToDouble(HSI, 0); return HSID; } Quite simple, reading the data into a byte array and converting it to double. Link to comment Share on other sites More sharing options...
Pete Dowson Posted September 12, 2005 Report Share Posted September 12, 2005 got it to work cleanly now :)... Quite simple, reading the data into a byte array and converting it to double. Good. Not that I understand why it is that complicated to transfer a double as a double. I'm spoiled by C's transparency I suppose. Regards, Pete Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now