Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello everyone,

It may be stupid, but I can not get my appilication to work.

I will first explain it. What I do is I open a connection to FSUIPC, set the timer to 20 sec and run it.

Every 20 seconds I append the text in my Rich Text Area (called Log) and so I have Position Report.

Now when I land, I try to log my touchdown rate, but I just get the number 0!

My code:

Imports FSUIPC

Public Class Form1
    Function SRound(ByVal Real As Double) As Integer
        Dim tmp As Integer
        tmp = Val(Real)
        If Real - tmp >= 0.5 Then
            SRound = tmp + 1
        Else
            SRound = tmp
        End If
    End Function
    Function Report()
        If Conn.Text = "Connected" Then




            Dim lon As FsLongitude = New FsLongitude(playerLongitude.Value)
            Dim lat As FsLatitude = New FsLatitude(playerLatitude.Value)
            Dim airpeedKnots As Double = (airSpeed.Value / 128D)
            Dim altFeet As Double
            altFeet = playerAltitude.Value / (65536.0 * 65536.0) * 3.28084
            altFeet = SRound(altFeet)
            Log.AppendText(lat.ToString() & ", " & lon.ToString() & " @ " & altFeet & " feet, with " & airpeedKnots.ToString("f1") & "knots." & vbNewLine)



        End If
    End Function
    Function CheckGround()
        FSUIPCConnection.Process()
        Dim touch As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H30C)
        Dim airspeedKnots As Double = (airSpeed.Value / 128D)
        Dim speedKnots As String = airspeedKnots & " knots."
        Dim touchrate As Double = (touch.Value / 256.0) * 3.28084 * 60.0
        If touchrate = 0 Then
        Else
            Log.AppendText("Landed " & touchrate & vbNewLine)
        End If

        If onGround.Value = 1 Then
            If onGroundall = 1 Then
            Else
                If Airborneall = 1 Then
                    Log.AppendText("Landed " & vbNewLine)
                Else
                    Log.AppendText("On ground" & vbNewLine)
                End If
                onGroundall = 1
                Airborneall = 0
            End If
        Else
            If Airborneall = 1 Then
            Else

                Log.AppendText("In air!" & vbNewLine)
                Airborneall = 1
                onGroundall = 0
            End If
        End If
    End Function
    Private Const AppTitle As String = "FSUIPCClientExample_VB"

    ' Register the Offsets we're interesing in for this application
    Dim airSpeed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2BC) ' Basic integer read example
    Dim avionics As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2E80) ' Basic integer read and write example
    Dim fsLocalDateTime As Offset(Of Byte()) = New FSUIPC.Offset(Of Byte())(&H238, 10) ' Example of reading an arbitary set of bytes.
    Dim aircraftType As Offset(Of String) = New FSUIPC.Offset(Of String)("AircraftInfo", &H3160, 24) ' Example of string and use of a group
    Dim lights As Offset(Of BitArray) = New FSUIPC.Offset(Of BitArray)(&HD0C, 2) ' Example of BitArray used to manage a bit field type offset.
    Dim compass As Offset(Of Double) = New FSUIPC.Offset(Of Double)(&H2CC) ' Example for disconnecting/reconnecting
    Dim pause As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H262, True) ' Example of a write only offset.
    Dim com2bcd As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H3118) ' Example of reading a frequency coded in Biary Coded Decimal
    Dim playerLatitude As Offset(Of Long) = New Offset(Of Long)(&H560) ' Offset for Lat/Lon features
    Dim playerLongitude As Offset(Of Long) = New Offset(Of Long)(&H568) ' Offset for Lat/Lon features
    Dim onGround As Offset(Of Short) = New Offset(Of Short)(&H366) ' Offset for Lat/Lon features
    Dim magVar As Offset(Of Short) = New Offset(Of Short)(&H2A0) ' Offset for Lat/Lon features
    Dim playerHeadingTrue As Offset(Of UInteger) = New Offset(Of UInteger)(&H580) ' Offset for moving the plane
    Dim playerAltitude As Offset(Of Long) = New Offset(Of Long)(&H570) ' Offset for moving the plane
    Dim slewMode As Offset(Of Short) = New Offset(Of Short)(&H5DC, True) ' Offset for moving the plane
    Dim sendControl As Offset(Of Integer) = New Offset(Of Integer)(&H3110, True) ' Offset for moving the plane
    Dim onGroundall As Integer = 0
    Dim Airborneall As Integer = 0

    Const REFRESH_SCENERY As Integer = 65562 ' Control number to refresh the scenery

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

    End Sub

    Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click

        If Conn.Text = "Connected" Then
            FSUIPCConnection.Close()
            Connect.Text = "Connect"
            Me.Timer1.Enabled = False
        Else
            FSUIPCConnection.Open()
            Conn.Text = "Connected"
            Connect.Text = "Disconnect"
            Timer2.Enabled = True
            CheckGround()
            Me.Timer1.Interval = 20000
            Me.Timer1.Enabled = True
            Report()

        End If
    End Sub
    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Timer1.Enabled = False
        Timer2.Enabled = False
        FSUIPCConnection.Close()
    End Sub

    Public Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Report()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        CheckGround()
    End Sub
End Class

Please help me out!

Posted

It may be stupid, but I can not get my appilication to work.

I'm afraid I don't know VB, and especialy not VB.Net, so I hope someone else can jump in and help you. But i can perhaps offer a little advice to help debug FSUIPC interactions:

1. Use the Logging in FSUIPC to see what your application is actually doing from FSUIPC's point of view. If you avoid running any other FSUIPC applications (to avoid flooding the log with other accesses), then you can log the ipc reads and writes and see exactly what your program is reading and writing, and when! And with FSUIPC4 you can even display the log in real time on a console window if you run FSX in Windowed mode.

2. Double-check the values you are using via FSInterrogate, which can also display them in real time.

3. Use whatever debugger comes with "VB 2010 Express.Net" to trace through your program to see where it is going wrong.

One thing which to me looks logically wrong in your program is that this part:

    	If touchrate = 0 Then
        Else
            Log.AppendText("Landed " & touchrate & vbNewLine)
        End If

apart from appearing to have an empty statement for a zero touchrate (therefore how is it possible that it is logging 0 as you say?), also appears before you've even checked you have landed, here:

If onGround.Value = 1 Then

Shouldn't you only log the touchdown rate when you've touched down?

Regards

Pete

Posted

Hi,

    Function CheckGround()
        FSUIPCConnection.Process()
        Dim touch As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H30C)

There's your problem.

You call the process() method and then you create the offset to get the touchdown rate. So this new offset is never processed. It will always be 0.

You need to move the offset declaration down to where all the others are at the form level. Then it will be be created when the application loads and will be processed when CheckGround() is called.

The other bad thing about declaring the offset inside CheckGround() is that you're registering a new copy of this offset request with the DLL every time it's called. This will make your app run slower and slower over time and will eventually exceed the memory limits of the FSUIPC data file causing your app to crash.

Paul

Posted

Hi,

There's your problem.

You call the process() method and then you create the offset to get the touchdown rate. So this new offset is never processed. It will always be 0.

You need to move the offset declaration down to where all the others are at the form level. Then it will be be created when the application loads and will be processed when CheckGround() is called.

The other bad thing about declaring the offset inside CheckGround() is that you're registering a new copy of this offset request with the DLL every time it's called. This will make your app run slower and slower over time and will eventually exceed the memory limits of the FSUIPC data file causing your app to crash.

Paul

Thanks a lot! That has fixed it!! (now I finally understand when to call the offsets thanks :P)

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.