jmsequeira Posted June 13, 2006 Report Posted June 13, 2006 Hi, I've been trying to get the plane current mass based on the "FSUIPC for Programers" document. Unfortunately, I can't understand how this FLOAT64 value is coded. I can see all the 8 bytes of this offset decreasing while the plane is flying, but I can't understand how can I use them to get the plane's current mass value. I tried several aproaches, including IEEE-754 floating-point recomendation, but it simply doesn't fit on this. My main question is: - How to get the plane's current mass from the 8 bit value on offset 0x30C8??? Thank you, Kind Regards J. Sequeira
Paul Henty Posted June 14, 2006 Report Posted June 14, 2006 You need to say what programmng languge you are using to get specific help for how to handle them in that specific language. However, in general you need to cast the 8-byte value directly to a 64 bit floating point type, (it's not an an 8byte Integer). The name of this type varies from language to language, as does the method of casting. In many languages the type you need is called a 'Double. Paul
jmsequeira Posted June 14, 2006 Author Report Posted June 14, 2006 Hi Paul, I'm using VB6. I based the code on a Peter Dowson's VB sample. Then I built some additional procedures and functions to handle each value. I'll try to follow your indication. However, I think I've tried to do exactly what you said. May be the implementation was not the correct one... The base sample I use to return integer values, is like this: Private Function Read_Value(v As Long, n As Long) As Double Dim dwResult As Long Dim r() As Byte Dim res As Double ReDim r(n) If FSUIPC_Read(v, n, VarPtr(r(1)), dwResult) Then If FSUIPC_Process(dwResult) Then res = 0# f = 1# For i = 1 To n res = res + f * r(i) f = f * 256# Next i Else ' Can't process End If Else ' Can't read End If Read_Value = res End Function How could I change this function to get a correct return to FLOAT64 value type? Thanks in advance, Kind regards, Joao Sequeira
jmsequeira Posted June 14, 2006 Author Report Posted June 14, 2006 Hi Paul (again), Based on the previous message I wrote you, I'm going to try this and tell you later if it works: ------------------------------------------------------------------------ Private Function Read_Value(v As Long, n As Long) As Double Dim dwResult As Long Dim r() As Double Dim res As Double ReDim r(1) If FSUIPC_Read(v, n, VarPtr(r(1)), dwResult) Then If FSUIPC_Process(dwResult) Then res = r(i) Else ' Can't process End If Else ' Can't read End If Read_Value = res End Function ------------------------------------------------------------------------ Kind regards, Joao Sequeira
Paul Henty Posted June 14, 2006 Report Posted June 14, 2006 Hi Joao, Your code looks like it will work (except you need to change the res = r(i) to res = r(1) ) However, it's a bit more compilcated than it need be - you don't need to use an array of doubles: This should be all you need to do, but I don't have VB6 on my machine anymore so I can't test it: ------------------------------------------------------------------------ Private Function Read_Value(v As Long, n As Long) As Double Dim dwResult As Long Dim res As Double If FSUIPC_Read(v, n, VarPtr(res), dwResult) Then If FSUIPC_Process(dwResult) Then Read_Value = res Else ' Can't process End If Else ' Can't read End If End Function ------------------------------------------------------------------------ Give that a try. If it doesn't work I'm sure a proper VB6 programmer will stop by and help you out. :-) Paul
jmsequeira Posted June 14, 2006 Author Report Posted June 14, 2006 Hi Paul, :D Thank you for your first comment. I tried the things I posted on the previous replies, and as I told you, I didn't succed on the first try. However, I was doing a mistake: the "n" parameter must still be "8", and not "1", as I put it, despite the fact that we are not getting separate bytes but a single value. So, putting the type as double, as you suggested, and putting n=8 on the function argument, the result is perfect! Then we just have to convert from slug's to pounds, and the value is exactly what we get from the Flight Simulator interface. Thanks a lot, :D Kind regards, Joao Sequeira Lisbon, Portugal
jmsequeira Posted June 14, 2006 Author Report Posted June 14, 2006 Hi again, :lol: Just to tell you were also right on your second reply... There's no need to use an array. So, the case is closed. Thank you once more, Joao Sequeira Lisbon, Portugal
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