Jump to content
The simFlight Network Forums

Programming Efficiency (VB.NET)


Recommended Posts

Hi Pete,

In mean time we've managed to get most things working. However we have a few questions. We are experiencing delays of +- 3 sec on the commands given, probabely due to unefficient programming.

Do you have any FSUIPC related tips concerning a more efficient programming? (Note that there is also code included for the acquisition of voltages).

Second question: We are getting the voltage values in double format, this means a lot of numbers behind the floating point, however, flightsim requires a Short as input, this means we are loosing all numbers behind the floating point. Currently we devide the voltage input by the max voltage input (so this means max = 1) and * 16348. Is there a more interesting way to cope with this problem?

------------------------

Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick

'Engine 1 Throttle Lever

Dim reader1 As AnalogMultiChannelReader

Dim myTask1 As New Task

myTask1.AIChannels.CreateVoltageChannel("dev1/ai0", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts)

myTask1.Control(TaskAction.Verify)

reader1 = New AnalogMultiChannelReader(myTask1.Stream)

Dim datainput1 As Double(,)

datainput1 = reader1.ReadMultiSample(-1)

Dim voltage1 As Double = datainput1(0, 0)

lblVoltageENG1.Text = voltage1

Dim dwOffset1 As Integer

Dim Wel1 As Short = ((voltage1 / 8.73) * 16384)

Dim ThrottleToken1 As Integer

Dim Result1 As Integer

dwOffset1 = &H88C

FSUIPC_Write(dwOffset1, Wel1, ThrottleToken1, Result1)

myTask1.Dispose()

'Engine 2 Throttle Lever

Dim reader2 As AnalogMultiChannelReader

Dim myTask2 As New Task

myTask2.AIChannels.CreateVoltageChannel("dev1/ai1", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts)

myTask2.Control(TaskAction.Verify)

reader2 = New AnalogMultiChannelReader(myTask2.Stream)

Dim datainput2 As Double(,)

datainput2 = reader2.ReadMultiSample(-1)

Dim voltage2 As Double = datainput2(0, 0)

lblVoltageENG2.Text = voltage2

Dim dwOffset2 As Integer

Dim Wel2 As Short = ((voltage2 / 8.73) * 16384)

Dim ThrottleToken2 As Integer

Dim Result2 As Integer

dwOffset2 = &H924

FSUIPC_Write(dwOffset2, Wel2, ThrottleToken2, Result2)

myTask2.Dispose()

'Engine 3 Throttle Lever

Dim reader3 As AnalogMultiChannelReader

Dim myTask3 As New Task

myTask3.AIChannels.CreateVoltageChannel("dev1/ai2", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts)

myTask3.Control(TaskAction.Verify)

reader3 = New AnalogMultiChannelReader(myTask3.Stream)

Dim datainput3 As Double(,)

datainput3 = reader3.ReadMultiSample(-1)

Dim voltage3 As Double = datainput3(0, 0)

lblVoltageENG3.Text = voltage3

Dim dwOffset3 As Integer

Dim Wel3 As Short = ((voltage3 / 8.73) * 16384)

Dim ThrottleToken3 As Integer

Dim Result3 As Integer

dwOffset3 = &H9BC

FSUIPC_Write(dwOffset3, Wel3, ThrottleToken3, Result3

myTask3.Dispose()

'Elevator Position Control

Dim reader4 As AnalogMultiChannelReader

Dim myTask4 As New Task

myTask4.AIChannels.CreateVoltageChannel("dev1/ai3", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts)

myTask4.Control(TaskAction.Verify)

reader4 = New AnalogMultiChannelReader(myTask4.Stream)

Dim datainput4 As Double(,)

datainput4 = reader4.ReadMultiSample(-1)

Dim voltage4 As Double = datainput4(0, 0)

lblVoltageElevator.Text = voltage4

Dim dwOffset4 As Integer

Dim Wel4 As Short = (((voltage4 - (9 / 2)) / (9 / 2)) * 16384)

Dim ThrottleToken4 As Integer

Dim Result4 As Integer

dwOffset4 = &HBB2

FSUIPC_Write(dwOffset4, Wel4, ThrottleToken4, Result4)

myTask4.Dispose()

FSUIPC_Process(Result1)

FSUIPC_Process(Result2)

FSUIPC_Process(Result3)

FSUIPC_Process(Result4)

End Sub

FSUIPC_Close() is called in form_closed

------------------------

All comments on the programming are more than welcome to impove the loading time.

Link to comment
Share on other sites

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.