• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

problem with subscribetosystemevent

Messages
39
Country
france
Hi everybody,
i have problems with the instruction and the comportment of the API SubscribeToSystemEvent...
i develop with VB.net and this seems not working...
i use an enum to define events : paused, unpaused, simstart and simstop...
i subscribe to these event using the API SubscribeToSystemEvent.
I try to trap them in an handler to ONRECVEVENT but it doesn't work.
what am i doing wrong ?

thank's in advance
 
No ideas at all ?
i've tried many solutions but no more results...
does anybody have an example of a vb.net script to test ?
help, please...
 
You would be better off supplying the code that does not work.

Are you overriding DefWndProc?
 
Hi Nudge and thank's for your answer.

I don't understand what you mean with "You would be better off supplying the code that does not work"...

Yes i do override the DefWndProc and the code is :

Protected Overrides Sub DefWndProc(ByRef m As Message)
If m.Msg = WM_USER_SIMCONNECT Then
If fsx_simconnect IsNot Nothing Then
fsx_simconnect.ReceiveMessage()
End If
Else
MyBase.DefWndProc(m)
End If
End Sub

what's wrong with that ?
 
Because there are a few steps to getting this to work, it would be quicker to see the section of code you are using to handle system events from FSX.

It's far too difficult to help you without seeing some code.
 
Here are some snippets from my C# code:

Code:
class MyConnect
{
  private enum EventEvent : uint
  {
    SimStart,
    ....
  }

  ...

  public void Setup()
  {
    ...

    simconnect.OnRecvEvent += new
               SimConnect.RecvEventEventHandler(OnRecvEvent);
    simconnect.SubscribeToSystemEvent(EventEvent.SimStart,
               "SimStart");
    ...
  }

  private void OnRecvEvent(SimConnect sender,
                           SIMCONNECT_RECV_EVENT data)
  {
     switch (data.uEventID)
     {
          case (uint)EventEvent.SimStart:
                    Logger.log("SimStart Received");
          ....
     }
  }
 
Hi again
thank's Denial for your C# code

here is a bit of code i use which is near the C# one, but in VB.net

Enum MES_EVENT_SYSTEM
SIMSTOP
SIMSTART
PAUSED
UNPAUSED
End Enum

Sub fsx_simconnect_OnRecvEvent(ByVal sender As SimConnect, ByVal data As SIMCONNECT_RECV_EVENT)
If data.uEventID = CType(MES_EVENT_SYSTEM.SIMSTOP, UInteger) Then
Me.Timer1.Enabled = False
End If
If data.uEventID = CType(MES_EVENT_SYSTEM.SIMSTART, UInteger) Then
Me.Timer1.Enabled = True
End If
If data.uEventID = CType(MES_EVENT_SYSTEM.PAUSED, UInteger) Then
Me.Timer1.Enabled = False
End If
If data.uEventID = CType(MES_EVENT_SYSTEM.UNPAUSED, UInteger) Then
Me.Timer1.Enabled = True
End If
End Sub

Sub ...
AddHandler fsx_simconnect.OnRecvEvent, New SimConnect.RecvEventEventHandler(AddressOf fsx_simconnect_OnRecvEvent)
fsx_simconnect.SubscribeToSystemEvent(MES_EVENT_SYSTEM.SIMSTOP, "SimStop")
fsx_simconnect.SubscribeToSystemEvent(MES_EVENT_SYSTEM.SIMSTART, "SimStart")
fsx_simconnect.SubscribeToSystemEvent(MES_EVENT_SYSTEM.PAUSED, "Paused")
fsx_simconnect.SubscribeToSystemEvent(MES_EVENT_SYSTEM.UNPAUSED, "Unpaused")

End sub
 
Change your IF THEN to a SELECT CASE, I've had problems in the past with the IF THEN and SimConnect.
 
You coud try to add a handler for the 'OnRecvException'

simconnect.OnRecvException += new
SimConnect.RecvExceptionEventHandler(OnRecvException);

and then use a handler like:

Code:
        private void OnRecvException(SimConnect sender, 
                                     SIMCONNECT_RECV_EXCEPTION data)
        {
            SIMCONNECT_EXCEPTION se = (SIMCONNECT_EXCEPTION)data.dwException;
            Logger.log("!!! Exception: " + se);
            Logger.log("!!! SendId:" + data.dwSendID + 
                       " Index:" + data.dwIndex + " Id:" + data.dwID);            
        }

(Logger is my own class that just writes message to a file).

I always add handlers to the OnRecvExecption, OnRecvOpen and OnRecvQuit handlers, just to track what's going on.

You could also add a messagebox after this:

Sub fsx_simconnect_OnRecvEvent(ByVal sender As SimConnect, ByVal data As SIMCONNECT_RECV_EVENT)

Before the if/then's so you can find out whether the problem is the if/thenor not receiving the events at all.

Daniel
 
Well i will try your solutions but i wanted to understand something before....
I have another event defined which is gear_toggle. When i press the G key on the keyboard, the onrecevent is fired
but when i press the P key (for pause or unpause) nothing happen.
That's a strange behavior...
well i follow my investigations trying your ideas
 
Hmmmm, it sound like you have more than one enum being referrenced in the event handler.

Do you have multiple enums being referenced in the event handler that are not initialised with a number sequentially?

Example

Enum Events1
SomeEvent
SomeEvent2
End Enum

Enum Events2
SomeEvent3
SomeEvent4
End Enum

these should be defined like so

Enum Events1
SomeEvent = 0
SomeEvent2 = 1
End Enum

Enum Events2
SomeEvent3 = 2
SomeEvent4 = 3
End Enum

SimConnect only returns an integer, not a unique integer, so you have to sequentially number your enum members, if using multiple enums in the event handler.
 
Yes i do have this...
i will try to change the definitions with integers as you said.
it's probably the solutions.i went in debug mode and saw this integer value tested.
but the last question is why the OnRecEvent is not fired when i press the P key on the keyboard. I put a msgbox at the beginning of the procedure handler and it only appears when i press another key which is an event...can it be due to these multiple enum definitions ?
I will tell you the result later, when i'll be at home...i'm at my office at this time...:o
bye
 
yes if you have two enums with the same integer value. They don't have to be sequential, but they must be unique.
 
Last edited:
Resolved !

Great Nudge !
i did what you said with my enum events and it works fine now. OnRecvEvent is fired for every event
Thank's a lot

See you next time on this forum perhaps :)
 
No problems, now you know why it's always best to see as much code as you can afford to show, it was not until you stated you had other events firing that I thought you may have multiple enums.
 
Back
Top