bajovirtual Posted October 22, 2010 Report Posted October 22, 2010 Hi everyone! first of all to thank the forum for so much information and help and I must say that my English is not very good because I am Argentine. I'm building an autopilot for FSX, with a LCD display and buttons on it, I use the buttons to select each item (ALT, HDG, NAV, etc) and the display shows me information such as altitude, heading, vertical speed, among others. The problem, until now the only one, is that I can not read the vertical velocity when it has a negative value when the plane is dropping, for example read the value 300 ft / min and reads it perfect (I'm working in Visual Studio 2010) but in trying to read a value as being down to 200 ft / min variable becomes "Vs = 64836" with more than worth -200 or -1200, the value is always "64836", know I'm doing wrong? with respect to other data (ALT, HDG, etc) I have no problem. I send the code to see him: Public AP_VS As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H7F2) Public AP_VS_ant As Integer FSUIPCConnection.Process() HDG = ((GRADOS_HDG.Value * 360) / 65536) ALT = ((ALTITUD.Value * 3.28084) / 65536) AP_VS_ant = AP_VS.Value Thank you very much and I hope you can help me!
Pete Dowson Posted October 22, 2010 Report Posted October 22, 2010 The problem, until now the only one, is that I can not read the vertical velocity when it has a negative value when the plane is dropping, for example read the value 300 ft / min and reads it perfect (I'm working in Visual Studio 2010) but in trying to read a value as being down to 200 ft / min variable becomes "Vs = 64836" with more than worth -200 or -1200, the value is always "64836", know I'm doing wrong? Yes, you are reading a 16-bit signed value into a 32-bit one, so the higher 16 bits stay zero including the sign bit. Offset 07F2 is 2 bytes (=16 bits), so it is a "short int" -- I don't know what that would be in the language you are using. 64836 in a 16-bit signed integer is actually 64836 - 65536 = -700. Note also that by reading 4 bytes (32 bits) instead of only the two, you are reading the lower 16 bits of the next value (at 07F4) as well. That is "RPM Hold". If the RPM hold is ever set your value yould be 65536 bigger again, because you'd get the "1" from the "RPM Hold On" flag`. Please ALWAYS take proper note of the size of each FSUIPC offset and use the most appropriate variable to match! The A/P heading value is also only 16 bits (2 bytes), so if you are doing the same for that you are only seeing success because you have the Altitude Lock switch off -- otherwise that too would read high. Pete
Paul Henty Posted October 23, 2010 Report Posted October 23, 2010 [This reply is a copy of the one I gave in my DLL thread after the original poster asked the same question there the next day. Posted here for anyone finding this while searching for the same problem] Your code is using the wrong data types. Each data type (e.g. Integer, Short, Double) stores a different amount of data. If you don't use the correct data type then you are getting the wrong values from FSUIPC. This happens because you end up getting the values of two offsets mixed together. Public GRADOS_HDG As Offset (Of Integer ) = New FSUIPC.Offset (Of Integer )(&H7CC) The "FSUIPC programmer's guide" clearly says this offset is 2 bytes long. You've used an Integer which is 4 bytes long. You need to use Short which is 2 bytes, like this: Public GRADOS_HDG As Offset (Of Short) = New FSUIPC.Offset (Of Short)(&H7CC) Public GRADOS_HDG_ant As Short All this is explained very clearly in the documentation that comes with my DLL. You need to read the "UserGuide.htm" document in the "Docs" folder in the zip you downloaded. Look at the section called "Registering your interest in an Offset". It has a table that tells you what variable type you need to use for each offset size and type. Following the rules laid out in that table your entire code should read: Public GRADOS_HDG As Offset (Of Short) = New FSUIPC.Offset (Of Short)(&H7CC) Public GRADOS_HDG_ant As Short Public ALTITUD As Offset (Of Integer) = New FSUIPC.Offset (Of Integer)(&H7D4) Public ALTITUD_ant As Integer Public AP_VS As Offset (Of Short) = New FSUIPC.Offset (Of Short)(&H7F2) Public AP_VS_ant As Short FSUIPCConnection.Process() GRADOS_HDG_ant = ((GRADOS_HDG.Value * 360) / 65536) ALTITUD_ant = ((ALTITUD.Value * 3.28084) / 65536) AP_VS_ant = AP_VS.Value Paul
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