1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is it possible to read FSUIPC value in a loop VB?

Discussion in 'Tools programming' started by pilotkostas, 17/12/09.

  1. pilotkostas

    pilotkostas

    Joined:
    24/5/09
    Messages:
    7
    Country:
    greece
    Hallo all,

    What im trying to do is read an FSUIPC offset inside a loop,the airspeed for example and i want to read it untill is bigger than a value (lets say 200) and then something.im using the following code but it does not work...


    Dim airSpeed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2BC)




    Do

    FSUIPCConnection.Process()
    Dim airpeedKnots As Double = airSpeed.Value / 128D


    If airpeedKnots.ToString() > 200 Then
    TextBox2.Text = "overspeed:"

    Exit Do

    Else
    'do nothing

    End If


    Loop


    Any ideas why this crashes?


    Kostas
  2. beatle

    beatle

    Joined:
    28/9/06
    Messages:
    324
    Country:
    us-virginia
    Why are you converting the airspeed value to a string before comparing it to an integer? That shouldn't even compile.
  3. pilotkostas

    pilotkostas

    Joined:
    24/5/09
    Messages:
    7
    Country:
    greece
    Corrected that ans it works,what i want to do is to read constantly an offset until it satisfies an condition what i do is create a loop and process the fsuipc connection is that the right way?Is there another way to do it?


    Kostas
  4. JordanMoore

    JordanMoore

    Joined:
    28/10/09
    Messages:
    18
    Country:
    us-newyork
    Greetings Kostas,

    You can use a timer, which would normally be less intensive than a tight loop. Provided you have your FSUIPC connection up and going then...

    Class Member:
    Private aircraft As New AircraftInfo (a class with all the aircraft related data you want to keep a running track of).


    Inside some mainLoop function():

    Private Function mainLoop()

    Dim dwResult As Integer
    Dim airspeed_t As Integer
    Dim intTokenAST As Integer
    FSUIPC_Read(&H2B8, 4, intTokenAST, dwResult)
    FSUIPC_Process(dwResult)
    FSUIPC_Get(intTokenAST, airspeed_t)


    aircraft.airspeed_t = Format(airspeed_t / 128, "0")

    End Function


    Setup a new Timer (with a frequency of 1sec for example):
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    mainLoop()
    End Sub


    Then anywhere else you have a reference to that same AircraftInfo object you can say...

    If aircraft.airspeed_t > 200 Then
    ...do something
    End If


    This psuedo example is based on true airspeed, and of course you would want some additional methods to control starting/stopping the timer, etc. In my code I actually populate the AircraftInfo inside the mainLoop and then pass the AircraftInfo reference out to other Functions that do various checks against various rules, which spawn various behaviors.

    I hope this was helpful.
  5. JordanMoore

    JordanMoore

    Joined:
    28/10/09
    Messages:
    18
    Country:
    us-newyork
    I just realized you might be using the newer FSUIPC VB api - so my actual FSUIPC calls might be a bit different, but the concept of using the timer instead of a performance-wrecking tight loop is the important part.

Share This Page