setting an event disables data reading

Discuss on the SimConnect SDK can be used by programmers to write add-on components for Prepar3D
Locked
ppp333ddd_
Posts: 58
Joined: Fri Aug 18, 2017 1:04 am

setting an event disables data reading

Post by ppp333ddd_ »

Hi,

I am using simconnect and C# WPF for data reading, data writing and event setting (pause the game, make the game in slew mode, etc.). The data reading and data writing worked fine previously. But when I tried to add a button to set the game into slew mode - the same function as pressing a 'y' in P3D, it was implemented but it disabled my data reading function.

Here is part of my code in function iniDataRequest(),
// subscribe to Slew controls - these are for event setting, but they disabled my data reading, why???
SimConnectModule.MapClientEventToSimEvent(EVENTS.SLEW_SET, "SLEW_TOGGLE");
SimConnectModule.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.SLEW_SET, false);

Without them, the data reading works fine. But when adding them, although the slew mode setting is fine, it disabled the data reading. Why?

Thanks a lot,
Jeff
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: setting an event disables data reading

Post by obinder »

Hello Jeff,

impossible to say without seeing the rest of your code. This can be anything. Don't you get exceptions from .Net and/or SimConnect? Usually you are told if something goes wrong.

Best regards
Oliver Binder
Lorby-SI
ppp333ddd_
Posts: 58
Joined: Fri Aug 18, 2017 1:04 am

Re: setting an event disables data reading

Post by ppp333ddd_ »

Hello Oliver,

Thanks for your reply. There is no exception as it won't remind me of any functional problem. Could you help me find what is the problem for simultaneous data reading and event setting if I extract my code and sent it to you?

Best regards,

Jeff
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: setting an event disables data reading

Post by obinder »

Hello Jeff,

not even SimConnect exceptions? Those are not thrown in your code, SimConnect sends them back to you and you have to write a callback function to get them.

As for your other request: sorry, that is taking it a bit far. I usually get paid for that kind of stuff. I am certain that you will figure it out eventually, because the problem you describe normally doesn't happen at all. Just check everything in your code, slowly and methodically. Make sure that you have all information that there is. A lot of SimConnect based development is trial&error unfortunately.

Best regards
Oliver Binder
Lorby-SI
ppp333ddd_
Posts: 58
Joined: Fri Aug 18, 2017 1:04 am

Re: setting an event disables data reading

Post by ppp333ddd_ »

Hello Oliver,

Thanks for your reply.

I have solved it now by creating multiple SimConnect objects and build multiple connections - therefore there is no conflict between data reading and event writing. But I encountered another problem - I cannot do the data reading in multiple .xaml of the project although reading data in one .xaml is fine. I have also tried to create different SimConnect Objects and build multiple connections for it, but it doesn't work. Am I in the correct way? Is it necessary to create multiple SimConnect objects and connections for data reading in multiple UI of the same project? Many thanks!

Best regards,
Jeff
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: setting an event disables data reading

Post by obinder »

Hello Jeff,

Sorry, can't help you there. I always only use a single access point, one Singleton SimConnect client per application that handles all data communications with the API. That way I avoid "flooding", redundancy (like having multiple loops reading the same values) sequencing and race conditions.

In C# I have both Windows Forms and WPF apps, and I never experienced what you describe in the OP. Unless your event sets the simulator into a state where it stops sending data (like dialog mode or pause)

Best regards
Oliver Binder
Lorby-SI
ppp333ddd_
Posts: 58
Joined: Fri Aug 18, 2017 1:04 am

Re: setting an event disables data reading

Post by ppp333ddd_ »

Hello Oliver,

Thanks for your reply. I really appreciate for the time you spent on my question.

The problem I am constantly encountering is the conflict among data-reading, data-writing and event-writing. To implement one of them, one Singleton SimConnect client is fine. But when I need to combine them in one application, collisions happen. Is there any technique needed for it, e.g. multithreading, etc?

Sorry I am a very primary programmar. The problems I have are probably too low-level.

Best regards,
Jeff
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: setting an event disables data reading

Post by obinder »

Hello Jeff,

my Singleton SimConnect class handles all communications - reading&writing variables as well as receiving&sending events at the same time. There never was any issue with that. I am frequently using the slew mode, on the users' craft and on other objects as well.

Did you implement an exception handler (OnRecvException) so SimConnect can tell you if you are doing something wrong?

Best regards
Oliver Binder
Lorby-SI
ppp333ddd_
Posts: 58
Joined: Fri Aug 18, 2017 1:04 am

Re: setting an event disables data reading

Post by ppp333ddd_ »

Hi Oliver,

Thanks for your reply. Now I can do the data reading in multiple .xaml files but still needs another simconnect client to to send events - when initializing data, function SubscribeToSystemEvent (to refresh read data) and function MapClientEventToSimEvent (to set slew mode) seems can't be called simultaneously by the same simconnect client.

Yes the exception handler OnRecvException is triggered but I cannot know where is wrong.

Best regards,
Jeff
User avatar
WarpD
Posts: 1469
Joined: Mon Feb 14, 2011 5:29 am

Re: setting an event disables data reading

Post by WarpD »

Jeff,

You're doing something seriously wrong. I have never, ever needed multiple SimConnect interfaces to read/write data combined with triggering events.
Ed Wilson
Senior Developer
Mindstar Aviation
Locked