Jump to content
The simFlight Network Forums

Fuel


Recommended Posts

I am trying to now calculate fuel from the aircraft. I would like it to add the fuel from start to finish from both engines. I have scene it in the sdk but I dont know how to use the offsets properly. Any help would be greatly aperciated.

Sorry, I don't understand what you want to do. Are you writing a program which interfaces to FSUIPC? Are you wanting to read fuel levels, or change them? What programming language are you using?

Regards

Pete

Link to comment
Share on other sites

I am coding it in VB 8 and yes I am trying to read te fuel.

The fuel tank capacities are provided by one offset location for each tank, and the level of the fuel in each is provided in another offset location for each. The offsets are listed quite clearly in the documentation -- check offsets 0B74 to 0BA8 for the more commonly used tanks and 1244 to 1260 for the extras some aircraft have (2nd and 3rd centre tanks, and 1 or 2 external tanks).

Is there something you don't understand about these?

Regards

Pete

Link to comment
Share on other sites

I really dont understand the offsets to be honest, such as BXXX but and in VB it is HXXX. So if you could help me out that would be great!

I don't know VB at all, except, yes, a hexadecimal number which is expressed in C/C++ as, for example, 0x0B74 would be something like &H0B74 in VB. Do you have any books on VB so you can find out a bit more about programming first?

If you want help here I think you really need to ask specific questions. Saying you "don't understand offsets" is a bit meaningless. What is it about "offsets" you don't understand? The fact that you put the offset value, in hex (or decimal) into function calls, to tell FSUIPC what you want? Just think of them as identifiers of data if you don't understand computer memory addressing (which is what they really are -- offsets from a known base into a 65kb area of memory).

I am pretty sure there are examples in VB in the FSUIPC SDK. Have you looked? There's also a lot of help and a tool you can use -- see the sticky thread called FSUIPC Client DLL for .NET near the beginning of this Forum.

Regards

Pete

Link to comment
Share on other sites

Ok this is my code:

Dim Fuel As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H90C)
Dim fuelleft As Double = (Fuel.Value)
Label26.Text = fuelleft.ToString("f1")

The H90C is the offset 090C in the SDK manual, it recieves fuel from the left engine and how much is used from the start of the flight. I havnt got it to work but I hope this code will help you guys understand a little bit more as to what I am looking to do.

Thank You

P.S- I know VB very well just I have been trying to get fuel total for a long time and I couldnt get it so I seeked help. Thank you again.

Link to comment
Share on other sites

Dim Fuel As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H90C)
Dim fuelleft As Double = (Fuel.Value)
Label26.Text = fuelleft.ToString("f1")

Right. This is obviously only for FSX and ESP, as 090C is new to FSUIPC4. It isn't available for FS9.

As I say, I don't know VB. But That "Of Integer" looks odd to me. Is it saying the value you will tread is an integer? Because it isn't.

The 2nd line implies the fuel is a double -- i.e. a 64-bit floating point number. Which it isn't.

As the offsets list shows, this value is a 32-bit floating point number, a "float" in C/C++ terms. I don't know what type that is in VB -- "single" perhaps?

Which part of that code actually connects to FSUIPC and reads the value? Apart from the conversion to a string it seems to be only declarations. Don't you have to call some function to do that? In C there's first of all an FSUIPC_Open, to make the connection, then any number of FSUIPC_Read and FSUIPC_Write function calls, and an FSUIPC_Process to action them. An FSUIPC_Close is used to sever the connection before terminating.

I suspect you are going to need help from someone who knows VB.

Regards

Pete

Link to comment
Share on other sites

Hi,

I looks like you're using my .NET Client DLL. In the ZIP there are some comprehensive documents that explain how to use the offsets. This includes a very helpful table showing you what VB type to use depending on the length and type of the Offset.

Also the sample VB program shows exactly how to use read and write offsets.

Please do read the documentation and help that I've already provided.

H90C is the offset 090C

That's not quite correct. The hex number is in VB is 90C not H90C. The H bit is not part of the number - it just tells VB that the number following is in Hex and not decimal.

When you see a C hex number like 0x090C then in VB you just take off the 0x and add &H. So 0x090C becomes &H090C. VB may remove the leading 0 because it's redundent giving &H90C.

As Pete said offset 0x090C is a 4 Byte (32-Bit) floating point offset. My documentation clearly states that this should be declared as 'Single' in VB.NET.

Also you need a Process() call to actually read the data. This is also explained in documentation and the sample code.

So your code should look something more like this.

Dim Fuel As Offset(Of Single) = New FSUIPC.Offset(Of Single)(&H90C)

Public Sub MySub()
    FSUIPCConnection.Process()
    Dim fuelleft As Single = (Fuel.Value)
    Label26.Text = fuelleft.ToString("f1")
End Sub

Paul

Link to comment
Share on other sites

I do thank you all for your help and patients but that sadly did not work below is the code to my whole program.

Imports FSUIPC
Public Class Form1
    Private Const AppTitle As String = "PiREP  Reporting System"
    Const Message As String = "Error 1222"
    Dim airSpeed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2BC)
    Dim touch As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H30C)
    Dim down As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H366)
    Private altitude As Offset(Of Long) = New FSUIPC.Offset(Of Long)(&H570)
    Dim Fuel As Offset(Of Single) = New FSUIPC.Offset(Of Single)(&H90C)



    Private Sub OpenFSUIPC()
        Try
            FSUIPCConnection.Open()
            Me.Timer1.Interval = 200
            Me.Timer1.Enabled = True
        Catch ex As Exception
            MessageBox.Show(Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Enabled = False
        Button2.Enabled = False
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        CheckBox1.Enabled = False
        ComboBox1.Enabled = False
        Label25.Enabled = False
        Label27.Enabled = False
        Timer2.Enabled = False
        TextBox3.CharacterCasing = CharacterCasing.Upper
        TextBox2.CharacterCasing = CharacterCasing.Upper
        OpenFSUIPC()

    End Sub
    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        FSUIPCConnection.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Starttime As String = TimeOfDay
        Timer2.Enabled = True
        Label13.Text = Starttime
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        ComboBox1.Enabled = False
        Button1.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FSUIPCConnection.Close()
    End Sub

    Private Sub InformationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InformationToolStripMenuItem.Click
        MsgBox("Version 1.0 Created By Nicholas Cooper")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Try
            FSUIPCConnection.Process()
            Dim deptime As String = TimeOfDay
            Dim airpeedKnots As Double = (airSpeed.Value / 128D)
            Me.Label15.Text = airpeedKnots.ToString("f1")
            Dim touchrate As Double = (touch.Value / 256.0) * 3.28084 * 60.0
            Dim altFeet As Double
            altFeet = altitude.Value / (65536.0 * 65536.0) * 3.28084
            altFeet = Math.Round(altFeet, 0)
            Label18.Text = altFeet

            Dim fuelleft As Single = (Fuel.Value)
            Label26.Text = fuelleft.ToString("f1")

            If airpeedKnots >= "60" Then
                Label16.Text = "In-Flight"
            Else
                Label16.Text = "On-Ground"
            End If
            If airpeedKnots <= "10" And Label23.Text = "3" Then
                Label27.Enabled = True
                Label25.Enabled = True
                Label27.Text = touchrate.ToString("f1")
            End If

        Catch exFSUIPC As FSUIPCException
            If exFSUIPC.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_SENDMSG Then
                FSUIPCConnection.Close()
                MessageBox.Show("The connection to Flight Sim has been lost.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox2.Enabled = True
        TextBox3.Enabled = True
        TextBox4.Enabled = True
        CheckBox1.Enabled = True
        ComboBox1.Enabled = True
        Button3.Enabled = False
        Button4.Enabled = False
        TextBox7.Enabled = False
        TextBox8.Enabled = False
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label20.Text = Val(Label20.Text) + Val(1)
        If Label20.Text = 360 Then
            Label23.Text = Val(Label23.Text) + Val(1)
            Label20.Text = Val(0)
        End If
        If Label23.Text = 10 Then
            Label21.Text = Val(Label21.Text) + Val(1)
            Label23.Text = Val(0)
        End If
        If Label20.Text = 1 Then
            Dim flthrs As String
            flthrs = Label21.Text + "." + Label19.Text
        End If
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            Label17.Text = "Yes"
        Else
            Label17.Text = "No"
        End If
    End Sub
End Class

I thank you all once again for all you help!

Link to comment
Share on other sites

Nicholas ,

I ran your code here.

It looks OK to me. I assume we're still talking about the fuel here.

Your 'label26' is being regularly updated with the value of offset 0x090C - the amount of fuel used by Engine 1 in pounds. These looked sensible to me (I'm no expert on fuel use). As I increased the throttle this value increased at a faster rate as I would expect. When I shut down to engine this offset stopped changing.

When you say it "doesn't work", what do you mean? Are you getting no values? The wrong values? If so, what are they?

Also, do you realise this offset only works on FSX? It won't work on earlier versions like FS9.

Paul

Link to comment
Share on other sites

Oh is there a fuel code for FS9 or no sir? That is most likly the reason why and I am sorry for that.

A few messages ago in this thread I did say "This is obviously only for FSX and ESP, as 090C is new to FSUIPC4. It isn't available for FS9. ". Did you somehow miss that? Offset 090C is not listed in the offsets list for FS9 and before, only in the update for FSX, and coloured in that list to show it is new.

The other offsets you use are okay.

Please use the correct documentation for your endeavours.

Pete

Link to comment
Share on other sites

I am sorry that I missed that, is there any other way to find out the fuel on FS9? If not is there a way to read how much fuel there is in the plane at a certain point in time?

Yes, of course -- in my earlier reply I pointed you to the fuel tank offsets which contain their capacities and current levels.

You do seem to be skipping replies made to you for some reason. :-( Please do read more carefully. I'll repeat the information again just this once:

"The fuel tank capacities are provided by one offset location for each tank, and the level of the fuel in each is provided in another offset location for each. The offsets are listed quite clearly in the documentation -- check offsets 0B74 to 0BA8 for the more commonly used tanks and 1244 to 1260 for the extras some aircraft have (2nd and 3rd centre tanks, and 1 or 2 external tanks)."

Another way to find this stuff is to use the FSUIPC for Programmers documentation, which is included in the SDK, and simply search it for appropriate words, like "fuel" in this case. It really doesn't take so long -- certainly faster than asking here all the time! ;-)

Regards

Pete

Link to comment
Share on other sites

Ok I have researched more about how this all works but now I am getting another problem. I use the offset HB80 and this tells me how much fuel can be put into the left engine. But is there anyway to read what is in that engine say the capasicty is 2500 and its at 1500 how can I get that 1500?

Thank you

Link to comment
Share on other sites

is there anyway to read what is in that engine say the capasicty is 2500 and its at 1500 how can I get that 1500?

The offset before it (0B7C) tell you how full the tank is as a percentage. So if the tank holds 2500 and there is 1500 left, this offset will give you back 60%.

If this offset says 25% then the tank only has 625 US gallons left.

Offset 0B7C is an Integer (4 bytes). The documentation says: "% * 128 * 65536" which means it's a percentage but it's been multiplied by 128 and then 65536 before being stored here. To get the percentage back you need to divide the integer in this offset by these numbers:

Fuel left (%) = Offset value / 128 / 65536 * 100

You can then work out the amount of fuel by using the capacity:

Fuel left (us gallons) = Capacity * Fuel left (%) / 100

Or you can do the whole lot in one go:

Fuel left (us gallons) = Capacity offset * (fuel left offset / 128 / 65536)

Paul

Link to comment
Share on other sites

Firstly, I made a small error in the above post, which I have now corrected. Pete's document says the data in the level offset is a percentage but it's actually a fraction. I've corrected the above post by scaling the data in the level offset by 100.

Anyway - here is some code which will read the data from the two offsets I mentioned and calculate the remaining fuel in US Gallons for the Left tank:

This code uses three text boxes to display the data. They are called:

txtLeftTankCapacity

txtLeftTankLevelPercent

txtLeftTankLevelGallons

You need to declare the two offsets:

    Dim leftTankCapacity As Offset(Of Integer) = New Offset(Of Integer)(&HB80)
    Dim leftTankLevel As Offset(Of Integer) = New Offset(Of Integer)(&HB7C)

Here is a method (fired from a button) that will read the data and work out the amount of fuel left. The data is displayed in the text boxes.

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        FSUIPCConnection.Process()

        ' 1. Display the capacity of the left tank in a text box (number of US Gallons when full)
        Me.txtLeftTankCapacity.Text = leftTankCapacity.Value.ToString()

        ' 2. Get the level of the left tank as a percentage (i.e. how full it is)
        Dim dblLeftTankLevelPercentage As Double = leftTankLevel.Value / 128D / 65535D * 100D

        ' 3. Display this in a text box
        Me.txtLeftTankLevelPercent.Text = dblLeftTankLevelPercentage.ToString("f2") & "%"

        ' 4. Work out how many gallons are left
        Dim dblLeftTankLevelGallons As Double = leftTankCapacity.Value * dblLeftTankLevelPercentage / 100
        ' Or, if you can also do it like this:
        'Dim dblLeftTankLevelGallons As Double = leftTankCapacity.Value * (leftTankLevel.Value / 128D / 65535D)

        ' 5. Display the amount left in the left tank in gallons
        Me.txtLeftTankLevelGallons.Text = dblLeftTankLevelGallons.ToString("f2")
    End Sub

Regards,

Paul

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.