Hukken Posted September 20, 2016 Report Posted September 20, 2016 Hi. I'll get straight to the point: In LUA, is it possible to to read Offset data as sexadecimals? I'm asking because I'm trying to set up some external engine gauges for the Majestic Dash 8 300, and in the manual it states: ////////////////////////////////////////////////////////////////////////////////// // To be received via offsets 50C8 to 50DF // For Engine Data, value=0X0 to 0XA (where 0X0 to 0X9 is the digit and 0XA is a blank digit) . // For Engine Data, Digit 0 in bites 0,1,2 & 3 of Byte 0; Digit 1 in bites 4,5,6 & 7 of Byte 0; // For Engine Data, Digit 2 in bites 0,1,2 & 3 of Byte 1; Digit 3 in bites 4,5,6 & 7 of Byte 1; // Example for Engine Data: NH1, value 88.5 would be: Byte 0 = 0XA8, Byte 1 =0X85. ////////////////////////////////////////////////////////////////////////////////// Description Offsets and range NH1 Offsets 50C8 & 50C9….range 000.0 to 199.9 TRQ1 Offsets 50CA & 50CB….range 000.0 to 199.9 FF1 Offsets 50CC & 50CD….range 0000 to 1999 PROP1 Offsets 50CE & 50CF….range 000.0 to 199.9 NL1 Offsets 50D0 & 50D1….range 000.0 to 199.9 ITT1 Offsets 50D2 & 50D3….range 0000 to 1999 So I guess I need the offset values available as hexadecimals in strings. When using ipc.readSB(offset) the value is only available as decimal number.
Pete Dowson Posted September 20, 2016 Report Posted September 20, 2016 3 hours ago, Hukken said: I'll get straight to the point: In LUA, is it possible to to read Offset data as sexadecimals? Assuming you meant "hexadecimal", then all vlaues are supplied as numbers. They are in binary, so you can express them any way you like. 3 hours ago, Hukken said: When using ipc.readSB(offset) the value is only available as decimal number. No. A number is only in "decimal" if it is converted into a decimal string using "string.format" or attached to a string. All numbers in computers are in binary -- i.e. strings of bits. This is fundamental to any understanding of programming. If you want hexadecimal strings you use a string.format with the %X facility. However, if you want to test or manipulate bits, which is what I assume you want to do, you should use the binary number as received. Otherwise you will have a lot more difficulty! Extracting or testing bits is done in Lua using the logic library functions supplied by FSUIPC. (Lua itself does not include bit manipulations, which is why I added these functions). BTW the programmer of that aircraft seems to have gone out of his way to make it complicated! Pete
Hukken Posted September 21, 2016 Author Report Posted September 21, 2016 Hi Pete, Thank you for the reply. 8 hours ago, Pete Dowson said: Assuming you meant "hexadecimal", then all vlaues are supplied as numbers Correct 8 hours ago, Pete Dowson said: No. A number is only in "decimal" if it is converted into a decimal string using "string.format" or attached to a string. All numbers in computers are in binary -- i.e. strings of bits. This is fundamental to any understanding of programming. If you want hexadecimal strings you use a string.format with the %X facility. However, if you want to test or manipulate bits, which is what I assume you want to do, you should use the binary number as received. Otherwise you will have a lot more difficulty! OK, so if I have understand correctly; when the following lines of code outputs 168, it's a binary number? That does not sounds correct? n = ipc.readUB(50C8) ipc.display(n) 9 hours ago, Pete Dowson said: BTW the programmer of that aircraft seems to have gone out of his way to make it complicated! I agree one hundred percent!!
Pete Dowson Posted September 21, 2016 Report Posted September 21, 2016 41 minutes ago, Hukken said: OK, so if I have understand correctly; when the following lines of code outputs 168, it's a binary number? That does not sounds correct? All numbers in the program are in binary! It is how numbers are represented in computers! If you display it then the Lua functions convert it to a string. Your byte value n is 168 in decimal but it is actually the bits 10101000, or hex A8. To display or log a value it has to be converted to character form, which is NOT the same as being a number! Characters are actually represented by ASCII binary numbers, so "168" in a string or display is in the computer as hexadecimal 313638. A new line would be decimal 10 or hex 0A and a return/enter decimal 13 or hex 0D. I think you need to get your head around numbers in computers before you can mess with the values you need. Pete
Hukken Posted September 21, 2016 Author Report Posted September 21, 2016 (edited) 12 hours ago, Pete Dowson said: I think you need to get your head around numbers in computers before you can mess with the values you need. You probably right. But despite my lacking knowlegde on basic computer numbers, I've now manged to extract the relevant values from the SIM and done the necessary processing in Lua. Now, with the correct values I can go back to the original program which is to set up some external gauge in Air Manager. Anyway, thanks for your inputs Pete. I got what I needed, and still learned some basic computer numbers! ;) Edited September 21, 2016 by Hukken
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