Hello the the Community! I just migrated from X-Plane to MSFS and lost all my previous experience on coding external modules.
The context is the following:
I develop an external module between some hardware which I use and FBW320 using SimConnect. Most of it works well and I am able to send text displays and to switch leds from my module to the aircraft.
Unfortunately, I also have to send H: events to the aircraft and we know that this is not possible directly.
I wrote a little WASM module to receive an order from my external module and then use the gauge interface to execute it towards the aircraft.
I see from the MSFS debug console that my wasm is correctly loaded, has not error code in the initialization sequence, but never receive any data from my external module.
Her are the way I define the shared client data in external module and wasm:
external module:
if (FAILED(SimConnect_MapClientDataNameToID(hSimConnect, "JPPbridge", 0)))
LOG <= "MapClientDataNameToID has failed";
if (FAILED(SimConnect_AddToClientDataDefinition(hSimConnect, 0, SIMCONNECT_CLIENTDATAOFFSET_AUTO, SIMCONNECT_CLIENTDATATYPE_INT64, 0, 0)))
LOG <= "AddToClientDataDefinition has failed";
if (FAILED(SimConnect_CreateClientData(hSimConnect, 0, 8, SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY)))
LOG <= "CreateClientData has failed";
WASM:
fprintf(stderr, "JPPBridge initialization");
if (FAILED(SimConnect_Open(&hSimConnect, "JPPbridge", (HWND)NULL, 0, 0, 0)))
{
fprintf(stderr, "Open failed");
return;
}
if (FAILED(SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL)))
{
fprintf(stderr, "CallDispatch failed");
return;
}
if (FAILED(SimConnect_MapClientDataNameToID(hSimConnect, "JPPbridge", 0)))
{
fprintf(stderr, "MapClientDataNameToID failed");
return;
}
if (FAILED(SimConnect_AddToClientDataDefinition(hSimConnect, 0, SIMCONNECT_CLIENTDATAOFFSET_AUTO, SIMCONNECT_CLIENTDATATYPE_INT64, 0, 0)))
{
fprintf(stderr, "AddToClientDataDefinition failed");
return;
}
if (FAILED(SimConnect_CreateClientData(hSimConnect, 0, 8, SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY)))
fprintf(stderr, "CreateClientData has failed");
if (FAILED(SimConnect_RequestClientData(hSimConnect, 0, iReqID, 0, SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET,
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT)))
{
fprintf(stderr, "RequestClientData failed");
return;
}
Finaly, the external module sent data like this:
if (FAILED(SimConnect_SetClientData(hSimConnect, 0, 0, 0, 0, 8, &BridgeContainer.m_data)))
LOG <= (string)"SetClientData failed for event " + to_string(id);
And the WasM receives it with a dispatch proc:
void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext)
{
if (pData->dwID == SIMCONNECT_RECV_ID_CLIENT_DATA)
{
SIMCONNECT_RECV_CLIENT_DATA* recv_data = (SIMCONNECT_RECV_CLIENT_DATA*)pData;
//if (recv_data->dwRequestID == iReqID)
//{
SBridge* cmd = (SBridge*)&recv_data->dwData;
execute_calculator_code(SEVENT[cmd->m_evt].m_name, nullptr, &cmd->m_val, nullptr);
fprintf(stderr, "execute event call %s with value %i", SEVENT[cmd->m_evt].m_name, cmd->m_val);
//}
}
}
I sincerely hope that somebody with MSFS experience will be ablle to assist me and make me exit from my stucked situation. Thanks in advance.
The context is the following:
I develop an external module between some hardware which I use and FBW320 using SimConnect. Most of it works well and I am able to send text displays and to switch leds from my module to the aircraft.
Unfortunately, I also have to send H: events to the aircraft and we know that this is not possible directly.
I wrote a little WASM module to receive an order from my external module and then use the gauge interface to execute it towards the aircraft.
I see from the MSFS debug console that my wasm is correctly loaded, has not error code in the initialization sequence, but never receive any data from my external module.
Her are the way I define the shared client data in external module and wasm:
external module:
if (FAILED(SimConnect_MapClientDataNameToID(hSimConnect, "JPPbridge", 0)))
LOG <= "MapClientDataNameToID has failed";
if (FAILED(SimConnect_AddToClientDataDefinition(hSimConnect, 0, SIMCONNECT_CLIENTDATAOFFSET_AUTO, SIMCONNECT_CLIENTDATATYPE_INT64, 0, 0)))
LOG <= "AddToClientDataDefinition has failed";
if (FAILED(SimConnect_CreateClientData(hSimConnect, 0, 8, SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY)))
LOG <= "CreateClientData has failed";
WASM:
fprintf(stderr, "JPPBridge initialization");
if (FAILED(SimConnect_Open(&hSimConnect, "JPPbridge", (HWND)NULL, 0, 0, 0)))
{
fprintf(stderr, "Open failed");
return;
}
if (FAILED(SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL)))
{
fprintf(stderr, "CallDispatch failed");
return;
}
if (FAILED(SimConnect_MapClientDataNameToID(hSimConnect, "JPPbridge", 0)))
{
fprintf(stderr, "MapClientDataNameToID failed");
return;
}
if (FAILED(SimConnect_AddToClientDataDefinition(hSimConnect, 0, SIMCONNECT_CLIENTDATAOFFSET_AUTO, SIMCONNECT_CLIENTDATATYPE_INT64, 0, 0)))
{
fprintf(stderr, "AddToClientDataDefinition failed");
return;
}
if (FAILED(SimConnect_CreateClientData(hSimConnect, 0, 8, SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY)))
fprintf(stderr, "CreateClientData has failed");
if (FAILED(SimConnect_RequestClientData(hSimConnect, 0, iReqID, 0, SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET,
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT)))
{
fprintf(stderr, "RequestClientData failed");
return;
}
Finaly, the external module sent data like this:
if (FAILED(SimConnect_SetClientData(hSimConnect, 0, 0, 0, 0, 8, &BridgeContainer.m_data)))
LOG <= (string)"SetClientData failed for event " + to_string(id);
And the WasM receives it with a dispatch proc:
void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext)
{
if (pData->dwID == SIMCONNECT_RECV_ID_CLIENT_DATA)
{
SIMCONNECT_RECV_CLIENT_DATA* recv_data = (SIMCONNECT_RECV_CLIENT_DATA*)pData;
//if (recv_data->dwRequestID == iReqID)
//{
SBridge* cmd = (SBridge*)&recv_data->dwData;
execute_calculator_code(SEVENT[cmd->m_evt].m_name, nullptr, &cmd->m_val, nullptr);
fprintf(stderr, "execute event call %s with value %i", SEVENT[cmd->m_evt].m_name, cmd->m_val);
//}
}
}
I sincerely hope that somebody with MSFS experience will be ablle to assist me and make me exit from my stucked situation. Thanks in advance.