Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Anyone know of a way to interface VB.Net to the Level-D 767 dll? Are there any VB.net packages anywhere? I've searched on Google and Level-D forums but to no avail

The only way Ive come up with so far to read the 767 switches etc is to read the offsets as written by FSConv, is this efficient enough for my flight tracker program?

Thanks

Gray

  • 3 weeks later...
Posted

Hi,

Great work with the port to .NET. The original VB6 support was brilliant but since then I have moved on to VS 2005. Only problem is that the supplied source code for VB.NET which came with .NET shell rev 2.004 is not quite 1 to 1 for the newer VB 2005 code and the built in conversion wizard just ends up with a big blank form. The final code doesn't seem to show any examples of reading real-time values.

If anyone out there has any working samples of VB 2005 code that just gets the current lon/lat values I'd really apprieciate it.

Regards,

John

Posted

Hi John,

Only problem is that the supplied source code for VB.NET which came with .NET shell rev 2.004 is not quite 1 to 1 for the newer VB 2005 code and the built in conversion wizard just ends up with a big blank form

Sounds like you are using the VB.NET shell that is supplied with the FSUIPC SDK. If so, you might want to repost in a new thread as this thread is for my new object oriented .NET client dll. You might not be speaking to the correct audience here.

However, you might want to download my DLL and try it out (it's also free). It has many advantages of the one supplied in the SDK. Check out the first post on page 1 of this thread to download the package with documentation and sample projects.

There are also exmples of reading lon and lat with my DLL on the first page of this thread.

Paul

  • 4 weeks later...
Posted

I have question regarding destroying objects.

In my project I have option to select aircraft with 2 different classes, defaultaircraft and leveld767. I have used objAircraft to hold the copy of the object depending on which aircraft is selected.

In my module I use Public objAircraft but dont set it to anything as this is done when the aircraft is selected. ie If the aircraft is Level-D 767 then in my code I use objAircraft=New leveld767, for default objAircraft=New DefaultAircraft.

This works fine for one run ie I select an aircraft, the object is created and my app runs. If however after I then want to choose a different aircraft I get the error 'An item with the same key has already been added.'. So I added the line objAircraft=Nothing, thinking this would kill the object which it seems to as in debug the reference objAircraft is then empty or 'nothing'.

ie my code

        objAircraft = Nothing

        'see if it is level-d 767
        If n = "Level-D Boeing 767-300ER" Then
            'if it is then set flag to show we are using this aircraft
            objAircraft = New LevelD767 'create instance of level-d aircraft
            LevelD = True
        Else
            objAircraft = New DefaultAircraft 'create instance of default aircraft
            LevelD = False
        End If

How can I get around this problem please? It seems that I need to completely destroy the objAircraft but cant figure out how.

Also using the above with regards to defining an object at runtime means that I lose my intellisense at design ie the leveld767 class has different methods than the defaultaircraft class. By declaring objAircraft as public but not linking it to a class means when I do this

- objAircraft. I dont get the list of all the methods etc to choose from so I am having to type them in manually. Doing it this way also means that if I mispell anything then my app throws up the error in runtime and not design. Is there a better way around this?

thanks

Gray

Posted

Hi,

Sorry for the delay - I've just moved house and don't have any internet connection.

How can I get around this problem please? It seems that I need to completely destroy the objAircraft but cant figure out how.

Your objAircraft is destroyed as soon as you set all the references to it to Nothing.

What's probably causing the problem here is that your Offset objects that are created by the objAircraft object are still registered with the FSUIPCConnection class.

The FSUIPCConnection class holds its own references to the offsets. So even though you have released the references to the offsets held by the objAircraft object they are still left if memory because they are registered with FSUIPConnection.

What you need to do it disconnect them before you lose the references. So in your objAircraft objects I sugest you put a method called something like "ReleaseOffsets()". In there call DisonnectGroup() (or DeleteGroup() if you have v1.3 of the library) for all the groups you've declared. If you havn't used groups you'll need to call .Disconnect() on each offset. (I suggest you always use groups as it's easier to disconnect). This will make FSUIPCConnection give up it's references to the offsets.

Call this before setting objAircraft to nothing and you should be OK to create another instance of your aircraft object.

If you want more info on this read my reply to LordOfWings earlier in this thread.

By declaring objAircraft as public but not linking it to a class means when I do this

- objAircraft. I dont get the list of all the methods etc to choose from so I am having to type them in manually. Doing it this way also means that if I mispell anything then my app throws up the error in runtime and not design. Is there a better way around this?

Not really. If they have different methods etc then they are different classes. The closest you'll get is to pull out the common methods etc into a base class and inherit from that when you define your specialised aircraft classes. Then you can declare the variable as the base class type and some intellisense (the common methods etc) will come through.

The other way (or this can be used in combination with the above) is to cast into the specific aircraft object type once you know what type you're dealing with. Presumably you have to know in your code so you can call the special methods. e.g.

Dim objAircraft as Object
Dim acDefault as DefaultAircraft
Dim acLevelD as LevelD767
If objAircraft.Name = "LevelD767" then
   Set acLevelD = objAircraft
   ' Call methods on acLevelD here
else
  Set acDefault = objAircraft
  ' Call methods on default aircraft
end if

Hope this helps a bit.

Paul

  • 3 weeks later...
Posted

I'm a beginner amatuer programmer and I was wondering how to go about writing a program that would constantly scan a group of offsets while FS9 is running. For example I want to turn on the leds of a phidgets card when the landing gear goes down and turn them off when gear is up. I've already written a simple console program that uses FSUIPC client and reads the offset of the landing gear once and turns on the led [see below] but how do I have the program run all the time and wait for the gear to change and turn on the led? Do I use the c# Timer class to call Process() and use conditional statements or an event delegate type deal? Thanks

Dazed and confused

using System;

using System.Collections.Generic;

using System.Text;

using Phidgets;

using Phidgets.Events;

using FSUIPC;

using System.Threading;

namespace FSUIPC_LED_Wrapper_dll

{

class Program

{

static LED myLed = new LED();

static void Main(string[] args)

{

myLed.open();

myLed.waitForAttachment();

try

{

FSUIPCConnection.Open(FlightSim.FS2K4);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

Offset gearValue = new Offset(0x0BEB);

FSUIPCConnection.Process();

Console.WriteLine("Gearup = 0 Gear down = 4194048 Value = {0}", gearValue.Value.ToString());

int gear = 4194048;

if (gearValue.Value == gear)

{

myLed.leds[1] = 100;

myLed.leds[2] = 100;

myLed.leds[8] = 100;

}

Console.ReadKey(true);

myLed.leds[1] = 0;

myLed.leds[2] = 0;

myLed.leds[8] = 0;

FSUIPCConnection.Close();

myLed.close();

}

}

}

Posted
I'm a beginner amatuer programmer ...

......

Console.WriteLine("Gearup = 0 Gear down = 4194048 Value = {0}", gearValue.Value.ToString());

int gear = 4194048;

if (gearValue.Value == gear)

......

}

Hi

I don't know C**, but of course you need to use a timer.

Offset gearValue = new Offset(0x0BEB);

You use the Offset BEB ??

The Gear positions are read in

0BEC 4 Gear position (nose): 0=full up, 16383=full down

0BF0 4 Gear position (right): 0=full up, 16383=full down

0BF4 4 Gear position (left): 0=full up, 16383=full down

int gear = 4194048;

if (gearValue.Value == gear)

The value for Gear down is 16383.

  • 4 weeks later...
Posted

Hi,

Any memory limitations in regards to the amount of offsets that can be registered? Please see attached - it doens't make sense to me at all :( Basically, any additional offset registered through FSUIPC.Offset, gives the same identical error....

--

Chris.

post-12659-128689563683_thumb.gif

Posted

Hi Chris,

Sorry for the delay in replying - I still don't have an internet connection after 2 months!

It does look a very strange problem. Does it make any difference if you decalare the type as FSUIPC.Offset? eg.

Dim Offsetxxxx as FSUIPC.Offset(of Integer) = New FSUIPC.Offset(of Integer)(&Hxxx)

As you say it doesn't make sense that the compiler suddenly can't find the type after a few lines.

If the above doesn't work I'll investgate some more.

Paul

  • 8 months later...
Posted

hello im using this dll everythink okey but i have little problem

        
Offset getLat = new Offset(0x0560);
Offset getLon = new Offset(0x0568);

 double lat = (double)getLat.Value * 90d / (10001750d * 65536d * 65536d);
            this.textEdit25.Text = lat.ToString("#,##0.000000");
            this.textEdit25.ToolTip = "Lat Formatted";

double lon = (double)getLon.Value * 360d / (65536d * 65536d * 65536d * 65536d);
            this.textEdit26.Text = lon.ToString("#,##0.000000");
            this.textEdit26.ToolTip = "Lon Formatted";

i put airplane LTBA 36R normally runway lat and lon is this

40,969453 lat

28,809467 lon i look in BGL file

my data is :

40,969926 lat

28,809453 lon

i cant understand where is my problem thank you for all helps

burak.

Posted

i put airplane LTBA 36R normally runway lat and lon is this

40,969453 lat

28,809467 lon i look in BGL file

my data is :

40,969926 lat

28,809453 lon

i cant understand where is my problem

I can't understand where your problem is either, because there isn't one described here. A difference of 0.000473 in latitude works out to around 150 feet -- much much shorter than a runway, and 0.000014 in longitude, at that latitude, to less than 4 inches! So, put yourself 150 feet further south then check again!

If it is FS2004 default LTBA you are talking about, the "start" positions encoded into the BGL (those places to which FS positions you if you tell it to got to Runway X in the menu) are NOT the centre of the threshold itself, if you compute the latter based on runway length and width. Here's the output for 36R from my MakeRunways program:

Start 36R: N40:58:11.7129 E028:48:34.0316 163ft Hdg: 358.5 true

Computed start 36R: Lat 40.969452 Long 28.809471

You'll see that the computed ("ideal") start is different from the START location encoded in the BGL:

N40:58:11.7129 = 40.9699203

E028:48:34.0316 = 28.8094532

in other words, spot on what you are reading programmatically!

You know you can also check your position using Shift+Z, on screen, don't you? Or in the Map view?

Pete

  • 1 month later...
Posted

Thanks guys for all your hard work. My projects coming along really nicely.

I'm struggling to get any nav or com freq displaying correctly. Does anyone have a sample vbnet 2008 frequency code sample they wish to share?

many thanks in advance.

Posted

I'm struggling to get any nav or com freq displaying correctly. Does anyone have a sample vbnet 2008 frequency code sample they wish to share?

Hi Hawk,

Take a look at page 1 of this thread - about 8 posts down I answer a similar question about COM2 from Devon. This should show you how to to it.

If this isn't sufficient let me know...

Paul

  • 3 weeks later...
Posted
Is it possible to store a value at startup, and place it into another textfield that is updated?

Can you explain a bit more - I'm not sure what you're trying to do.

Where do you want to store the value at startup? - are you talking about writing a value into Flight Sim or simply storing a value in a variable or form control?

What do you mean by "another textfield that is updated"? What information is being updated and where does it come from?

If you can give me the specific problem you're trying to solve I'll be able to tell you how to do it.

Paul

Posted

Hi Paul,

For example,

I'd like to be able to store the fuel amount shown in the textbox upon starting the app, save that into another text field that isnt updated with the timer so I can view the fuel at start and fuel on landing if that makes sense

(i'm working with the SDK example)

Posted

I'd like to be able to store the fuel amount shown in the textbox upon starting the app, save that into another text field that isnt updated with the timer so I can view the fuel at start and fuel on landing if that makes sense

No probs - here's what you do...

1. Create the textbox to hold the startup fuel amount

2. Find the sub called: Private Sub Form1_Load...

3. After the call to OpenFSUIPC() add a process() line

4. Get the value from your fuel amount offset, do any maths/formatting you need and put the result in your new text box.

5. That's it. The Form1_Load() only runs when you start the form. So it'll grab the startup fuel amount. After that the timer will update your current fuel amount as normal.

Here's an example of the same thing but I'm storing the Compass Heading at startup as I don't have fuel data in my test app....

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenFSUIPC()
        FSUIPCConnection.Process()
        Me.txtHeadingAtStartup.Text = compass.Value.ToString("F2")
    End Sub

Paul

  • 3 months later...
Posted

Hello!

I have now successfully connected to FSUIPC, but a problem occurs then i'm trying to read values:

Error 1 Constant expression not representable in type 'Integer'.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        FSUIPCConnection.Process()
        Dim hdg As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H580)
        Dim hdg2 As Double = hdg.Value * 360 / (65536 * 65536)
        Label3.Text = hdg2

    End Sub

Using VB 2008 Express

Posted

Hi BoXon,

There are two problems here.

First, your specific error. The VB.NET compiler checks for overflows with literals at compile time, unlike VB6. What's happening here is that because hdg.Value is an Integer and so is 360 it's treating (65536 * 65536) as an Integer type. But 65536 squared is outside that range of a signed Integer in VB.NET. So it won't let you compile because the code will produce an overflow error at runtime.

The solutions is to enter the literal values as Double type literals by adding a .0 on the end like this:

Dim hdg2 As Double = hdg.Value * 360.0 / (65536.0 * 65536.0)

This will force the calculations to be done as doubles (the hgd.Value will automatically be cast into a Double by VB).

The second problem is that you're creating an Offset each time the timer ticks. You should only create the Offset once. The FSUIPC Client will throw an error if you try to create the same offset twice.

The easiest way is to make them class-level private variables (See my example VB.NET app). So they go under the 'CLASS' statement at the top of your class, but above the first Sub or Function.

Hope that helps...

If you have any more questions just ask.

Paul

Posted

Well, atleast i got it to read something.

But my heading is 224, but my code reads -117,735343845561

What am i doing wrong? :?

Imports FSUIPC
Public Class Form1

    Dim hdg As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H580)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            ' Attempt to open a connection to FSUIPC (running on any version of Flight Sim)

            FSUIPCConnection.Open()

            ' Opened OK
            Timer1.Enabled = True

        Catch ex As Exception

            ' Badness occurred - show the error message

            MessageBox.Show(ex.Message, "skyCARS", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        FSUIPCConnection.Process()
        Dim hdg2 As Double = hdg.Value * 360.0 / (65536.0 * 65536.0)
        Label1.Text = hdg2
    End Sub
End Class

Posted
But my heading is 224, but my code reads -117,735343845561

What am i doing wrong?

Firstly, offset 0580 is the heading in Degrees TRUE. You're probably seeing the heading in Degrees Magnetic. You need to get the Magnetic Variation from Offset 02A0 (see the FSUIPC Programmer's Guide).

The negative heading is because you are using an signed Integer. Try using an UInteger for the offset.

Dim hdg As Offset(Of UInteger) = New FSUIPC.Offset(Of UInteger)(&H580)

But, you'll still need to correct -tve headings (and headings over 360) after doing calculations with headings, by adding or subtracting 360.

So your code needs to do something like this:

    Dim hdg As Offset(Of UInteger) = New FSUIPC.Offset(Of UInteger)(&H580)
    Dim magvar As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H2A0)

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        FSUIPCConnection.Process()
        Dim hdgTrue As Double = hdg.Value * 360.0 / (65536.0 * 65536.0)
        Dim hdgMag As Double = hdgTrue - (magvar.Value * 360.0 / 65536.0)
        If hdgMag < 0 Then
            hdgMag += 360
        ElseIf hdgMag > 360 Then
            hdgMag -= 360
        End If
        Label1.Text = hdgMag
    End Sub

I can't test this at the moment but you get the idea...

Most people write a little function to 'normalise' the headings to between 0 and 360 to save writing the same code every time you do some maths on a heading.

Paul

Guest
This topic is now closed to further replies.
×
×
  • 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.