Jump to content
The simFlight Network Forums

Recommended Posts

Posted
A random question but is it possible to tell which airfield an aircraft is at in the fs db via fsuipc as opposed to the lat and lon position?

As Pete already said, the answer is "no" but ...

Recipe:

- text file with "central spot" coordinates for all airports in the world, one airport per line, like this:

LPPT;LISBOA;38.781311;-9.135919;374

EGLL;HEATHROW;51.4775;-0.461389;83

LFPG;CHARLES DE GAULLE;49.012778;2.55;392

(...)

Note: I believe there is a way to generate it from FS itself...

- The following bit of (ugly) VB code

- A lot of patience to tweak it to your needs ...

Sub mylocation(ByVal curlat As Double, ByVal curlon As Double)
        Dim path As String = airportdata 'Full path including filename to the airport coordinates file, like C:\myairport.txt
        Dim latdif As Double = 10000
        Dim londif As Double = 10000

        ' Open the stream and read it back.
        Dim sr As StreamReader = File.OpenText(path)

        Do While sr.Peek()
            Dim somatemp As Double = 0
            Dim Alat As Double
            Dim Blon As Double

            Dim temp As String = sr.ReadLine()
            Dim TestArray() As String = Split(temp, ";")
            If TestArray(0) = "" Then Exit Do
            Alat = Val(TestArray(2))
            Blon = Val(TestArray(3))
            If (Math.Abs(Alat - curlat) < latdif) And (Math.Abs(Blon - curlon) < londif) Then
                latdif = Math.Abs(Alat - curlat)
                londif = Math.Abs(Blon - curlon)
                arpt = TestArray(0)
            End If

        Loop
        sr.Close()

    End Sub

When calling mylocation(curFSlat,curFSlon), it *should* set the "arpt" variable to the current airport ICAO.

Be advised that if you're just *near* the airport (and not *at* the airport) it will still set the "arpt" to the nearest airport ICAO ...

Of course you can tweak this: after finding the nearest airport, you can check if the altitude AGL is the same (give or take some feet) as the TestArray(4) - airport elevation- and/or check if the distance from the current location to the airport known location is less or equal than "X" nautical miles ...

Yeah, it *still* can fail, but heybetter than nothing :)

P.S. - If you tweak the code, share it ;-)

Regards,

  • 1 month later...
Posted

Can somebody please give an example of how I can get like the aircraft speed or altitude from the FS into visual basic? Then show it on the application I know how to make the variable a little bit here is an example.

 Dim FlightSimVersion As New FSUIPC.Offset(Of Integer)(&H3308)
    Dim AircraftName As New FSUIPC.Offset(Of String)(&H3D00, 256)
    Dim AirSpeed As New FSUIPC.Offset(Of Integer)("1", &H2BC)
    Dim OnGround As New FSUIPC.Offset(Of Short)("1", &H366)
    Dim PreLongitude As New FSUIPC.Offset(Of Long)(&H560)
    Dim PreLatitude As New FSUIPC.Offset(Of Long)(&H568)
    Dim Altitude As New FSUIPC.Offset(Of Long)(&H570)
    Dim GroundSpeed As New FSUIPC.Offset(Of Integer)(&H2B4)

Now what i have to do?

Posted
Can somebody please give an example of how I can get like the aircraft speed or altitude from the FS into visual basic?

Hi Topdog,

There is an example VB.NET application supplied with my DLL. It displays various types of data on a form.

In summary though, you need to call the FSUIPCConnection.Process() method to read the data from FS. Then you read the values from the .Value property on the offsets. e.g.

Me.txtMyTextBox.Text = AirSpeed.Value.ToString()

Please have a look at the sample application as it explains everything in detail and also shows you how to setup a timer loop to keep everything updating on a regular basis. If you still need help, feel free to post more questions.

Paul

Posted

Now I know how to get the information and the basic stuff. I was also wondering 2 things. How come when I got the heading info it came out to a big number with the actual heading to the left of the decimal. For example, in Flight Sim I set my heading to 050 in VB.NET it shows 50.0217981453628 how can I just have it just show 050. Also how can I have the numbers update automatically for it to change, for some reason I always have to close the program I am building and restart it. I want it to update automatically how can I do that?

This is the heading dim part

   Dim Heading As New FSUIPC.Offset(Of Double)("indh", &H2CC)

I got the airspeed to update automatically how can I do the heading an altitude?

Posted
How come when I got the heading info it came out to a big number with the actual heading to the left of the decimal.

Because FSUIPC gives you a precise value for the heading, that is, values in-between each degree.

how can I just have it just show 050

This is nothing to do with FSUIPC or the DLL, you just use normal programming techniques to format the number to how you want it. In the case of VB.NET you can use one of the overloads of the ToString() method on the Double class:

Me.myTextBox.Text = Heading.Value.ToString("000")

Also how can I have the numbers update automatically for it to change

You need to call Process() again and then get the new values from the offsets and display them on the form again. To do this at regular intervals you need to add a timer to the form and put the update code in the Tick() event. This is clearly demonstrated in the sample application.

Paul

Posted

How can I keep looping that just put that in the timmer function thing

ex:

  Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try

            ' Process the default group 
            FSUIPCConnection.Process()


            ' IAS - Simple integer returned so just divide as per the 
            ' FSUIPC documentation for this offset and display the result.
            Dim airpeedKnots As Double = (airSpeed.Value / 128D)
            Label20.Text = airpeedKnots.ToString("f1")
            Me.Label19.Text = Heading.Value.ToString("000")


        Catch exFSUIPC As FSUIPCException
            If exFSUIPC.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_SENDMSG Then
                Me.Timer1.Enabled = False
                FSUIPCConnection.Close()
                MessageBox.Show("The connection to Flight Sim has been lost.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                ' not the disonnect error so some other baddness occured.
                ' just rethrow to halt the application
                Throw exFSUIPC
            End If

        Catch ex As Exception
            ' Sometime when the connection is lost, bad data gets returned 
            ' and causes problems with some of the other lines.  
            ' This catch block just makes sure the user doesn't see any
            ' other Exceptions apart from FSUIPCExceptions.
        End Try



    End Sub
End Class

Is that the correct way?

Also please forgive me I am new to the vb.net thank you.

Also the following code above is giving me 000 when my current heading 197

This is how I get the heading info

    Dim Heading As New FSUIPC.Offset(Of Double)("indh", &H2CC)

  Label19.Text = Heading.Value.ToString("000")

Posted

Hi Topdog,

How can I keep looping that just put that in the timer function thing

The timer loops for you. It keeps calling the Tick() event at the interval that you set. Make sure that you set Timer1.Enabled = True to turn it on and set Timer1.Interval to the number of milliseconds you want between ticks. e.g to update 10 times per second:

Timer1.Interval = 100
Timer1.Enabled = True

Also the following code above is giving me 000 when my current heading 197

From looking at your code I can see that the heading is not being updated from FSUIPC. You have defined it to be in a 'group' called "indh", but then you never process that group, only the default group. Somewhere in you code you need:

FSUIPCConnection.Process("indh")

The grouping feature is explained in the UserGuide.htm. Please read this if you haven't already.

Paul

Posted

So can I get an example please of the timer thing, because I am still lost. Also look at this please.

Dim Heading As New FSUIPC.Offset(Of Double)("indh", &H2CC)

I have already group it.

Posted
So can I get an example please of the timer thing

You already have an example of the timer. The example VB.NET application I supplied with the DLL has a timer in it. Everything you need is there.

Your problem maybe that you've not added the timer component to the form. You need to drag it from the toolbox (where you get buttons and textboxes from) onto your form. Then add the Tick() event code by double clicking it.

    Dim Heading As New FSUIPC.Offset(Of Double)("indh", &H2CC)

I have already group it.

I know. That's the problem. You have grouped it, but you're never processing that group.

As I said in the last message, you need to process the group:

FSUIPCConnection.Process("indh")

Did you add that line?

The best thing for you to do at the moment is remove all the grouping:

Just declare the heading like this:

Dim Heading As New FSUIPC.Offset(Of Double)(&H2CC)

That should give you a value for the heading.

If you're really stuck on getting the timer to work then send me the form code (cut and paste) via private message on the forum. It's difficult to help without the code. I'll make the timer work and send it back to you with comments showing what I did.

Paul

Posted

Ok I got the heading thing to work but now I am lost, I can get the altitude but it comes out to this big number why is that

 Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H570)
   Label29.Text = altitude.Value.ToString("00,000")

Also how can I get it so that it will display the right format?

Posted
Ok I got the heading thing to work but now I am lost, I can get the altitude but it comes out to this big number why is that?

Are you referring to the documentation at all? The list of offsets and what they contain? You will see that the 32-bit integer at 0570 is the fractional part of the altitude, not the main integral part. If all you want is the altitude in metres, you will see it clearly stated that this is in the next 32-bit integer, at offset 0574.

If you want more accuracy you could add the fractional part after copying it to a floating point variable and dividing it by 65536 twice. Otherwise you'd need to read all 8 bytes as a 64-bit integer, copy it to a floating point variable, and divide by 65536 twice. This latter method would cope with negative altitudes correctly too.

Please do read the information actually published about this. It will help and save you and others a lot of time!

Pete

Posted
Sorry, I am still new to VB. Also I see it where it says 32 bit but I don't know how will I code that in the program I am working on?

It doesn't only say 32-bit, it also says offset 0570 for the fraction and offset 0574 for the integral part. THAT's the part which should have caught your attention! Why not read all the words?

Bits are what make computers work. They are the basis of computer memory, the individual switches with are either on (1) or off (0). The numbers such switches make up are in what is called BINARY, "BI" for "2" because there's only two digits, 0 and 1. (In DECIMAL, "DEC" for 10, there are 10 digits, 0 to 9).

There are 8 bits in a BYTE. Since the integers you are reading are 4 bytes that's 4 x 8 = 32. It is only simple arithmetic! I don't know VB at all, but I think its integers are 32-bit.

Pete

Posted
Sorry, I am still new to VB. Also I see it where it says 32 bit but I don't know how will I code that in the program I am working on?

As Pete explained, 32 bits is the same as 4 bytes which is an Integer in VB.NET. So declare the offset as:

Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H574)

Paul

Posted
Sorry, I am still new to VB. Also I see it where it says 32 bit but I don't know how will I code that in the program I am working on?

As Pete explained, 32 bits is the same as 4 bytes which is an Integer in VB.NET. So declare the offset as:

Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H574)

Paul

I am confused that is how I did it and it still comes out to a big number.

Posted

I am confused that is how I did it and it still comes out to a big number.

Can you paste your code in here (especially the offset declaration and the bit where you use the altitude).

Also please tell me what altitude your plane is at in the sim and what the 'big number' is that you're getting.

Thanks,

Paul

Posted

Here it is:

  Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H570)

  Label29.Text = altitude.Value.ToString("00,000")

That is all I have for the altitude portion.

Posted

  Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H570)

Pete and I have tried to explain that 570 is the FRACTIONAL part of the altitude - i.e. AFTER the decimal place.

I've told you to how to fix this:

 Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H574)

And you've not changed your code. Your code still says 570. All you need to do is change your offset from 570 to 574.

Also note that the number you will get is in Metres. If you want Feet you'll need to convert it - (Multiply by 3.2808399).

If Pete and I are going to help you please read what we're saying to you and make the changes we suggest. Otherwise we're all wasting our time.

Paul

  • 1 month later...
Posted

Hi phenty,

I've been using your DLL to program via C#.NET and have found it a great way to communicate with FSX - very straightforward and easy to use. So far, it has been able to do everything I have needed except for my most recent endeavour. I am trying to extract AI Traffic information via the TCAS_DATA found in Pete's SDK. I have tried using a and offset types with no success. Could you please explain or offer a quick C# code example that shows how to retrieve this data. Thanks in advance,

Cory

AZPilot

Posted

Hi Corry,

You were on the right track with the Byte[]. In a nutshell you need:

Read the housekeeping headers to find the number of slots in use and which have changed.

For each slot that's changed, work out the offset of the slot in the two large AI data tables.

Read the slot data into a byte array.

Decode the raw bytes in the byte array into usable .NET variable types.

The last stage requires decoding the relevant bytes in the Byte array using the BitConverter class and some ASCII string decoder classes for the string types.

It's all pretty complicated to be honest. However...

I have an unreleased 1.4 version of the DLL that lets you get access to all the AI in a really easy .NET way. The AI traffic is presented as a collection of AIPlaneInfo classes. You can just access each plane as a class and get its properties. There are also properties that aren't provided by FSUIPC like distance and bearing from the player. You can also filter the traffic tables to ignore planes over a certain distance or altitude etc.

The reason it's unreleased is I've not done the documentation yet and no one has tested it (except me). I'll be happy to PM you the 1.4 version with some example code if you want to try it and let me know how it goes.

If you prefer to do it yourself I can help you some more, but be warned that the AI code in the DLL runs to nearly 500 lines. ;-) Let me know what you want to do.

BTW, if there is anyone else reading this who wants to try the new AI traffic features, just send me a PM.

Paul

  • 3 weeks later...
  • 4 months later...
Posted

Hi all,

well I'm gradually working my way through it! I have been posting in various threads, but I think I've found the right one - with Pete's guidance - thanks Pete!

To recap:

I am trying to write a program in Visual Basic 2008 Express, which will run through a verbal checklist for the Boeing 737 800. It does so by automatically calling each challenge (by playing a '.wav' file) then either giving the correct response, or waiting 5s and recalling the challenge if the item is not in the required state.

I've got it working to my satisfaction purely within VB8, by representing the 'required state' as a checkbox.

If I check the box (either before, or immeiately after, the challenge) the response is given appropriately. If I leave the box uncehcked, the program will wait and then re-issue the challenge.

I can run down the list of checkboxes and check them at random - the program will still run past all the checked ones and wait at the unchecked box. Great!

Now all I have to do is get rid of the checkboxes and replace them with actual FSUIPC offsets.

here's what I've done:

1) Opened up the FSUIPC_shell.sln from the UIPC_SDK VB .Net Shell Revision 2.004.zip in the FSUIPC SDK

2) Added the 'Imports FSUIPC' line to the start of the prog

3) modified the first few lines like this:

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dwResult As Integer

        FSUIPC_Initialization()
        If (Not FSUIPC_Open(SIM_ANY, dwResult)) Then
            MsgBox("FSUIPC not found, application will close")
            End
        Else : MsgBox("fsuipc found")
            My.Forms.Form2.Show()
            My.Forms.Form2.BringToFront()

        End If

So far so good - if FS is running, I get the "FSUIPC found" message, if not, I get the "not found" message. It also opens Form2 and brings to to the front.

The I added the following code out of the example:

  Try
            ' Attempt to open a connection to FSUIPC (running on any version of Flight Sim)

            FSUIPCConnection.Open()

            ' Opened OK 

        Catch ex As Exception

            ' Badness occurred - show the error message

            MsgBox(ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

This is where I'm not having such success!

I'm getting the "FSUIPC Error #7: FSUIPC_ERR_VERSION. Incorrect version of FSUIPC." message mentioned elsewhere in this thread.

I downloaded and registered the newest version of FSUIPC and had another go.

I've followed Peter's instructions:

The .dll signature is OK

I've renamed the FSUIPC.key file to FSUIC.key.old so it gets missed

But I'm still getting the message when I try to open the connection.

Any ideas? I realise I may have missed something totally obvious, being akin to a cretin when it comes to programming!

Thanks,

Roger.

Posted
I'm getting the "FSUIPC Error #7: FSUIPC_ERR_VERSION. Incorrect version of FSUIPC." message mentioned elsewhere in this thread.

Do you get this with published FSUIPC client programs, like FSInterrogate, or my own TrafficLook or WeatherSet programs?

I downloaded and registered the newest version of FSUIPC and had another go.

I've followed Peter's instructions:

The .dll signature is OK

I've renamed the FSUIPC.key file to FSUIC.key.old so it gets missed

Why, did you suspect you had a pirate signature?

Use FSUIPC logging -- ipc read and write options, and see what you are reading.

Regards

Pete

Posted

Hi Peter,

FS Interrogate and Traffic look seem to be working fine. I flipped the battery switch and it changed from 0 to 1 on re-scanning in FSI. Traffic look appears to be pickin gup at least one other aircraft.

Here's a sample of the log (yes, it gets big very quickly doesn't it!)

9957825 WRITE0 0DDC, 2 bytes: 22 00

9957825 READ0 7B81, 1 bytes: 00

9957856 READ0 3210, 4 bytes: FF B4 00 00

9958059 READ0 3210, 4 bytes: FF B4 00 00

9958137 READ0 7BE9, 1 bytes: 00

9958261 READ0 3210, 4 bytes: FF B4 00 00

9958464 READ0 3210, 4 bytes: FF B4 00 00

9958636 READ0 7BE9, 1 bytes: 00

9958667 READ0 3210, 4 bytes: FF B4 00 00

9958870 READ0 3210, 4 bytes: FF B4 00 00

9959073 READ0 3210, 4 bytes: FF B4 00 00

9959135 READ0 7BE9, 1 bytes: 00

9959275 READ0 3210, 4 bytes: FF B4 00 00

9959478 READ0 3210, 4 bytes: FF B4 00 00

9959634 READ0 7BE9, 1 bytes: 00

9959681 READ0 3210, 4 bytes: FF B4 00 00

9959837 READ0 0BC8, 2 bytes: FF 7F

9959837 WRITE0 0DDE, 2 bytes: 01 00

9959837 READ0 3D00, 256 bytes: 42 6F 65 69 6E 67 20 37 33 37 2D 38 30 30 20 41

9959837 69 72 20 53 63 68 65 66 66 65 6C 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

9959837 WRITE0 0DDC, 2 bytes: 22 00

9959837 READ0 7B81, 1 bytes: 00

9959884 READ0 3210, 4 bytes: FF B4 00 00

9960087 READ0 3210, 4 bytes: FF B4 00 00

9960133 READ0 7BE9, 1 bytes: 00

9960289 READ0 3210, 4 bytes: FF B4 00 00

9960492 READ0 3210, 4 bytes: FF B4 00 00

9960492 WRITE0 3210, 2 bytes: FF FF

9960633 READ0 7BE9, 1 bytes: 00

9960695 READ0 3210, 4 bytes: FF FF 00 00

9960898 READ0 3210, 4 bytes: FF FF 00 00

9961101 READ0 3210, 4 bytes: FF FF 00 00

Thanks,

Roger.

Guest
This topic is now closed to further replies.
×
×
  • 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.