Jump to content
The simFlight Network Forums

VB.NET and Fsuipc


Recommended Posts

Hi,

I'm writing a little program in VB.NET (2008) accessing FS values through Fsuipc.dll using the code provided in the SDK and written by Bob Scott (who adapted it from the original VB code by Chris Brett).

Although I have no problems reading individual values, there are times at which I would like to read a longer block of bytes. For example, latitude, longitude, altitude, pitch, bank and heading all appear one after the other, so instead of reading all these values individually, it seems to be more time-saving to read the entire block once and then split up the bytes as I need them.

The problem for me is the function Read_FSUIPC which requires an integer for the token. The Get_FSUIPC provides an overload function to copy stuff into an array of bytes, so that's no problem. But I don't know how to handle the Read_FSUIPC function. Can someone give me an example or direct me to some site where examples are available.

Thanks a lot for your help

Sascha

Link to comment
Share on other sites

Although I have no problems reading individual values, there are times at which I would like to read a longer block of bytes. For example, latitude, longitude, altitude, pitch, bank and heading all appear one after the other, so instead of reading all these values individually, it seems to be more time-saving to read the entire block once and then split up the bytes as I need them.

As long as you aren't doing a "Process" call for each individual one, they are blocked up for you in terms of the actual transfer of data. Except for some red tape added for each read the only saving you make by using one read instead of several is in the calls to the read function (which is in your program).

However, that said, I myself far prefer to read data in structures, such as the "LLAPBH" one you mention (LLAPBH = Lat Lon Alt Pitch Bank Heading, and is actually a structure inside FS's own code). In some cases you really do need to write data as one block too, or else the order gets critical and timing becomes an issue.

Where all the values are of the same type you presumably use an array. Even the LLAPBH set could be read as an array of 9 integers -- but then you'd have to be careful to join up the high and low parts of the 64-bit values carefully, and take care of those parts which are signed and those that are unsigned. I think VB has some difficulties with unsigned numbers.

In most languages you can define structures, which are just collections of values of possibly different types, in a defined arrangement. I don't know if VB supports such things or not.

The problem for me is the function Read_FSUIPC which requires an integer for the token. The Get_FSUIPC provides an overload function to copy stuff into an array of bytes, so that's no problem. But I don't know how to handle the Read_FSUIPC function. Can someone give me an example or direct me to some site where examples are available.

Ah, now you've lost me. There's a "Get" as well as a "Read"? What's the token for? I assume this is something to do with the fact that VB.NET is "managed" or "interpreted" rather than real native code?

Isn't the interface package provided by Paul Henty of use here? See viewtopic.php?f=54&t=53255

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

Thanks a lot for the detailed answer which despite its length did not answer any of my questions. I know about structures, arrays and all that stuff. My question was simply: if Read_FSUIPC accepts only an integer for a token (=destination), what can I do in the case of arrays (of bytes), structures or whatever. Can someone who is familiar with VB.Net and the code in the SDK package provide some sample code or hint.

Thanks a lot for your help

Sascha

Link to comment
Share on other sites

Thanks a lot for the detailed answer which despite its length did not answer any of my questions. I know about structures, arrays and all that stuff. My question was simply: if Read_FSUIPC accepts only an integer for a token (=destination), what can I do in the case of arrays (of bytes), structures or whatever.

Sorry I've no idea what on Earth a token is needed for at all, and certainly not how it relates to the type of data, so I can't help with that part. I assumed you knew VB.NET, as a user of that system, but not about FSUIPC and C type structures and arrays.

There's no tokens used in the FSUIPC part of the interface so that must be some VB.NET contrivance. I know folks do read and write FSUIPC strings and double floating point values in VB.NET, so it must certainly be possible despite the "token" only being an integer. I suspect the token isn't related to the data type so much as a way of identifying the bit of memory it occupies, a kind of C pointer replacement? If so it shouldn't matter what form the data takes, so structures should be okay.

Regards

Pete

Link to comment
Share on other sites

Sascha,

Pete did answer your question. As long as all the individual reads are stacked up before a single process you will save no time at all by reading a large block and splitting out the individual variables manually.

However if you really must do it like this, here is what you would do...

The Token is merely a reference to the data you want. It's not the actual data. So regardless of the length of the data you are reading the token is always an integer. The token is peculiar to this poorly implemented FSUIPC SDK and is why I wrote my DLL that Pete referred to.

1. You set up the read as normal: You declare the start offset of the data block and the length of the entire data block (ie, the length of all the offsets added together). You get an integer token as normal.

2. Then you process.

3. Then you get your byte array back using the appropriate Get() overload, passing your integer token (which identifies the start of your data block) and the length of the entire data block again (dwSize). This will copy the raw bytes from FSUIPC into the byte array you passed into the Get() function.

4. So now you have an array of bytes which you must split up into individual variables. For this you need to use the BitConverter class. It has methods (e.g. ToInt32(), ToDouble() etc.) which take an array of bytes and a start address in that array where the variable starts. You can get an idea of how to use these by looking at the Get() methods in the source for the VB.NET SDK. Basically if the first variable in the data block is the latitude (64bit int (8bytes)) and the second is the Longitude (also 64Bits (8 bytes)) you would do this:

Dim myLat as Long
Dim myLon as Long
myLat = BitConverter.ToInt64(myArrayFromFSUIPC,0)
myLon = BitConverter.ToInt64(myArrayFromFSUIPC,8)

and so on for each variable in your large data block.

So that's how you would do it. But I assure you it's a complete waste of time.

Paul

Link to comment
Share on other sites

Hi Paul,

That was exactly the type of information I was looking for. Thank you very very much. My problem was that I wasn't sure what was meant by a "token" and that I did not understand the significance of the Get(..) functions. Now thanks to you and Peter everything is clear and I can proceed.

I guess the real important information from Pete and you was that I don't save time as long as I use only one Process for multiple Reads. So I leave it that way, the code is much more readable that way.

Thanks again

Sascha

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.