Jump to content
The simFlight Network Forums

events in FSUIPC C# possible ?


mroschk

Recommended Posts

Hello,

 

just  question if Events are possible with C#.Net FSUIPC Client?

Like in the Windows programming .... as example onButtonPress()...for Offsets.

So, if an Offset Change, i want that a procedure is autmatic called and the Offset chage can be handled.

 

Matthias

Link to comment
Share on other sites

No, I haven't built in any events for offset value changes.

I've often thought about it because it's more in line with the normal way of .NET programming, but I can't see a good way of doing it. 

e.g. Would you want to subscribe to each offset's updated event separately? Or maybe one event that gets called every time any offset changes. If it's one event, should it be called once for each offset that has changed, or just once with an array of all offsets that have changed?

Would you want to still control the Process() calls yourself or have the DLL do this automatically given a polling interval? If you're using multiple groups then you may need to specify different time intervals between the automatic Process() calls for each group separately.

FSUIPC doesn't work by events, so the DLL will need to Process() and then detect changes in the Offset values.

It can be done, but the more I think about it the more complicated it gets.

If you have any ideas on how it should work from your point of view, or answers to the questions raised then I'll have another think about it.

Paul

Link to comment
Share on other sites

Hello,

 

thanks for the Answer.
I understand..it is not working with FSUIPC at the Moment.

But it Sounds very good that you think about including it.

I see two way's here:
1. A Special class which the user can add Offsets to Monitor. This class provides the eventhandler like in c#:
https://msdn.microsoft.com/de-de/library/system.eventhandler(v=vs.110).aspx

2. I dont know if it is possible, but it is the best way i think.
If it is possible use the FSX or P3D to Trigger the update of an Offset. Then the user can just look at it and just do it like in a c# Event like:

private Offset<int> airspeed = new Offset<int>(0x02BC);
airspeedonChange()....

That second way would be great!

Matthias

Link to comment
Share on other sites

>> If it is possible use the FSX or P3D to Trigger the update of an Offset.

No it's impossible. The only way it can work is the DLL detecting changed values after a Process() call.

Here is a mock-up of something that I could implement fairly easily: Note that you still need to handle the Process() calls yourself.

        private Offset<int> airspeed = new Offset<int>(0x02BC);

        public Form4()
        {
            InitializeComponent();
            this.airspeed.ValueChanged += airspeed_ValueChanged;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FSUIPCConnection.Process();
        }

        private void airspeed_ValueChanged(object sender, OffsetEventArgs<int> e)
        {
            this.lblAirspeed.Text = "Airspeed: " + e.Offset.Value.ToString();
        }

Would that be any good?

Paul

Link to comment
Share on other sites

Quote

i know this example from the SDK.

No, you can't do this at the moment. There is no ValueChanged at the moment. It was something I was proposing to add.

Quote

But i think a Timer for such a Operation is not a really good and .Net conform Solution.

I am very sensitive with timers in any .Net program.

I agree, but FSUIPC doesn't work on an event model. The only way is to use timers to poll the data. Either you use a timer in your application or I have to use a timer in my DLL. There's no escaping timers. If I do it in the DLL the timer would need to run on a different thread than your UI thread which means extra complexity getting the value data onto the main UI thread.

As I said I've thought about it before but always came to the same conclusions:

1. Doing it properly (background thread timer in the DLL) is complicated.

2. Doing it the easy way (as show in my last post) doesn't really give you much improvement over the current way,

Unfortunately FSUIPC is a 'procedural' style interface, not an object oriented one. It's that way because it was invented 20 years ago. The DLL does its best to give ,NET programmers a more familiar '.NET' way of programming (way better than the original C SDK ports to C#) but there's only so much that is possible because of how FSUIPC works.

Paul

Link to comment
Share on other sites

Pete Dowson is the author of FSUIPC, I just wrote the .NET interface.

The only way I can think of creating a fully event-driven .NET interface is to switch to using SimConnect. However, it's a lot of work and I'm not really very interested in doing that in the near future. There is already a .NET client DLL for SimConnect written by Microsoft so .NET programmers already have something that works. Unfortunately it's quite cumbersome and poorly documented. There may be a need for another DLL that makes SimConnect much easier but I don't have the time at the moment.

Paul

 

Link to comment
Share on other sites

  • 5 months later...

Hi Paul,

I am using your client to communicate with the sim. Simconnect seemed to be more complicated and it lacks support and documentation for mortals like us. I am not a programmer so I do not understand much of the available official documentation So I go for the fsuipc client dll. But I do also think that events will be nice as using timers and threads uses to much sources. I am not a programmer so maybe I am doing things wrong. What I do is I try to manage timer intervals when the comm is idle and from a point of time it gets more complicated then not having events.

Link to comment
Share on other sites

Yes, lots of timers can get difficult to manage. Unfortunately this is how it has to be done. FSUIPC was designed for C, C++, not for .NET.

Although the DLL can make FSUIPC look more like a .NET class library, it can't change the way FSUIPC works fundamentally.

As I discuss in this thread, I've thought about adding events but I don't believe it's practical.

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.