rmjc Posted January 27, 2005 Report Posted January 27, 2005 I'm trying to read the Outside Air Temperature using offset 0E8C. I have the latest version of FSUIPC installed, and I'm reading other settings with no issues. However, this one, even when divided by 256 (per the programmers doc), still gives a number that is much too high. For instance, ATIS is showing a temp around 0, and I'm getting a number in the 250s. Any ideas?
Pete Dowson Posted January 27, 2005 Report Posted January 27, 2005 I'm trying to read the Outside Air Temperature using offset 0E8C. I have the latest version of FSUIPC installed, and I'm reading other settings with no issues. However, this one, even when divided by 256 (per the programmers doc), still gives a number that is much too high. For instance, ATIS is showing a temp around 0, and I'm getting a number in the 250s. Any ideas? Hmmm. Think about this: as the value is contained in only 16 bits (2 bytes) it is impossible for it to contain a positive value of anything greater than 31767, which after dividing by 256 would give you 124 degrees C, no where near your 250. So I assume that the temperature is below zero, maybe only slightly, and you are wrongly treating the number as unsigned! Please look in the FSUIPC SDK and find the program called FSInterrogate. ALWAYS check your results against those shown by FSInterrogate. If you get something different you have an error in your program. You can also use FSUIPC Logging. Go to the FSUIPC options, find the Logging tab and select IPC read logging. This will show the values actualy being supplied to your program. Regards Pete
rmjc Posted January 28, 2005 Author Report Posted January 28, 2005 I agree - based on what I see in FSInterrogate, I'm getting unsigned data back. I'm using the latest version of FSUIPC.bas to pull data back through Visual Basic. Here's the code I'm using to get the Outside temp value: Dim Success As Boolean Dim Data As Long Dim dwResult As Long Success = FSUIPC_Read(&H0E8C, 2, VarPtr(Data), dwResult) Success = FSUIPC_Process(dwResult) Debug.Print Data How can I tell FSUIPC.bas that I want to pull signed data, rather than unsigned, which is what it seems to be pulling? Thanks!
Thomas Molitor Posted January 28, 2005 Report Posted January 28, 2005 The OAT is a two byte value, so you have to use Integer not Long. Should look like that: Dim Success As Boolean Dim Data As Integer Dim dwResult As Long Success = FSUIPC_Read(&H0E8C, 2, VarPtr(Data), dwResult) Success = FSUIPC_Process(dwResult) Debug.Print Data Hope this helps Thomas
Pete Dowson Posted January 28, 2005 Report Posted January 28, 2005 I agree - based on what I see in FSInterrogate, I'm getting unsigned data back. Sorry, but you misunderstand something fundamental here. The data returned by FSUIPC has no types associated with it. How it is treated is entirely up to your code. If the 16-bit value is supposed to be signed it is up to YOU to read it into a signed variable. As far as the FSUIPC interface is concerned, its all just data, rows of bits if you like. There's no meaning at all associated with any of it until YOUR program determines what to do with it. Dim Success As Boolean Dim Data As Long Dim dwResult As Long Success = FSUIPC_Read(&H0E8C, 2, VarPtr(Data), dwResult) Well, I don't know VB at all, but your problem is staring at you -- you are reading 2 bytes (i.e. 16 bits) into a 4 byte (32-bit) variable. The top 16 bits of the 32 bit value should contain the propagated sign bit, but won't do so unless you make it. How can I tell FSUIPC.bas that I want to pull signed data, rather than unsigned, which is what it seems to be pulling? You can't and don't. You either need to declare the correct data type (a 16-bit signed value, not a 32-bit one), or work out a logical mthod of extending the sign bit into the top 16 bits, like "if value >= 32768 logically "OR" the value hex FFFF0000 into it". But I would hope that VB supported a 16-bit value, as the code will be better. Haven't you got any VB reference books? They surely must talk about number representations someplace, for learning VB programmers? Regards, Pete
rmjc Posted January 28, 2005 Author Report Posted January 28, 2005 Thanks to both of you! That was exactly my problem. I understand VB fairly well, but I forget how the underlying bits and bytes work at times. :oops: Thanks again! Robert
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