Nikko Agustino Posted May 3, 2013 Report Share Posted May 3, 2013 Hello forums, Currently I'm building an ACARS for my virtual airline. And I have a problem with BCD data from offset $034C, $034E, $0350, $0352, and $0354 which is shown as BCD. How can I store BCD data to delphi variable? I have searched on this forum and google but I can't find how to do it. FSUIPC_Read($0354, 4, @xpdr, dwResult); FSUIPC_Process(dwResult);label2.Caption := FloatToStr(xpdr);[/CODE]If I use the above code it only show 0 on the label.Regards,Nikko Link to comment Share on other sites More sharing options...
Pete Dowson Posted May 3, 2013 Report Share Posted May 3, 2013 Currently I'm building an ACARS for my virtual airline. And I have a problem with BCD data from offset $034C, $034E, $0350, $0352, and $0354 which is shown as BCD. How can I store BCD data to delphi variable? I have searched on this forum and google but I can't find how to do it. FSUIPC_Read($0354, 4, @xpdr, dwResult); FSUIPC_Process(dwResult);label2.Caption := FloatToStr(xpdr);[/CODE]If I use the above code it only show 0 on the label.I don't know Delphi at all, but I can immediately see two things wrong!1. Offset 0354 is [b]2[/b] bytes long but you've set 4! Why?2. The contents of 0354 is just a 16-bit value,[i] NOT [/i]floating point, so why try converting "FloatToStr"?Declare "xpdr" as an integer, and set it to zero first.After reading / processing, you can print it in hexadecimal, because the hex view of the value IS the transponder value. Each 4 bits is a digit, 0-7.Pete Link to comment Share on other sites More sharing options...
Nikko Agustino Posted May 3, 2013 Author Report Share Posted May 3, 2013 Hi Pete, Sorry for my mistake. I already change the code to integer value and the result is different from FS Interrogate value. Here is the result for some squawk. squawk result 1200 4608 2000 8192 7500 29952 7600 30208 7700 30464 I have no idea how to convert this. Or maybe I make another mistake to retrieve the value? FSUIPC_Read($0354, 2, @xpdr, dwResult); FSUIPC_Process(dwResult);label2.Caption := IntToStr(xpdr);[/CODE] Link to comment Share on other sites More sharing options...
Pete Dowson Posted May 3, 2013 Report Share Posted May 3, 2013 Sorry for my mistake. I already change the code to integer value and the result is different from FS Interrogate value. Here is the result for some squawk. squawk result 1200 4608 = 0x1200 2000 8192 = 0x2000 7500 29952 = 0x7500 7600 30208 = 0x7600 7700 30464 = 0x7700 Oh dear. I already told you, it is HEXADECIMAL!. I am sure Delphi has some way of converting a decimal number into a hexadecimal string!! Don't you have any reference books or "Delphi for Dummies" books to refer to? If not you will have to resort to VERY simple arithmetic -- Take the Remainder when dividing by 16 = 4th digit Take the Quotient from that and divide by 16, remainder = 3rd digit Take the Quotient from that and divide by 16, remainder = 2nd digit Take the Quotient from that = 1st digit Try it! Pete Link to comment Share on other sites More sharing options...
Nikko Agustino Posted May 3, 2013 Author Report Share Posted May 3, 2013 Hi Pete, I'm sorry it's a misunderstanding here. I think the xpdr value is hexadecimal and need to be converted to integer. I was wrong, it was the opposite. And now the following code is fully working. FSUIPC_Read($0354, 2, @xpdr, dwResult); FSUIPC_Process(dwResult);label2.Caption := IntToHex(xpdr, 1);[/CODE]Thank you very much Pete. Link to comment Share on other sites More sharing options...
Pete Dowson Posted May 3, 2013 Report Share Posted May 3, 2013 I'm sorry it's a misunderstanding here. I think the xpdr value is hexadecimal and need to be converted to integer. The value is a 16-bit binary number. It is neither a decimal integer or an hexadecimal one, it is simply a row of 16 bits, each of which is 0 or 1. It is the way you interpret it, the way you display it, which changes, never the value itself which is still always a row of bits. In the case of BCD, the hexadecimal way of showing it shows the correct Transponder code. It isn't the conversion of one type of value to another, only the way of showing it in printable/displayable form. 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