• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

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

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
 
Why are you converting the airspeed value to a string before comparing it to an integer? That shouldn't even compile.
 
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
 
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.
 
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.
 
Back
Top