How to call transmitClientEvent
Pomax opened this issue · comments
I'm trying to send events into MSFS, and looking at the docs over on https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/API_Reference/Events_And_Data/SimConnect_TransmitClientEvent.htm paired with the code over in https://github.com/EvenAR/node-simconnect/blob/master/src/SimConnectConnection.ts#L384-L400 I wrote the following code to trigger the tail wheel lock:
handle.transmitClientEvent(
SimConnectConstants.OBJECT_ID_USER, // object id
0x00010000 + 1005, // event id
0, // event does not use data, so any value will do
0, // group id
0 // flags
);
(using the KEY_TOGGLE_TAILWHEEL_LOCK
event id found in the SDK's WASM\include\MSFS\Legacy\gauges.h
file)
Unfortunately, that seems to throw an exception (RecvException { exception: 1, sendId: 4, index: 2 }
) but I'm not quite sure what I need to fix to make this work, and I don't see any of the examples trying to send events into the sim to use as reference.
The sample on their website works for me in node-simconnect. That is, it doesn't give me an exception:
handle.mapClientEventToSimEvent(MY_EVENT_ID, "DME_SELECT");
handle.transmitClientEvent(SimConnectConstants.OBJECT_ID_USER, MY_EVENT_ID, 2, NotificationPriority.DEFAULT, EventFlag.EVENT_FLAG_GROUPID_IS_PRIORITY);
I have never played with the events system myself so I can't immediately see what's wrong with your code. I tried to use the same parameters as you in C++ and it gives me the same exception. Have you found a working example from the official SDK which uses these legacy gauge events?
Btw, index: 2
tells that it's the second parameter that causes the error (event id)
Not in the SDK itself, but I was using python-simconnect
before, which has a trigger function that takes the eventname as string and worked (to be fair, I've only ever needed it for setting/releasing the tail wheel lock, for some reason the actual simvar for that isn't settable, so triggering an event's your only option).
That little snippet was super helpful though, I was using (0,0) for the priorty and event mask, where it should have been (1,16): things work, huzzah!
async function testSimEvents(api) {
console.log(`tailwheel lock:`, await api.get(`TAILWHEEL_LOCK_ON`));
await api.trigger(`TOGGLE_TAILWHEEL_LOCK`);
console.log(`tailwheel lock:`, await api.get(`TAILWHEEL_LOCK_ON`));
await api.trigger(`TOGGLE_TAILWHEEL_LOCK`);
console.log(`tailwheel lock:`, await api.get(`TAILWHEEL_LOCK_ON`));
}
with API code:
trigger(triggerName, value = 0) {
const { handle } = this;
const eventID = this.nextId();
handle.mapClientEventToSimEvent(eventID, triggerName);
handle.transmitClientEvent(
SimConnectConstants.OBJECT_ID_USER,
eventID,
value,
1, // highest priority
16, // group id is priority
);
}
Yields the following console output:
tailwheel lock: { TAILWHEEL_LOCK_ON: 1 }
tailwheel lock: { TAILWHEEL_LOCK_ON: 0 }
tailwheel lock: { TAILWHEEL_LOCK_ON: 1 }