Jump to content
The simFlight Network Forums

Reading String ofsets in VB.Net


Recommended Posts

Hi,

I'm having problems reading strings from FSUIPC...

            ' Aircraft Type
            Dim FSAircraft As String
            ReDim dwBytes(256)
            If myFSUIPC.FSUIPC_Read(&H3D00, 256, dwBytes(256), dwResult) Then
                If myFSUIPC.FSUIPC_Process(dwResult) Then
                    MsgBox(dwBytes(256))
                End If
            End If

Am I going about this the wrong way??? The return value is always 29...

I'm also using something similar to detect whether the simulator is ready. Again, is always returns non zero (Never ready), even when I'm flying :?:

Link to comment
Share on other sites

Am I going about this the wrong way??? The return value is always 29...

Sorry, I don't know VB, nor do I know the number 29... (are there more digits? The full number may give a clue?). I see you define a string called FSAircraft but then don't seem to use it. What does "ReDim" do? It seems to be applied to dwBytes not FSAircraft?

Apart from those oddities (to me at least) I think I see at least wo things wrong with your code:

1. I don't think you can pass "dwBytes(256)" as anything meaningful in that parameter position. 256 is presumably the length of the array, but isn't "dwBytes(256)" then simply the 256th or 257th (depending whether VB counts from 1 or 0) byte in that array? I have no idea what it has in it, but passing it over to FSUIPC isn't doing any good. You need to pass a pointer to the first element of the array, something to do with "varptr" I believe. Please look it up in your "VB for Beginners" book.

2. I don't think that "bytes" and "character strings" are the same thing in VB as they actually are in the real machine (and in C). You have to do something to make a string with the array of bytes you receive.

Do you have any books to help you with VB? It is not easy to jump straight into something sophisticated like the FSUIPC interface without knowing the language first.

Regards,

Pete

Link to comment
Share on other sites

Hi Pete,

Yes, the value is always 29. Regardles of what plane, regardless of what state the simulator is in. The same is also happening with offset 3364 (Simulator ready) - which, never returns the 0 state.

I'm sure I'm doing something wrong here... The problem is what :D

Just quickly in regards to your suggestions, questions and answers...

1) ReDim, reinitialise and changes the size of the variable. In the case below, I changed the length of the array

2) More than likely not yes. There is a function ToString which will convert it. That didn't work either however.

3) The unused String was just me testing... I originally had:

If myFSUIPC.FSUIPC_Read(&H3D00, 256, FSAircraft, dwResult) Then

But that didn't work either. It also returned 29 :cry:

And yes, it returns '29'. Nothing more, nothing less.

I'm not a VB.NET pro no. I'm merely trying to figure out at this stage how things work.... The below for example, works right when it returns the state the the simulater is not ready. It does not return correctly when the simulator is ready however...

            ' Is Simulation Ready?
            If myFSUIPC.FSUIPC_Read(&H3364, 1, dwBytes(1), dwResult) Then
                If myFSUIPC.FSUIPC_Process(dwResult) Then
                    If dwBytes(1) = 0 Then
                        Me.Label9.Text = "OK"
                        SimulatorReady = True
                    Else
                        Me.Label9.Text = "NOK"
                        SimulatorReady = False
                    End If
                End If
            End If

The question thus really is not a matter of 'why is this not working', but rather one of 'what am I doing wrong'.

Guess someone that knows VB.NET would have to jump in here...

--

Chris.

Link to comment
Share on other sites

Yes, the value is always 29.

You are probably reading into a different place than you think, then.

Regardles of what plane, regardless of what state the simulator is in. The same is also happening with offset 3364 (Simulator ready) - which, never returns the 0 state.

I'm sure it will be -- check with FSUIPC IPC logging, or FSInterrogate. The problem will be that you are passing over something which is NOT pointing to where you want the information to be placed.

I'm sure I'm doing something wrong here... The problem is what :D

did you look up "varptr" (or whatever it is called -- look at the examples in the SDK). It really does look like you are passing over the contents of the places you want to read into, NOT the address (pointer) of (to) them.

1) ReDim, reinitialise and changes the size of the variable. In the case below, I changed the length of the array

Yes, but you changed a variable called "dwBytes" which wasn't a string. You declared an FSAircraft string but didn't use it. How would the MsgBox call print a Byte array?

3) The unused String was just me testing... I originally had:

If myFSUIPC.FSUIPC_Read(&H3D00, 256, FSAircraft, dwResult) Then

But that didn't work either. It also returned 29 :cry:

But I'm pretty sure that, at least in VB (I don't know if it changed in the .NET version), "FSAircraft" is not going to be a pointer to FSAircraft. You need to make itr into a pointer to where FSUIPC is to place the data! Didn't I say this before?

The question thus really is not a matter of 'why is this not working', but rather one of 'what am I doing wrong'.

Did you bother to look up "varptr" or "VarPtr" or whatever it is called? You seem to have ignored half of my suggestions.

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.