Jump to content
The simFlight Network Forums

Recommended Posts

Hi there,

I am sorry if I sound silly asking, but I am trying to receive some critical info from FSUIPC (airspeed, etc.) through a C++ program. I have called FSUIPC_Open and then tried FSUIPC_Read, but the char is null. Is there any chance you can point me in the direction?

This is the code:

char speeds[3];


void launchfsuipc() {
DWORD dwCLOSED;
DWORD res;
if(FSUIPC_Open(SIM_ANY,&dwCLOSED)) {
//link ok
FSUIPC_Read(0x238, 3, speeds,&res);
stringstream ss;
ss << speeds[1] << speeds[2] << speeds[3];
MessageBoxA(NULL, ss.str().c_str(), "", MB_OK);
}
else {
//link failed
MessageBoxA(NULL, "YO HOMIE I FAILED", "YO", MB_OK);
}
}[/CODE]

Thanks,

--

Collin Biedenkapp

Link to comment
Share on other sites

I am sorry if I sound silly asking, but I am trying to receive some critical info from FSUIPC (airspeed, etc.) through a C++ program. I have called FSUIPC_Open and then tried FSUIPC_Read, but the char is null. Is there any chance you can point me in the direction?

All FSUIPC_Read and FSUIPC_Write do is add your request to the queue of requests waiting to be processed. Please look at the examples provided and read the text files and other documents provided. The only communication with FSUIPC occurs when you execute the FSUIPC_Process call. You should be accumulating all your requests for a sinlge Process each cycle, for efficiency, because each Process call involves a process switch. The read and write costs themselves are negligible, they just handle data in your own program.

Regards

Pete

Link to comment
Share on other sites

Ah, I was looking at the wrong example. I apologize, thanks!

I have used a code exactly as in the example (except for MessageBoxA due to a different character set and a C++ compiler), and I am getting garbage data in the strings for FSX time. How can I get a length of actual data received in order to use a null terminator?

Edited by Collin Biedenkapp
Link to comment
Share on other sites

I have used a code exactly as in the example (except for MessageBoxA due to a different character set and a C++ compiler), and I am getting garbage data in the strings for FSX time.

The FS time data isn't character based, but binary values -- i.e. numbers. If you want strings to display you'll have to convert numbers to string character representations, eg. by using sprintf or similar.

How can I get a length of actual data received in order to use a null terminator?

Numerical values have fixed defined lengths in any case -- a bytes is 1 bytes, a word is 2 bytes, etc. Different numbers have different sizes or representations. Any strings actually provided in the offset list are either of a defined length or already have a zero terminator in any case!

There's a FAQ subforum thread telling you about numbers and bits for those new to programming.

Pete

Link to comment
Share on other sites

This is my current function. I have read through the guides and I cannot figure it out. I am now unable to get the data to read properly, and I am unaware of the way to apply the expression formula.


unsigned short PITCH[2];

void launchfsuipc() {
DWORD dwResult;
if (FSUIPC_Open(SIM_ANY, &dwResult)) {
DWORD result;
FSUIPC_Read(0x842,2,PITCH, &result);
DWORD result1;
FSUIPC_Process(&result1);
//Does PITCH[0] not contain the correct value?
}

else
MessageBoxA(NULL, pszErrors[dwResult], "UIPChello: Failed to open link to FSUIPC", 0) ;

FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here
}[/CODE]

Link to comment
Share on other sites

This is my current function. I have read through the guides and I cannot figure it out. I am now unable to get the data to read properly, and I am unaware of the way to apply the expression formula.

What are you actually reading in PITCH[0]?

Why have you defined PITCH as an array of 2 16-bit unsigned words?

Offset 0842 is the vertical speed and as documented, it is one signed 16-bit word,i.e. 2 bytes long. You are correctly reading two bytes, so what is the other PITCH word for? And why "unsgined" when is distinctly tells you it is signed?

I don't understand why you'd want to call the vertical speed "PITCH", -- that smacks of carelessness. And what is this "expression formula" which you want to apply, and why can't you?

If you want the vertical speed in floating point feet per minute just do this:


signed short VS;
double verticalspeed;
...
FSUIPC_Read(0x842,2,&VS, &result);
...
verticalspeed = - (VS * 3.28084);
}[/CODE]

As always, please PLEASE take more care when looking up and checking offset use and access. Why aren't you using the tools provided, like Logging and FSInterogate to work out what you need to do?

Regards

Pete

Link to comment
Share on other sites

I apologize, again, and I thank you for your help. I was using FSInterrogate some, but clearly not enough. Upon your help and further investigation of the variables, I am able to receive and process them properly.

I appreciate the help, and I promise I will not post again until I have throughout researched the issue first. For the record, the PITCH variable was being used as I copied this code from another one I had written earlier, and I hadn't switched the variable name yet. I am storing them in a struct with their appropriate types and names now.

--

Collin

Link to comment
Share on other sites

I apologize, again, and I thank you for your help. I was using FSInterrogate some, but clearly not enough. Upon your help and further investigation of the variables, I am able to receive and process them properly..

Super! Glad you sorted it all out. I hope you manage to continue, but please don't feel unable to come back if you experience any more complex problems!

Pete

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.