High-Octane Posted August 3, 2005 Report Posted August 3, 2005 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]
rickalty Posted August 3, 2005 Report Posted August 3, 2005 First thing that jumps out at me is that you Dim "setLfuelPct", but then in the FSUIPC_Write, you use "setLfuel", which isn't declared anywhere. Richard
High-Octane Posted August 3, 2005 Author Report Posted August 3, 2005 Apparently, I must mistype it, I type the whole thing in this previous post instead copying it out of VB appl... So, 'setLFuelPct' correct ....
Pete Dowson Posted August 3, 2005 Report Posted August 3, 2005 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
High-Octane Posted August 4, 2005 Author Report Posted August 4, 2005 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
Pete Dowson Posted August 4, 2005 Report Posted August 4, 2005 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
High-Octane Posted August 5, 2005 Author Report Posted August 5, 2005 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now