PDA

View Full Version : Is it possible to read FSUIPC value in a loop VB?


pilotkostas
17 Dec 2009, 08:48
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

beatle
17 Dec 2009, 10:35
Why are you converting the airspeed value to a string before comparing it to an integer? That shouldn't even compile.

pilotkostas
18 Dec 2009, 21:51
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

JordanMoore
18 Dec 2009, 23:30
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.

JordanMoore
18 Dec 2009, 23:32
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.