Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I created application that has two command button and a label.... One command button is to increase value and other command button is to decrease value. Using FSUIPC write...so here's code snippet.

Private Sub Increase_Click()
Lfuelval 1
End Sub

Private Sub Decrease_Click()
Lfuelval -1
End Sub

Private Sub Lfuelval(ByVal argNum As Long)
Dim dwresult As Long
Dim setLfuelPct As Long
Dim Value

Call FSUIPC_Write(&HB7C, 4, VarPtr(setLfuel), dwresult)
Call FSUIPC_Process(dwresult)

setLfuelPct = Val(100) + argNum / 8372890 * (128 * 63556)
LFuelPct.Caption = Val(LFuelPct.Caption) + argNum
End Sub

It did not work, what did I do wrong?? if you can help I'd be appreicated.[/b]

Posted

Private Sub Increase_Click()
Lfuelval 1
End Sub

Private Sub Decrease_Click()
Lfuelval -1
End Sub

Private Sub Lfuelval(ByVal argNum As Long)
Dim dwresult As Long
Dim setLfuelPct As Long
Dim Value

Call FSUIPC_Write(&HB7C, 4, VarPtr(setLfuel), dwresult)
Call FSUIPC_Process(dwresult)

setLfuelPct = Val(100) + argNum / 8372890 * (128 * 63556)
LFuelPct.Caption = Val(LFuelPct.Caption) + argNum
End Sub

I evidently don't understand VB at all. What is actually setting or changing value in the variable you are writing to 0B7C? What is "8372890"? Where are you reading and using the tank capacity, or are you assuming it is fixed (i.e. doing this for a specific aircraft)?

You seem to be updating something AFTER writing something else. It always worries me when I see arithmetic like

Val(100) + argNum / 8372890 * (128 * 63556)

What is done in what order? Do you know? I always use parentheses to force the order I know I want. In particular, if "argNum" is the +1 or -1 passed as a parameter, then dividing it by 8372890 will surely give zero!? After all, it is declared as a "long" so it isn't capable of storing fractional values is it?

Pete

Posted

I evidently don't understand VB at all. What is actually setting or changing

value in the variable you are writing to 0B7C? What is "8372890"? Where are you reading and using the tank capacity, or are you assuming it is fixed (i.e. doing this for a specific aircraft)?

You seem to be updating something AFTER writing something else. It always worries me when I see arithmetic like

Val(100) + argNum / 8372890 * (128 * 63556)

What is done in what order? Do you know? I always use parentheses to force the order I know I want. In particular, if "argNum" is the +1 or -1 passed as a parameter, then dividing it by 8372890 will surely give zero!? After all, it is declared as a "long" so it isn't capable of storing fractional values is it?

Perhaps, I got really confused. Seem like I got myself in mess.. I have suceed getting my application to Read Fuel Capacity, Lbs, and Percentage. But Unable to clarify the logic in writing them. Actually it's my first time doing this

Say, if you were me... You use C ?? (I assume thats the programming language you are familar with) and you wanted to increase or decrease fuel % for center tank. How would you implement it? with calculation of Fuel Level and Capacity?

Let me know

Arthur

Posted

Say, if you were me... You use C ?? (I assume thats the programming language you are familar with) and you wanted to increase or decrease fuel % for center tank. How would you implement it? with calculation of Fuel Level and Capacity?

Well, I've not done this in a program, but you could easily check for yourself using FSInterrogate (you can WRITE to FSUIPC in FSInterrogate as well as read and observe, you know).

Anyway, for just a simple percentage increase/decrease you don't need the actual capacities -- you'd only ever need capacities if you wanted a fixed number of gallons or litres or pounds of kilograms of change. You just need the fact that 100% level is known to be 128 * 65536, or 8388608.

In "pseudo-code" (i.e. no known language):

Read the levels for all tanks (in one Process call)

For each tank, assuming its level readout is now in 32-bit integer 'L'

For 1% increase:

  • L = L + 83886 (which is (128 * 65536) / 100, thus 1%)
    Check L <= 8388608 (this is 128 * 65536, representing 100%)
    -- if not set L = 8388608 (100%)

For 1% decrease:

  • L = L - 83886 (which is (128 * 65536) / 100, thus 1%)
    Check L >= 0
    -- if not set L = 0 (0%)

Write L back to level offset for this tank

Loop for next tank

Do the Process call for all the tanks written

Pete

Posted
L = L + 83886 (which is (128 * 65536) / 100, thus 1%)

Check L <= 8388608 (this is 128 * 65536, representing 100%)

-- if not set L = 8388608 (100%)

For 1% decrease:

L = L - 83886 (which is (128 * 65536) / 100, thus 1%)

Check L >= 0

-- if not set L = 0 (0%)

Write L back to level offset for this tank

Loop for next tank

Do the Process call for all the tanks written

Interesting Theory Pete, I got this working now.... I created two VB button, one for increasing and other one for decreasing fuel, At that time, I simply click it at both ways and they either dump or increases fuel by 10 pounds on every button clicks.

Now I am working on VB "doevent" function (loop) and see if I could get it to lose few pound automatically following by clock ticks as if I engages fuel jettison. Your theory really helps.

Thanks

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.