Jump to content
The simFlight Network Forums

FSUIPC Client DLL for .NET - Version 2.0


Recommended Posts

FS Interrogate and Traffic look seem to be working fine.

So, in that case you have a bug in your code.

Here's a sample of the log (yes, it gets big very quickly doesn't it!)

There's no point in logging stuff from working programs. I only suggested you use logging to find out what your program was doing wrong. Don't run anything else as well or it will be too confusing -- you only want your program using FSUIPC if you want to see what it does.

BTW, looking back, if you have an FSUIPC_Open call to make a connection and you are also using Paul's DLL to make a connection, you will likely have a clash in any case. I think you should either stick to the standard FSUIPC VB example methods, or use Paul's DLL. Don't mix methods.

Regards

Pete

Link to comment
Share on other sites

Pete wrote:

BTW, looking back, if you have an FSUIPC_Open call to make a connection and you are also using Paul's DLL to make a connection, you will likely have a clash in any case. I think you should either stick to the standard FSUIPC VB example methods, or use Paul's DLL. Don't mix methods.

Roger replies:

That was it! I had been trying to use both.

I've now got somewhere! Thanks.

For info, using only the FSUIPCDotNetClient1.3 from the FSUIPC SDK, what I have done is this:

1) I wrote a program which works fine when it's totally internal to Visual Basic 2008 Express.

2) I wanted to replace the checkboxes in the program with actual values from Flgith Sim 2004.

3) I wrote 'Imports FSUIPC' at the top of my program.

4) I made the association to the fsuipcClient.dll as described in the Readme under the heading: Installation (Step-by-Step for Visual Studio)

5) I then copied and pasted the relevant parts of the FSUIPCClient Example for opening the link to FS and also heavily used the examples for getting data.

6) I had to chenge the lien:

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

to:

MsgBox(ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)

I dunno why it wouldn't allow AppTitle, but otherwise it all works fine.

Result - I have a messagbox which says "Battery Switch is 1" or "Battery Switch is 0" depending on whether I switch it on or off in Flight Sim!

To those of you who eat Codeflakes for breakfast, this may not appear all that world-shaking, but I have to say I'm experiencing my very own "Hello World" moment and am quite excited!

Thanks Peter for your patient help , and thanks Paul for writing the DotNetClient stuff in the first place. best to thank Mary as well, just in case...

Cheers,

Roger.

Link to comment
Share on other sites

Hi Pete and Roger,

Sorry I've not chimed in on this - I've been in hospital for a couple of weeks after being thrown off a horse.

Anyway - It looks like you've sorted it out between you - thanks Pete.

I'm back on-line now so if you need any more help just ask...

Regards,

Paul

Link to comment
Share on other sites

G'day all,

I am currently designing an ACARS program primarily for FSX.

I got 2 problems/questions:

1. The data (heading, speed etc.) will not update with FS....its just 0

2. Dumb question, where do i get the codes e.g &H290 for the offsets? (i know &H means 'Hex')

Thanks in advance,

Mitchell Williamson

Australian Frontier VA PIREP System/VMS Development and Administration

http://www.australianfrontier.com

Link to comment
Share on other sites

1. The data (heading, speed etc.) will not update with FS....its just 0

Does the included sample VB.NET application work for you? If not there maybe something wrong with your FSUIPC install. If my app works then I'd need to see some code to see why yours isn't working. You can also use the FSUIPC logging features to see what values are being read from FSUIPC (if any).

2. Dumb question, where do i get the codes e.g &H290 for the offsets? (i know &H means 'Hex')

From the document "FSUIPC for Programmers.pdf" (FS9) or "FSUIPC4 Offsets status.pdf" (FSX) found in the FSUIPC SDK. Download it here:

http://www.schiratti.com/dowson.html

Paul

Link to comment
Share on other sites

The example program that came with the dll works perfectly.

Timer Sub:

   ' The timer handles the real-time updating of the Form.
    ' The default group (ie, no group specified) is 
    ' Processed and every Offset in the default group is updated.
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Try

            ' Process the default group 
            FSUIPCConnection.Process()


            ' IAS - Simple integer returned so just divide as per the 
            ' FSUIPC documentation for this offset and display the result.
            Dim airpeedKnots As Double = (airSpeed.Value / 128D)
            Me.iastxt.Text = airpeedKnots.ToString("f1")

            Me.alttxt.Text = altitude.ToString("f1")

            ' Compass heading
            ' Used to demonstrate disconnecting and reconnecting an Offset.
            ' We display the data in the field regardless of whether 
            ' it's been updated or not.
            Me.hdgtxt.Text = compass.Value.ToString("F2")


        Catch exFSUIPC As FSUIPCException
            If exFSUIPC.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_SENDMSG Then
                ' Send message error - connection to FSUIPC lost.
                ' Show message, disable the main timer loop and relight the 
                ' connection button:
                ' Also Close the broken connection.
                Me.Timer1.Enabled = False
                Me.cnctfsbtn.Enabled = True
                FSUIPCConnection.Close()
                MessageBox.Show("The connection to Flight Sim has been lost.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                ' not the disonnect error so some other baddness occured.
                ' just rethrow to halt the application
                Throw exFSUIPC
            End If

        Catch ex As Exception
            ' Sometime when the connection is lost, bad data gets returned 
            ' and causes problems with some of the other lines.  
            ' This catch block just makes sure the user doesn't see any
            ' other Exceptions apart from FSUIPCExceptions.
        End Try
    End Sub

cnctfsbtn (Connect to FS Button) code:

    Private Sub cnctfsbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cnctfsbtn.Click
        Try

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

            FSUIPCConnection.Open()
            Me.cnctfsbtn.Enabled = False
            Me.Timer1.Interval = 200
            Me.Timer1.Enabled = True
            Dim airpeedKnots As Double = (airSpeed.Value / 128D)
            Me.iastxt.Text = airpeedKnots.ToString("f1")
            Me.hdgtxt.Text = compass.Value.ToString("F2")
            Me.alttxt.Text = altitude.Value.ToString("00,000")
        Catch ex As Exception
            ' Badness occurred - show the error message
            MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)


        End Try

    End Sub

Code at top of VB script:

Imports FSUIPC

Public Class AFVA_ACARS

    ' Constants
    Private Const AppTitle As String = "AFVA Acars"

    ' Register the Offsets we're interesing in for this application
    Dim airSpeed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2BC) ' Basic integer read example
    Dim avionics As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H2E80) ' Basic integer read and write example
    Dim fsLocalDateTime As Offset(Of Byte()) = New FSUIPC.Offset(Of Byte())(&H238, 10) ' Example of reading an arbitary set of bytes.
    Dim aircraftType As Offset(Of String) = New FSUIPC.Offset(Of String)("AircraftInfo", &H3160, 24) ' Example of string and use of a group
    Dim lights As Offset(Of BitArray) = New FSUIPC.Offset(Of BitArray)(&HD0C, 2) ' Example of BitArray used to manage a bit field type offset.
    Dim compass As Offset(Of Double) = New FSUIPC.Offset(Of Double)(&H2CC) ' Example for disconnecting/reconnecting
    Dim pause As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H262, True) ' Example of a write only offset.
    Dim altitude As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H574)
    Dim verspd As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&HCCFE)

Any errors in the code above?

EDIT: Forgot the log:

********* FSUIPC4, Version 4.50 by Pete Dowson *********
User Name=""
User Addr=""
FSUIPC4 not user registered
WIDEFS7 not user registered, or expired
[Continuation log requested by user]
Running inside FSX (using SimConnect Acc/SP2 Oct07)
Module base=61000000
Wind smoothing fix is fully installed
   102531 System time = 20:48:42, Simulator time = 13:47:39 (04:47Z)
   102531 LogOptions changed, now 00000000 0000001D
   102609 Ready Flags: Ready-To-Fly=Y, In Menu=N, In Dlg=N
   109359  READ0  3304,   4 bytes: 00 00 00 45                                      ...E
   109359  READ0  3308,   4 bytes: 08 00 DE FA                                      ....
   125078 Ready Flags: Ready-To-Fly=Y, In Menu=Y, In Dlg=Y
   125078 Sim stopped: average frame rate for last 22 secs = 81.8 fps
   131031 LogOptions changed, now 00000000 00000001
[Log closed by user request, and continued in new file]
   151875 System time = 20:49:31, Simulator time = 13:48:04 (04:48Z)
   151875 *** FSUIPC log file being closed
Average frame rate for running time of 49 secs = 78.3 fps
Memory managed: 22 Allocs, 21 Freed
********* FSUIPC Log file closed ***********

Link to comment
Share on other sites

********* FSUIPC4, Version 4.50 by Pete Dowson *********

I can't help with the VB, but you should be aware that version 4.50 is old and unsupported. 4.53 is currently the oldest supported version for FSX, and 4.56 will be released before Christmas (I hope).

From the log it appears you are connecting okay but never actually reading anything from FSUIPC -- the two accesses logged are standard ones from the Open call. I don't see any reads in your code either, but then they could be hidden for all know of this programming system! ;-)

Regards

Pete

Link to comment
Share on other sites

Any errors in the code above?

Can't see anything obviously wrong. As Pete says, there is no data being requested from FSUIPC. I can only imagine the Timer_Tick() isn't actually getting called.

Try putting a breakpoint on one of the lines in Timer_Tick() to make sure it's being run.

If it's not getting run then:

Go to the form design view

At the bottom, click on the Timer control.

Go to the properties pane and put it into Event view by pressing the events button at the top of the pane.

Make sure the Tick event has "Timer1_Tick()" as its value. I suspect this is blank at the moment.

If this isn't the problem, and you are sure the Timer_Tick() sub is getting called, then let me know and I'll think about it some more.

Paul

Link to comment
Share on other sites

Heh! I wondered if anyne would get the joke about Peter, Paul and Mary!

Hi to Paul as well. Sorry to hear about your having been thrown off a horse - an animal which is uncomfortable in the middle and dangerous at both ends, according to Noel Coward...

If you're going to get yourself thrown off things, make sure the person throwing you has arranged for a soft landing as well.... ;-P

Anyway it appears I have been trying to reinvent the wheel, what with FSCaptain and FS2Crew out there.

But with you guys' help I _have_ learned how to interface a program with FS9, so at least if I come up with anonther idea I'll know how to do things!

Thanks again,

Roge.

Link to comment
Share on other sites

I have this problem. I am at notch #1 and i directly go to notch #4..

what i get in the values are: #$ (it stays lkike this for a while) and then goes #2,#3,#4..........

What are you using to find this out? If you are reading FSUIPC offsets, which have you tried. There are a lot realting to flaps. And what version of FS?

Pete

Link to comment
Share on other sites

  • 3 weeks later...

I have this problem. I am at notch #1 and i directly go to notch #4..

what i get in the values are: #$ (it stays lkike this for a while) and then goes #2,#3,#4..........

What are you using to find this out? If you are reading FSUIPC offsets, which have you tried. There are a lot realting to flaps. And what version of FS?

Pete

Yeap , my mistake not too much info:

FS2004 is the simulator at hand.

i am using the following definition:

Dim fs_Flaps As Offset(Of Int32) = New FSUIPC.Offset(Of Int32)("GeneralINF", &HBDC)
Dim fs_Flaps_inc As Offset(Of Int16) = New FSUIPC.Offset(Of Int16)("GeneralINF", &H3BFA)

and to calculate the current position i am using this:

Calc_Flap_Current_Pos = Math.Round(fs_Flaps.Value / fs_Flaps_inc.Value)

I think that the calculations are correct but the values within FS are making my problem appear.

lets say we are on incr 1 andi put flaps directly to increment 4...what i get is:

1......4......2......3.......4

he realizes that i put the flaps to increment 4 and then as the flaps are passing the values between it changes the variables....

any ideas?

Elias

Link to comment
Share on other sites

lets say we are on incr 1 andi put flaps directly to increment 4...what i get is:

1......4......2......3.......4

he realizes that i put the flaps to increment 4 and then as the flaps are passing the values between it changes the variables....

any ideas?

I'm still not understanding the problem I'm afraid. Do the Flaps physically move to #4 immediately, then go back to 2 then 3 then 4? It seems very unlikely to me.

Are you sure this is not simply down to the fact that you are reading back the value you wrote to 0BDC first, before FS has received the command, reacted to it and starts changing the lever position itself?

If you want to read the actual flaps position, not its control, you need to look at 0BE0 and 0BE4, not your control input at 0BDC.

Regards

Pete

Link to comment
Share on other sites

Hi,

I have been trying to code the DME speed kts the same way as showed on FS.

I have problem showing my speed as rounded to the lower int as FS.

If the DME speed is 120,6 it will be displayd as 121 in my program.

code:

Dim vor2dmespd As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H308)

Dim dmespdval As Short

dmespdval = Math.Floor(CInt(vor1dmespd.Value)) / 10

TextBox5.Text = Format(dmespdval, "000")

Any help would be nice.

Bw:Mika

Link to comment
Share on other sites

I have problem showing my speed as rounded to the lower int as FS.

If the DME speed is 120,6 it will be displayd as 121 in my program.

...

dmespdval = Math.Floor(CInt(vor1dmespd.Value)) / 10

By using the "floor" of the value divided by 10, you are rounding DOWN. If you want to round to the nearest integer (120.6 as 121) you have to add 0.5 first.

I don't know VB or whatever language you are using, but in C it would be

dmespdval = (int) ((vor1dmespd.Value + 0.5)/ 10);

Regards

Pete

Link to comment
Share on other sites

dmespdval = Math.Floor(CInt(vor1dmespd.Value)) / 10

I think you've got the parenthesis wrong there. You want to 'floor' the result of the division. You are dividing after you've done the 'floor' function.

Try this:

dmespdval = Math.Floor(vor1dmespd.Value / 10)

Paul

Link to comment
Share on other sites

I think you've got the parenthesis wrong there. You want to 'floor' the result of the division. You are dividing after you've done the 'floor' function.

I didn't spot that, but if you don't add 0.5 before the division, won't "floor" still round down, not to the nearest integer as he seems to want?

Pete

Link to comment
Share on other sites

dmespdval = Math.Floor(CInt(vor1dmespd.Value)) / 10

I think you've got the parenthesis wrong there. You want to 'floor' the result of the division. You are dividing after you've done the 'floor' function.

Try this:

dmespdval = Math.Floor(vor1dmespd.Value / 10)

Paul

This did the trick, i use VB.Net and i'am still learning the basics, Thaks to you all.

And the greatest thanks to You Pete, for making the homecockpit scene as it it today.

I can't see how flight simulator could be this popular without your work with the FSUIPC.

I'am a proud owner of registered copy of it, and now i'am using the FSUIPCclient to program my own stuff.

Link to comment
Share on other sites

Hello there, i have a question regarding the offset addresses.

I am developing a small application (.net 3.5 with WPF) which is supposed to be able to accomplish basic tasks, like gather flight information, aircraft information, and so on.

So far i've managed to create an Autopilot Panel, Lights Panel (as the one in the example from the SDK), and some basic info.

I am a bit in a doubt regarding the 0764 address. FSInterrogate says (which i assumed) that the value is 1 if AP is available, 0 if not.

However in code, running the debbugger that offset always returns 1 (i've tried with cessna, feelthere airbus A318, B777, PMDG MD-11 and so forth). Even trying to retrieve the value with FSInterrogate, it is still 1 in all cases.

My question is - is this a) issue caused by my FSUIPC dll, b) issue from FS (someth not configure correctly, as in not setting that value to 0 inside FS itself), c) this isn't really working at all ?

I would need that value in order to make visible or not the Autopilot Panel.

Thanks in advance!

P.S. for whoever is interested, i can make the code available, as long as i don't break any rules :)

Forgot to mention, i am using C#. Here's the code i am using to retrieve the value:

Declaration:

...

public Offset autopilotAvailable = new Offset(FSUIPCGroupProcess.Aircraft, FSConstants.AutopilotAvailable);

... declared as public because i access it from a UserControl

Usage:

public void ProcessAicraftInfo()

{

try

{

_fs.Process(FSUIPCGroupProcess.Aircraft);

lblAicrType.Content = aircraftType.Value;

lblAicrState.Content = aircraftState.Value == 1 ? "On Ground" : "Airborne";

_isAutopilotAvailable = autopilotAvailable.Value == 1 ? true : false;

lblApAvailable.Content = _isAutopilotAvailable ? "Yes" : "No";

}

catch (FSUIPCException ex)

{

if (ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)

{

//Force disconnect

Disconnect();

System.Windows.MessageBox.Show("FSUIPC Connection Lost.");

}

}

}

_fs is instance of FSInstance class created by me, which exposes different methods from FSUIPCConnection and so forth. Disconnect() is another method which calls FSUIPConnection.Disconnect() and clears some variables from the current Window and so forth.

Link to comment
Share on other sites

Hi,

I can't see anything obviously wrong with your code.

is this a) issue caused by my FSUIPC dll,

You can easily tell if my DLL (or your code) is causing the problem by looking at FSInterogate. If FSInterogate is reporting 1s as well then it's very unlikely the problem lies with your or my code.

i've tried with cessna, feelthere airbus A318, B777, PMDG MD-11 and so forth

But surely all those aircraft have autopilots installed? Are you sure you've tried it with a plane without an autopilot? Maybe a glider (sailplane)?

Paul

Link to comment
Share on other sites

Hello there,

First of all thanks for your prompt response.

As far as i know about Cessna, it doesn't have Autopilot. I might be wrong though, i will try also with a glider or something.

I was 99% sure it can't be a DLL issue, but rather a FS issue. I'll be able to confirm that later today (i am at work now so 8+ i'll be back to codingnow i'm coding for "others" :) ).

I would have another question which came on top of my mind now.

So, you've offered the possibility to instantiate an Offset by specifying a GroupName, which then might be specified in the Process() overloaded method (awesome feature, i want to add).

In my app, i have got about 4 Groups of offsets: Aircraft Info, Flight Info, Autopilot Info and Lights Info.

I am using in read/write mode the Autopilot and Lights when needed (as you could see in my code, when the private bools are true - _processAutoPilot, _processLights).

To get to my question, basically based on those bools i am calling a Process({group_name} but in my timer_tick event handler, i might call Process 4 times (i have 4 groups).

Is that much more resource consuming then rather calling Process() without any group name (when all the groups must be processed) ?

Thanks in advance, again.

Link to comment
Share on other sites

I am a bit in a doubt regarding the 0764 address. FSInterrogate says (which i assumed) that the value is 1 if AP is available, 0 if not.

Please do NOT use the data in FSInterrogate as the reference for offset use. The data module for that is not maintained, and it does not explain things. It is merely a tool, not a reference. Use the offset tables in the documentation provided, where they are much more fully explained and which are maintained.

However in code, running the debbugger that offset always returns 1 (i've tried with cessna, feelthere airbus A318, B777, PMDG MD-11 and so forth). Even trying to retrieve the value with FSInterrogate, it is still 1 in all cases.

Of course. Because they all have autopilots. Try the glider. If you don't want any of those aircraft to have an autopilot you have to change the AIRCRAFT.CFG file.

Regards

Pete

Link to comment
Share on other sites

Hello,

thanks again for the prompt response :)

I would've said that aircraft like Cessna (the single propeller ones) don't have autopilot, but it seems i was wrong.

I wouldn't want to go for the aircraft.cfg method, because i would allow some friends of mine to use this application, and i wouldn't have a 100% sure thing when it comes to configuration files and all.

Is there any possibility to retrieve through FSUIPC client dll for .net the aircraft model also? As far as i can see, for feelthere B777-200ER for example, all i get is BOEING, for A318 i get AIRBUS.

What does the offset for aircraft type actually retrieve? (by that i mean from where ...).

Regards,

Tudor Hoinaru

Link to comment
Share on other sites

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.