aaj280174 Posted April 4, 2011 Report Posted April 4, 2011 Hi Pete! I'm trying to read the heading offset 0x580 in C + +. Based on the examples you provide in the FSUIPC SDK, there you proceed to read from offset 0x238, 0x239 and 0x23a. But with any other offsets always results in the same display in Printf 2293232. My idea is to collect and send the offset to a serial port which will control a pic showing the position of the servo gauge. Everything is ready, the difficulty is in reading the same offset. There is some code to release the offset gauge?. Recently got the key FSUIPC. Thanks Junior #include "stdafx.h" #include <time.h> #include <windows.h> #include "FSUIPC_User.h" #include "IPCuser.h" char *pszErrors[] = { "Ok", "Attempt to Open when already Open", "Não foi possível o link com o FSUIPC", "Failed to Register common message with Windows", "Failed to create Atom for mapping filename", "Failed to create a file mapping object", "Failed to open a view to the file map", "Incorrect version of FSUIPC, or not FSUIPC", "Sim is not version requested", "Call cannot execute, link not Open", "Call cannot execute: no requests accumulated", "IPC timed out all retries", "IPC sendmessage failed all retries", "IPC request contains bad data", "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC", "Read or Write request cannot be added, memory for Process is full", }; if (FSUIPC_Open(SIM_ANY, &dwResult)) { char chMsg[128], chTimeMsg[64]; unsigned int Heading[32]; BOOL fTimeOk = TRUE; static char chOurKey[] = "123456789ABC"; if (FSUIPC_Write(0x8001, 12, chOurKey, &dwResult)) FSUIPC_Process(&dwResult); if (!FSUIPC_Read(0x580, 4, Heading, &dwResult)|| !FSUIPC_Process(&dwResult)) // Process the request(s) fTimeOk = FALSE; if (fTimeOk) printf("HEADING = %d\n\n",Heading); else printf("Request for time failed: %s\n\n", pszErrors[dwResult]); } else printf ("PTEPS: Falha ao abrir link para FSUIPC\n\n\n", 0) ; FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here return 0 }
Pete Dowson Posted April 4, 2011 Report Posted April 4, 2011 I'm trying to read the heading offset 0x580 in C + +. Based on the examples you provide in the FSUIPC SDK, there you proceed to read from offset 0x238, 0x239 and 0x23a. But with any other offsets always results in the same display in Printf 2293232. You are just learning programming? Look at what you have done (I show the relevant lines only): unsigned int Heading[32]; if (!FSUIPC_Read(0x580, 4, Heading, &dwResult)|| printf("HEADING = %d\n\n",Heading); So "heading" is an array of 32 x ints. In other words, 32 x 32bit integers, or 32 x 4 = 128 bytes. The value of "Heading" is the address of this array on the stack. You read the 4 bytes from offset 0580 into the 4 bytes addressed by Heading, so in fact it will go into the first element of that array, i.e. into Heading[0]. But then you print the address of the array, not the contents of its first element! The correct three lines would be: unsigned int Heading; if (!FSUIPC_Read(0x580, 4, &Heading, &dwResult)|| printf("HEADING = %d\n\n",Heading); Since you only need one unsigned int, not 32 of them, you don't need an array. You send FSUIPC_Read the address -- the & preceding the name means "the address of ...". Pete
aaj280174 Posted April 4, 2011 Author Report Posted April 4, 2011 You are just learning programming? Look at what you have done (I show the relevant lines only): So "heading" is an array of 32 x ints. In other words, 32 x 32bit integers, or 32 x 4 = 128 bytes. The value of "Heading" is the address of this array on the stack. You read the 4 bytes from offset 0580 into the 4 bytes addressed by Heading, so in fact it will go into the first element of that array, i.e. into Heading[0]. But then you print the address of the array, not the contents of its first element! The correct three lines would be: unsigned int Heading; if (!FSUIPC_Read(0x580, 4, &Heading, &dwResult)|| printf("HEADING = %d\n\n",Heading); Since you only need one unsigned int, not 32 of them, you don't need an array. You send FSUIPC_Read the address -- the & preceding the name means "the address of ...". Pete
aaj280174 Posted April 4, 2011 Author Report Posted April 4, 2011 Hi pete! All understood I'm really at a basic level of programming, sorry. It worked perfectly after modifying the code, thank you. Junior
aaj280174 Posted April 9, 2011 Author Report Posted April 9, 2011 Hi Pete! Now this problem appeared in the reading. When I run the 0x580 offset reading the following happens: I have the Cessna 330 degrees of the bow and reading in c + + -571588881 output appears as shown in the log FSUIPC 3723378415. Thanks Hi pete! All understood I'm really at a basic level of programming, sorry. It worked perfectly after modifying the code, thank you. Junior
Pete Dowson Posted April 10, 2011 Report Posted April 10, 2011 When I run the 0x580 offset reading the following happens: I have the Cessna 330 degrees of the bow and reading in c + + -571588881 output appears as shown in the log FSUIPC 3723378415. They are exactly the same number, one is reading the unconverted 32-bit integer as signed and the other as signed. 330 degrees is the same as -30 degrees. Pete
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