SimConnect send control-requests (events) to P3D airplane.

Discuss on the SimConnect SDK can be used by programmers to write add-on components for Prepar3D
Post Reply
lvedin
Posts: 36
Joined: Wed Aug 01, 2018 6:58 am

SimConnect send control-requests (events) to P3D airplane.

Post by lvedin »

I have the SimConnect C++ project up end running, seams to work since SimConnect_Open() response is correct.

I want to control my PMDG 737 such as gear and flaps from my application. Is this possible, what is the basic way ?.. The samples does not give me good hints since purposes typical get notifications from P3D, I only want to send commands such as GEAR_UP to P3D.

Can I simply call a SimConnect function whenever I want, is it SimConnect_SetDataOnSimObject() ?

Or must I create my void CALLBACK MyDispatchProcSD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext) ?.. If so, can I make it regular called so I can send my airplane control-command-events such as GEAR_UP at any time.

The reason to control from my application, is I use analog lever to control the flaps, and each button has a 2:nd function etc handled by my application. I read my controls via Windows API.

A lot of thank's if I can solve this / Lennart Vedin
lvedin
Posts: 36
Joined: Wed Aug 01, 2018 6:58 am

Re: SimConnect send control-requests (events) to P3D airplane.

Post by lvedin »

Additional regarding my research:
I did look the sample ThrottleControl.cpp

It looks like it aim to control the throttle, but i do not understand how the function call shall really work.
struct structThrottleControl
{
double throttlePercent;
};
structThrottleControl tc;
hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_THROTTLE, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(tc), &tc);

since DEFINITION_THROTTLE and REQUEST_THROTTLE are equal to zero (as the definition, and as my debug), there is nothing I see in the entire code that tell P3D that this is a throttle request.
lvedin
Posts: 36
Joined: Wed Aug 01, 2018 6:58 am

Re: SimConnect send control-requests (events) to P3D airplane.

Post by lvedin »

Hmm ! I suppose I shall use Simulation Variable as Text such as text-string: "GENERAL ENG THROTTLE LEVER POSITION:1".

I will try this for "FLAPS HANDLE INDEX" and "GEAR HANDLE POSITION"....
JB3DG
Posts: 609
Joined: Mon Jan 09, 2012 6:44 pm

Re: SimConnect send control-requests (events) to P3D airplane.

Post by JB3DG »

SetDataOnSimObject is used for setting Sim vars directly. You will want TransmitClientEvent to send events instead.
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun
lvedin
Posts: 36
Joined: Wed Aug 01, 2018 6:58 am

Re: SimConnect send control-requests (events) to P3D airplane.

Post by lvedin »

No it is my fault since I write about events. I cannot send events to take action in P3D, except to pass to other clients.
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: SimConnect send control-requests (events) to P3D airplane.

Post by obinder »

lvedin wrote: Tue Sep 25, 2018 6:44 pm No it is my fault since I write about events. I cannot send events to take action in P3D, except to pass to other clients.
Sure you can, and in some cases you have to because the simulator variable can't be set. Not the case in your example, but there are many of those variables that you can only read but not write to.

Before using them, you first have to establish the link between your structure, the enum value and the actual variable(s). That is what "SimConnect_AddToDataDefinition" is for. I suggest that you carefully re-read the examples.

Best regards
Oliver Binder
Lorby-SI
JB3DG
Posts: 609
Joined: Mon Jan 09, 2012 6:44 pm

Re: SimConnect send control-requests (events) to P3D airplane.

Post by JB3DG »

You normally use SimConnect_MapClientEventToSimEvent for your key event definitions (along with the extra functions involved in this process) and use SimConnect_TransmitClientEvent to trigger that event. Use SimConnect_AddToDataDefinition for adding sim variables to definition groups that you will set with SimConnect_SetDataOnSimObject.
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun
Post Reply