Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

Happy New year for all ;)

1) Howto monitoring VAS Value to Vb.net in my ACARS system ?

2) Request Pay Service to help me to make good ACARS system (in the good way) communicate to phpvms and an other for monitoring simple Google MAP datas via Php / MySQL (with source code)

Thanks hope receive answers.

 

Regards Fred

Posted

1. The VAS Value (Memory available to FS in Kb) is in offset 0x024C. It's an Integer (4 Bytes),

2. I can't help with writing a full ACARS system unfortunately. Hopefully someone else is looking for a new project.

Paul

Posted
22 minutes ago, Paul Henty said:

1. The VAS Value (Memory available to FS in Kb) is in offset 0x024C. It's an Integer (4 Bytes),

2. I can't help with writing a full ACARS system unfortunately. Hopefully someone else is looking for a new project.

Paul

Hi Paul,

Can you please make for me  a form to monitoring VAS available and used with the correct way to connect to FSX. In that way in can view howto do in the correct way, Thanks

 

Fred

Posted

Here is the VB version:

You need to make a new Windows Forms project in VB.NET

Then add a reference to the FSUIPCClient.DLL (I've attached the latest version).

Then on Form1 you need to add:

  • A button called "btnConnect"
  • A button called "btnDisconnect"
  • A Timer called "Timer1"
  • A Label called "lblConnectionStatus"
  • A Label called "lblVAS"

Then paste the whole code below into the code behind the form:

Imports FSUIPC

Public Class Form1

    ' Declare offsets here
    Private VAS As Offset(Of Integer) = New Offset(Of Integer)(&H24C)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' set the timer to tick every second. (Change this if you need more rapid updates)
        Me.Timer1.Interval = 1000
        configureScreen()
    End Sub

    Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
        ' Try to connect to FS
        Try
            FSUIPCConnection.Open()
            ' Open was sucessful, start the timer
            Me.Timer1.Start()
        Catch exFSUIPC As FSUIPCException
            MessageBox.Show(exFSUIPC.Message)
        Catch ex As Exception
            MessageBox.Show("Error when connecting: " & ex.Message)
        End Try
    End Sub

    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' Process the offsets
        Try
            FSUIPCConnection.Process()
        Catch ex As Exception
            ' Connection lost
            ' Stop the timer
            Me.Timer1.Stop()
            MessageBox.Show("Error reading data from Flight Sim: " & ex.Message)
        Finally
            configureScreen()
        End Try
    End Sub

    Private Sub configureScreen()
        ' Configure the screen
        ' Test if connection is open or not
        If (FSUIPCConnection.IsConnectionOpen()) Then
            Me.lblConnectionStatus.Text = "Connected to " & FSUIPCConnection.FlightSimVersionConnected.ToString()
            Me.btnConnect.Enabled = False
            Me.btnDisconnect.Enabled = True
            ' VAS readout
            Dim VASMb As Double = Me.VAS.Value / 1024D ' Convert from Kb to Mb
            Me.lblVAS.Text = "Memory remaining: " & VASMb.ToString("N0") & "Mb" ' Show Mb with no decimal places
        Else
            Me.lblConnectionStatus.Text = "Not connected"
            Me.btnConnect.Enabled = True
            Me.btnDisconnect.Enabled = False
            Me.lblVAS.Text = "Memory remaining: ?Mb"
        End If
    End Sub

    Private Sub btnDisconnect_Click(sender As Object, e As EventArgs) Handles btnDisconnect.Click
        ' Stop the timer
        Me.Timer1.Stop()
        ' Close the connection
        FSUIPCConnection.Close()
        configureScreen()
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        FSUIPCConnection.Close()
    End Sub
End Class

 

How it works:

There is a timer (Timer1) that is set to tick every 1 second. (You can change this if your application needs more frequent updates).

When the user presses the connect button, we try to connect to FSUIPC. If a problem occurs we tell the user. If the connection is good we start the timer ticking.

We then call configure screen which will always draw the screen properly, depending on if we're connected etc. If we are connected it:

  • lights the 'diconnect' button
  • tells the user they are connection (and to what sim - FSX/P3D etc)
  • disables the 'connect' button
  • displays the current VAS value

If we're not connected it:

  • disabled the 'diconnect' button
  • tells the user they are not connected
  • enables the 'connect' button
  • displays the ? for the current VAS value

Once the timer is ticking, on every tick we call Process() to get the the current offset data. If all goes well we call configureScreen() to update the screen. If there is a problem (connection lost) then we stop the timer and tell the user there was a problem.

I'll post the C# version below in a bit...

FSUIPCClient3.0_RC2.zip

Posted

Here is the C# version. Other than the language it's identical to the VB version above.

NOTE: You will need to change the 'namespace'. Before pasting the code, make a note of what the namespace is for your project (Look at the code behind the Form1 and see what the namespace line says). Then after pasting the code, change the namespace from VASOffsetCSharp back to whatever yours was.

To get this working use the same procedure as above. Make a new C# windows forms project, add the controls to the form and paste the entire code behind, then change the namespace.

NOTE2: Is c# make sure the timer is called 'timer1' (lowercase t) and not 'Timer1' as in VB.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FSUIPC;

namespace VASOffsetCSharp
{
    public partial class Form1 : Form
    {
        // Declare offsets here
        private Offset<int> VAS = new Offset<int>(0x024C);

        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
            this.FormClosing += Form1_FormClosing;
            this.timer1.Tick += timer1_Tick;
            this.btnConnect.Click += btnConnect_Click;
            this.btnDisconnect.Click += btnDisconnect_Click;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // set the timer to tick every second. (Change this if you need more rapid updates)
            this.timer1.Interval = 1000;
            configureScreen();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            // Try to connect to FS
            try
            {
                FSUIPCConnection.Open();
                // Open was sucessful, start the timer
                this.timer1.Start();
            }
            catch (FSUIPCException exFSUIPC)
            {
                MessageBox.Show(exFSUIPC.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error when connecting: " + ex.Message);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                // Process the offsets
                FSUIPCConnection.Process();
            }
            catch (Exception ex)
            {
                // Connection lost
                // Stop the timer
                this.timer1.Stop();
                MessageBox.Show("Error reading data from Flight Sim: " + ex.Message);
            }
            finally
            {
                configureScreen();
            }
        }

        private void configureScreen()
        {
            // Configure the screen
            // Test if connection is open or not
            if (FSUIPCConnection.IsConnectionOpen())
            {
                this.lblConnectionStatus.Text = "Connected to " + FSUIPCConnection.FlightSimVersionConnected.ToString();
                this.btnConnect.Enabled = false;
                this.btnDisconnect.Enabled = true;
                // VAS readout
                double VASMb = this.VAS.Value / 1024d; // Convert from Kb to Mb
                this.lblVAS.Text = "Memory remaining: " + VASMb.ToString("N0") + "Mb"; // Show Mb with no decimal places
            }
            else
            {
                this.lblConnectionStatus.Text = "Not connected";
                this.btnConnect.Enabled = true;
                this.btnDisconnect.Enabled = false;
                this.lblVAS.Text = "Memory remaining: ?Mb";
            }
        }

        private void btnDisconnect_Click(object sender, EventArgs e)
        {
            // Stop the timer
            this.timer1.Stop();
            // Close the connection
            FSUIPCConnection.Close();
            configureScreen();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            FSUIPCConnection.Close();
        }
    }
}

Paul

Posted

The easiest way would be to use a ProgressBar control.

Set the min value to 0, the max value to 4096 and the Style to 'continuous' or 'blocks' depending on your preference.

The memory used is just 4096 - memory free in Mb (VASMb variable in the example code).

In the configureScreen method, set the Value property of ProgressBar to the memoryUsed, Then set the colour of the bar (Forecolor property) depending on the value of the memory used. For example, if it's > 3072 then Red, else if > 2048 then Orange, else Green. Set the levels to your preference.

There are plenty of websites and YouTube videos that cover how to use ProgressBars in VB.NET and C#.

Paul

Posted
3 hours ago, Paul Henty said:

In the configureScreen method, set the Value property of ProgressBar to the memoryUsed, Then set the colour of the bar (Forecolor property) depending on the value of the memory used. For example, if it's > 3072 then Red, else if > 2048 then Orange, else Green. Set the levels to your preference.

There are plenty of websites and YouTube videos that cover how to use ProgressBars in VB.NET and C#.

Paul

Sorry Paul I don't understand this part

 ProgressBar1.Value = VASMb
            If VASMb = 4096 Then
                ProgressBar1.ForeColor = Color.Green

                If VASMb <> 3072 Then
                    ProgressBar1.ForeColor = Color.Orange
                End If

                If VASMb < 2048 Then
                    ProgressBar1.ForeColor = Color.Orange
                End If

            End If

Fred

2017-01-02 22_04_21-VAS Monitoring.png

Posted

Try this:

            Dim VASUsedMb = 4096 - VASMb
            ProgressBar1.Value = VASUsedMb
            If VASUsedMb > 3072 Then
                ProgressBar1.ForeColor = Color.Red
            ElseIf VASUsedMb > 2048 Then
                ProgressBar1.ForeColor = Color.Orange
            Else
                ProgressBar1.ForeColor = Color.Green
            End If

Paul

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.