MSFS SimConnect...
MSFS SimConnect...
I got a push towards using HTTP calls, using MSFS 2020 SimConnect and Python. See this MSFS 2020 post: https://forums.flightsimulator.com/t/is ... tic/358010
Has anyone done any SimConnect gets/puts using PB and HTTP?
Would HTTP calls using PB be the correct route to go or is using Python a better choice for getting/putting data into the simulator using SimConnect?
Thanks for any thoughts you may have on this.
Has anyone done any SimConnect gets/puts using PB and HTTP?
Would HTTP calls using PB be the correct route to go or is using Python a better choice for getting/putting data into the simulator using SimConnect?
Thanks for any thoughts you may have on this.
Re: MSFS SimConnect...
Since I wrote the post above, I have been using a combination of Visual Studio C/C++ (Yuk!) and SimConnect calls to get data from MSFS 2020. I am then putting that data into an SQLite DB so that I can read that data and display it using a PB user GUI.
It is working well, but the response time is limited to getting data once every second. Which is not really acceptable. A Simconnect loop and writes to SQLite is not efficient enough to process every quarter-second. I tried that.
I really need to do the SimConnect calls from PB directly so it all happens in memory. I have found two different SimConnect PB posts that have direct calls. One is using the very old FSX calls (2008) so I am not sure that they will work. The link is here on the PB forum: viewtopic.php?f=13&t=32555&start=15
This other link is more up to date but the project was abandoned by the author and I have tried reaching him twice now to no success. His PB SimConnect GitHub link: https://github.com/aziascreations/FS202 ... c-Bindings
If I could get some help on how to link in these PB SimConnect.lib procedural calls I would be home free. These are the library calls that I need to code:
Here is a picture of my working Flight Information program. While it works nicely I would really like to have it all happen from PB. If someone can help me with these calls I would really appreciate it! This is over my programming skills to pull off in PB.
https://drive.google.com/file/d/1XpyBdf ... sp=sharing
There are millions of users now using MSFS 2020 and it is very hot. PB could really use a boost and we could do that here if we were to get SimConnect working with PB. If anyone could code a simple window that gets data from the sim (just one field of data) I would be indebted to you and likewise, other "new" PB users would be too. I would gladly post on the MSFS forums how I was able to get (and eventually, put) data using PB.
Heck, I would gladly buy you some serious coffee if you could code a simple, very quick, PB SimConnect window for me!
It is working well, but the response time is limited to getting data once every second. Which is not really acceptable. A Simconnect loop and writes to SQLite is not efficient enough to process every quarter-second. I tried that.
I really need to do the SimConnect calls from PB directly so it all happens in memory. I have found two different SimConnect PB posts that have direct calls. One is using the very old FSX calls (2008) so I am not sure that they will work. The link is here on the PB forum: viewtopic.php?f=13&t=32555&start=15
This other link is more up to date but the project was abandoned by the author and I have tried reaching him twice now to no success. His PB SimConnect GitHub link: https://github.com/aziascreations/FS202 ... c-Bindings
If I could get some help on how to link in these PB SimConnect.lib procedural calls I would be home free. These are the library calls that I need to code:
Code: Select all
SimConnect_Open(phSimConnect.l, szName.s, hwnd.l, UserEventWin32.l, hEventHandle.l, ConfigIndex.l)
SimConnect_AddToDataDefinition(hSimConnect.l, DefineID.l, DatumName.s, UnitsName.s, DatumType = #SIMCONNECT_DATATYPE_FLOAT64, fEpsilon.f=0.0, DatumID.l=#SIMCONNECT_UNUSED)
SimConnect_RequestDataOnSimObject(hSimConnect.l, RequestID.l, DefineID.l, ObjectID.l, Period.l, flags.l, origin.l, interval.l, limit.l)
SimConnect_GetNextDispatch(hSimConnect.l, *ppData.SIMCONNECT_RECV, pcbData.l)
SimConnect_Close(hSimConnect.l)
https://drive.google.com/file/d/1XpyBdf ... sp=sharing
There are millions of users now using MSFS 2020 and it is very hot. PB could really use a boost and we could do that here if we were to get SimConnect working with PB. If anyone could code a simple window that gets data from the sim (just one field of data) I would be indebted to you and likewise, other "new" PB users would be too. I would gladly post on the MSFS forums how I was able to get (and eventually, put) data using PB.
Heck, I would gladly buy you some serious coffee if you could code a simple, very quick, PB SimConnect window for me!
Re: MSFS SimConnect...
Here is some working C/C++ code that gets a SimVar variable:
Code: Select all
#include <Windows.h>
#include "SimConnect.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
HANDLE hSimConnect = NULL;
enum DATA_DEFINE_ID { DEFINITION_ID_AP, };
enum DATA_REQUEST_ID { REQUEST_AP_SETTINGS, };
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct AutopilotData {
public:double ALTITUDE;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR pCmdLine, _In_ int nCmdShow)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
HRESULT hr;
SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = NULL;
SIMCONNECT_RECV* pData = NULL;
DWORD cbData = 0;
AutopilotData* pAutopilotData = NULL;
bool bDone = false;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Connect to MSFS
if (FAILED(SimConnect_Open(&hSimConnect, "MSFS Info", NULL, 0, 0, 0))) {
return false;
}
// Add data to return
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ID_AP, "INDICATED ALTITUDE", "Feet");
// Request data call to return data
hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_AP_SETTINGS, DEFINITION_ID_AP, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_CLIENT_DATA_PERIOD_VISUAL_FRAME);
bDone = false;
while (bDone == false)
{
// Get next set of data
hr = SimConnect_GetNextDispatch(hSimConnect, &pData, &cbData);
if (SUCCEEDED(hr))
{
// Assign data to structure
pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
if (pData->dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA && pObjData->dwRequestID == REQUEST_AP_SETTINGS)
{
pAutopilotData = (AutopilotData*)&pObjData->dwData;
// Display Altitude data here
// Not the most efficient. A call back funtion should be used instead.
Sleep(16); // Basically, 60fps (1000ms / 60fps = 16ms)
}
}
}
// Close
hr = SimConnect_Close(hSimConnect);
return true;
}
Re: MSFS SimConnect...
Yup. I'm back at this. The MSFS community has voiced an interest in creating a HUD window display to be used while flying. I really think PB is the answer to what they want. And, I know this would get more notice from other programmers on the MSFS.com and FSDeveloper.com forums.
I need your help to get the data. I have spent the last two days cleaning up some code that I downloaded from here: https://github.com/aziascreations/FS202 ... c-Bindings
I am having trouble with structure pointers and addresses. The code below compiles but it is wrong. I have marked the code that is erroring out, and I have more code at the bottom that I have no idea how to declare.
If anyone could help me I would "really" appreciate it. I am converting from C++ code to PB. You see the posts above. The C++ code (post above) is working just fine. But I want to do it in PB!
Below are some Google drive links to SimConnect.dll and SimConnect.lib for compiling purposes.
SimConnect.lib: https://drive.google.com/file/d/1NBKTE8 ... sp=sharing
SimConnect.dll: https://drive.google.com/file/d/1Riw2MM ... sp=sharing
This code is the MSFS SimConnect.h file converted into a SimConnect.pbi file. Don't trust this! I did the best I could do to set everything properly:
And this is the main program. The code at lines: 57 and 86 are incorrect. But, I have no idea what I am doing at this point. But I am really close! Help me, please!
Here is what I am working towards. Now I just need the data for the window:
https://drive.google.com/file/d/16wEBks ... sp=sharing
I need your help to get the data. I have spent the last two days cleaning up some code that I downloaded from here: https://github.com/aziascreations/FS202 ... c-Bindings
I am having trouble with structure pointers and addresses. The code below compiles but it is wrong. I have marked the code that is erroring out, and I have more code at the bottom that I have no idea how to declare.
If anyone could help me I would "really" appreciate it. I am converting from C++ code to PB. You see the posts above. The C++ code (post above) is working just fine. But I want to do it in PB!
Below are some Google drive links to SimConnect.dll and SimConnect.lib for compiling purposes.
SimConnect.lib: https://drive.google.com/file/d/1NBKTE8 ... sp=sharing
SimConnect.dll: https://drive.google.com/file/d/1Riw2MM ... sp=sharing
This code is the MSFS SimConnect.h file converted into a SimConnect.pbi file. Don't trust this! I did the best I could do to set everything properly:
Code: Select all
;Original Author: https://github.com/aziascreations
;Original file location: https://github.com/aziascreations/FS2020---SimConnect-PureBasic-Bindings
; Macros
Macro LONG : l : EndMacro
Macro DWORD : l : EndMacro
Macro HANDLE : i : EndMacro
Macro HRESULT : LONG : EndMacro
Macro HWND : HANDLE : EndMacro
Macro WORD : w : EndMacro
CompilerIf Not #PB_Compiler_OS = #PB_OS_Windows
CompilerError "Error: Please compile this program on a Windows machine!"
CompilerEndIf
CompilerIf Not #PB_Compiler_Processor = #PB_Processor_x64
CompilerError "Error: Please compile the program for a x64 cpu architecture!"
CompilerEndIf
EnableExplicit
; Constants
#DWORD_MAX = $FFFFFFFF
; DWORDs
; special value to indicate unused event, ID
#SIMCONNECT_UNUSED = #DWORD_MAX
; proxy value for User vehicle ObjectID
#SIMCONNECT_OBJECT_ID_USER = 0
; Floats
; Maximum value for SimConnect_CreateClientData dwSize parameter
#SIMCONNECT_CLIENTDATA_MAX_SIZE = 8192
; Notification Group priority values
#SIMCONNECT_GROUP_PRIORITY_HIGHEST = 1 ; highest priority
#SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE = 10000000 ; highest priority that allows events to be masked
#SIMCONNECT_GROUP_PRIORITY_STANDARD = 1900000000 ; standard priority
#SIMCONNECT_GROUP_PRIORITY_DEFAULT = 2000000000 ; default priority
#SIMCONNECT_GROUP_PRIORITY_LOWEST = 4000000000 ; priorities lower than this will be ignored
; SIMCONNECT_DATA_INITPOSITION.Airspeed
#INITPOSITION_AIRSPEED_CRUISE = -1 ; aircraft's cruise airspeed
#INITPOSITION_AIRSPEED_KEEP = -2 ; keep current airspeed
; AddToClientDataDefinition dwSizeOrType parameter type values
#SIMCONNECT_CLIENTDATATYPE_INT8 = -1 ; 8-bit integer number
#SIMCONNECT_CLIENTDATATYPE_INT16 = -2 ; 16-bit integer number
#SIMCONNECT_CLIENTDATATYPE_INT32 = -3 ; 32-bit integer number
#SIMCONNECT_CLIENTDATATYPE_INT64 = -4 ; 64-bit integer number
#SIMCONNECT_CLIENTDATATYPE_FLOAT32 = -5 ; 32-bit floating-point number (float)
#SIMCONNECT_CLIENTDATATYPE_FLOAT64 = -6 ; 64-bit floating-point number (double)
; AddToClientDataDefinition dwOffset parameter special values
#SIMCONNECT_CLIENTDATAOFFSET_AUTO = -1 ; automatically compute offset of the ClientData variable
; Open ConfigIndex parameter special value
#SIMCONNECT_OPEN_CONFIGINDEX_LOCAL = -1 ; ignore SimConnect.cfg settings, and force local connection
;- Macros
Macro SIMCONNECT_OBJECT_ID : DWORD : EndMacro
Macro SIMCONNECT_NOTIFICATION_GROUP_ID : DWORD : EndMacro
Macro SIMCONNECT_CLIENT_EVENT_ID : DWORD : EndMacro
Macro SIMCONNECT_TEXT_TYPE : DWORD : EndMacro
Macro SIMCONNECT_DATA_DEFINITION_ID : DWORD : EndMacro
Macro SIMCONNECT_DATATYPE_TYPE : DWORD : EndMacro
Macro SIMCONNECT_DATA_REQUEST_ID : DWORD : EndMacro
Macro SIMCONNECT_SIMOBJECT_TYPE_TYPE: DWORD : EndMacro
;- Enums
Enumeration SIMCONNECT_RECV_ID
#SIMCONNECT_RECV_ID_NULL
#SIMCONNECT_RECV_ID_EXCEPTION
#SIMCONNECT_RECV_ID_OPEN
#SIMCONNECT_RECV_ID_QUIT
#SIMCONNECT_RECV_ID_EVENT
#SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE
#SIMCONNECT_RECV_ID_EVENT_FILENAME
#SIMCONNECT_RECV_ID_EVENT_FRAME
#SIMCONNECT_RECV_ID_SIMOBJECT_DATA
#SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE
#SIMCONNECT_RECV_ID_WEATHER_OBSERVATION
#SIMCONNECT_RECV_ID_CLOUD_STATE
#SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID
#SIMCONNECT_RECV_ID_RESERVED_KEY
#SIMCONNECT_RECV_ID_CUSTOM_ACTION
#SIMCONNECT_RECV_ID_SYSTEM_STATE
#SIMCONNECT_RECV_ID_CLIENT_DATA
#SIMCONNECT_RECV_ID_EVENT_WEATHER_MODE
#SIMCONNECT_RECV_ID_AIRPORT_LIST
#SIMCONNECT_RECV_ID_VOR_LIST
#SIMCONNECT_RECV_ID_NDB_LIST
#SIMCONNECT_RECV_ID_WAYPOINT_LIST
#SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SERVER_STARTED
#SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_CLIENT_STARTED
#SIMCONNECT_RECV_ID_EVENT_MULTIPLAYER_SESSION_ENDED
#SIMCONNECT_RECV_ID_EVENT_RACE_END
#SIMCONNECT_RECV_ID_EVENT_RACE_LAP
EndEnumeration
; Data data types
Enumeration SIMCONNECT_DATATYPE
#SIMCONNECT_DATATYPE_INVALID ; invalid data type
#SIMCONNECT_DATATYPE_INT32 ; 32-bit integer number
#SIMCONNECT_DATATYPE_INT64 ; 64-bit integer number
#SIMCONNECT_DATATYPE_FLOAT32 ; 32-bit floating-point number (float)
#SIMCONNECT_DATATYPE_FLOAT64 ; 64-bit floating-point number (double)
#SIMCONNECT_DATATYPE_STRING8 ; 8-byte string
#SIMCONNECT_DATATYPE_STRING32 ; 32-byte string
#SIMCONNECT_DATATYPE_STRING64 ; 64-byte string
#SIMCONNECT_DATATYPE_STRING128 ; 128-byte string
#SIMCONNECT_DATATYPE_STRING256 ; 256-byte string
#SIMCONNECT_DATATYPE_STRING260 ; 260-byte string
#SIMCONNECT_DATATYPE_STRINGV ; variable-length string
#SIMCONNECT_DATATYPE_INITPOSITION ; see SIMCONNECT_DATA_INITPOSITION
#SIMCONNECT_DATATYPE_MARKERSTATE ; see SIMCONNECT_DATA_MARKERSTATE
#SIMCONNECT_DATATYPE_WAYPOINT ; see SIMCONNECT_DATA_WAYPOINT
#SIMCONNECT_DATATYPE_LATLONALT ; see SIMCONNECT_DATA_LATLONALT
#SIMCONNECT_DATATYPE_XYZ ; see SIMCONNECT_DATA_XYZ
#SIMCONNECT_DATATYPE_MAX ; enum limit
EndEnumeration
; Exception error types
Enumeration SIMCONNECT_EXCEPTION
#SIMCONNECT_EXCEPTION_NONE
#SIMCONNECT_EXCEPTION_ERROR
#SIMCONNECT_EXCEPTION_SIZE_MISMATCH
#SIMCONNECT_EXCEPTION_UNRECOGNIZED_ID
#SIMCONNECT_EXCEPTION_UNOPENED
#SIMCONNECT_EXCEPTION_VERSION_MISMATCH
#SIMCONNECT_EXCEPTION_TOO_MANY_GROUPS
#SIMCONNECT_EXCEPTION_NAME_UNRECOGNIZED
#SIMCONNECT_EXCEPTION_TOO_MANY_EVENT_NAMES
#SIMCONNECT_EXCEPTION_EVENT_ID_DUPLICATE
#SIMCONNECT_EXCEPTION_TOO_MANY_MAPS
#SIMCONNECT_EXCEPTION_TOO_MANY_OBJECTS
#SIMCONNECT_EXCEPTION_TOO_MANY_REQUESTS
#SIMCONNECT_EXCEPTION_WEATHER_INVALID_PORT
#SIMCONNECT_EXCEPTION_WEATHER_INVALID_METAR
#SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_GET_OBSERVATION
#SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_CREATE_STATION
#SIMCONNECT_EXCEPTION_WEATHER_UNABLE_TO_REMOVE_STATION
#SIMCONNECT_EXCEPTION_INVALID_DATA_TYPE
#SIMCONNECT_EXCEPTION_INVALID_DATA_SIZE
#SIMCONNECT_EXCEPTION_DATA_ERROR
#SIMCONNECT_EXCEPTION_INVALID_ARRAY
#SIMCONNECT_EXCEPTION_CREATE_OBJECT_FAILED
#SIMCONNECT_EXCEPTION_LOAD_FLIGHTPLAN_FAILED
#SIMCONNECT_EXCEPTION_OPERATION_INVALID_FOR_OBJECT_TYPE
#SIMCONNECT_EXCEPTION_ILLEGAL_OPERATION
#SIMCONNECT_EXCEPTION_ALREADY_SUBSCRIBED
#SIMCONNECT_EXCEPTION_INVALID_ENUM
#SIMCONNECT_EXCEPTION_DEFINITION_ERROR
#SIMCONNECT_EXCEPTION_DUPLICATE_ID
#SIMCONNECT_EXCEPTION_DATUM_ID
#SIMCONNECT_EXCEPTION_OUT_OF_BOUNDS
#SIMCONNECT_EXCEPTION_ALREADY_CREATED
#SIMCONNECT_EXCEPTION_OBJECT_OUTSIDE_REALITY_BUBBLE
#SIMCONNECT_EXCEPTION_OBJECT_CONTAINER
#SIMCONNECT_EXCEPTION_OBJECT_AI
#SIMCONNECT_EXCEPTION_OBJECT_ATC
#SIMCONNECT_EXCEPTION_OBJECT_SCHEDULE
EndEnumeration
; Object types
Enumeration SIMCONNECT_SIMOBJECT_TYPE
#SIMCONNECT_SIMOBJECT_TYPE_USER
#SIMCONNECT_SIMOBJECT_TYPE_ALL
#SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT
#SIMCONNECT_SIMOBJECT_TYPE_HELICOPTER
#SIMCONNECT_SIMOBJECT_TYPE_BOAT
#SIMCONNECT_SIMOBJECT_TYPE_GROUND
EndEnumeration
; EventState values
Enumeration SIMCONNECT_STATE
#SIMCONNECT_STATE_OFF
#SIMCONNECT_STATE_ON
EndEnumeration
; Object Data Request Period values
Enumeration SIMCONNECT_PERIOD
#SIMCONNECT_PERIOD_NEVER
#SIMCONNECT_PERIOD_ONCE
#SIMCONNECT_PERIOD_VISUAL_FRAME
#SIMCONNECT_PERIOD_SIM_FRAME
#SIMCONNECT_PERIOD_SECOND
EndEnumeration
; Missions
Enumeration SIMCONNECT_MISSION_END
#SIMCONNECT_MISSION_FAILED
#SIMCONNECT_MISSION_CRASHED
#SIMCONNECT_MISSION_SUCCEEDED
EndEnumeration
; ClientData Request Period values
Enumeration SIMCONNECT_CLIENT_DATA_PERIOD
#SIMCONNECT_CLIENT_DATA_PERIOD_NEVER
#SIMCONNECT_CLIENT_DATA_PERIOD_ONCE
#SIMCONNECT_CLIENT_DATA_PERIOD_VISUAL_FRAME
#SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET
#SIMCONNECT_CLIENT_DATA_PERIOD_SECOND
EndEnumeration
; Equates
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_VOR_FLAGS ; flags for SIMCONNECT_RECV_ID_VOR_LIST
#SIMCONNECT_RECV_ID_VOR_LIST_HAS_NAV_SIGNAL = $00000001 ; Has Nav signal
#SIMCONNECT_RECV_ID_VOR_LIST_HAS_LOCALIZER = $00000002 ; Has localizer
#SIMCONNECT_RECV_ID_VOR_LIST_HAS_GLIDE_SLOPE = $00000004 ; Has Nav signal
#SIMCONNECT_RECV_ID_VOR_LIST_HAS_DME = $00000008 ; Station has DME
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_EVENT_FLAG
#SIMCONNECT_EVENT_FLAG_DEFAULT = $00000000
#SIMCONNECT_EVENT_FLAG_FAST_REPEAT_TIMER = $00000001 ; set event repeat timer to simulate fast repeat
#SIMCONNECT_EVENT_FLAG_SLOW_REPEAT_TIMER = $00000002 ; set event repeat timer to simulate slow repeat
#SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY = $00000010 ; interpret GroupID parameter as priority value
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_DATA_REQUEST_FLAG
#SIMCONNECT_DATA_REQUEST_FLAG_DEFAULT = $00000000
#SIMCONNECT_DATA_REQUEST_FLAG_CHANGED = $00000001 ; send requested data when value(s) change
#SIMCONNECT_DATA_REQUEST_FLAG_TAGGED = $00000002 ; send requested data in tagged format
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_DATA_SET_FLAG
#SIMCONNECT_DATA_SET_FLAG_DEFAULT = $00000000
#SIMCONNECT_DATA_SET_FLAG_TAGGED = $00000001 ; data is in tagged format
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_CREATE_CLIENT_DATA_FLAG
#SIMCONNECT_CREATE_CLIENT_DATA_FLAG_DEFAULT = $00000000
#SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY = $00000001 ; permit only ClientData creator to write into ClientData
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_CLIENT_DATA_REQUEST_FLAG
#SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT = $00000000
#SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED = $00000001 ; send requested ClientData when value(s) change
#SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_TAGGED = $00000002 ; send requested ClientData in tagged format
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_CLIENT_DATA_SET_FLAG
#SIMCONNECT_CLIENT_DATA_SET_FLAG_DEFAULT = $00000000
#SIMCONNECT_CLIENT_DATA_SET_FLAG_TAGGED = $00000001 ; data is in tagged format
;SIMCONNECT_ENUM_FLAGS SIMCONNECT_VIEW_SYSTEM_EVENT_DATA ; dwData contains these flags for the "View" System Event
#SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_2D = $00000001 ; 2D Panels IN cockpit view
#SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_COCKPIT_VIRTUAL = $00000002 ; Virtual (3D) panels in cockpit view
#SIMCONNECT_VIEW_SYSTEM_EVENT_DATA_ORTHOGONAL = $00000004 ; Orthogonal (Map) view
;- Structures
; SIMCONNECT_REFSTRUCT SIMCONNECT_RECV
; {
; DWORD dwSize; // record size
; DWORD dwVersion; // interface version
; DWORD dwID; // see SIMCONNECT_RECV_ID
; };
Structure SIMCONNECT_RECV Align 1
dwSize.DWORD
dwVersion.DWORD
dwID.DWORD
EndStructure
; SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EXCEPTION : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_EXCEPTION
; {
; DWORD dwException; // see SIMCONNECT_EXCEPTION
; Static const DWORD UNKNOWN_SENDID = 0;
; DWORD dwSendID; // see SimConnect_GetLastSentPacketID
; Static const DWORD UNKNOWN_INDEX = DWORD_MAX;
; DWORD dwIndex; // index of parameter that was source of error
; };
Structure SIMCONNECT_RECV_EXCEPTION Extends SIMCONNECT_RECV Align 1
dwException.DWORD
dwSendID.DWORD
dwIndex.DWORD
EndStructure
; SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_OPEN : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_OPEN
; {
; SIMCONNECT_STRING( szApplicationName, 256);
; DWORD dwApplicationVersionMajor;
; DWORD dwApplicationVersionMinor;
; DWORD dwApplicationBuildMajor;
; DWORD dwApplicationBuildMinor;
; DWORD dwSimConnectVersionMajor;
; DWORD dwSimConnectVersionMinor;
; DWORD dwSimConnectBuildMajor;
; DWORD dwSimConnectBuildMinor;
; DWORD dwReserved1;
; DWORD dwReserved2;
; };
Structure SIMCONNECT_RECV_OPEN Extends SIMCONNECT_RECV Align 1
szApplicationName.a[256] ; Can't be read with a PeekS apparently...
dwApplicationVersionMajor.DWORD
dwApplicationVersionMinor.DWORD
dwApplicationBuildMajor.DWORD
dwApplicationBuildMinor.DWORD
dwSimConnectVersionMajor.DWORD
dwSimConnectVersionMinor.DWORD
dwSimConnectBuildMajor.DWORD
dwSimConnectBuildMinor.DWORD
dwReserved1.DWORD
dwReserved2.DWORD
EndStructure
; SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_EVENT : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_EVENT
; {
; Static const DWORD UNKNOWN_GROUP = DWORD_MAX;
; DWORD uGroupID;
; DWORD uEventID;
; DWORD dwData; // uEventID-dependent context
; };
Structure SIMCONNECT_RECV_EVENT Extends SIMCONNECT_RECV Align 1
uGroupID.DWORD
uEventID.DWORD
dwData.DWORD
EndStructure
; SIMCONNECT_REFSTRUCT SIMCONNECT_RECV_SIMOBJECT_DATA : public SIMCONNECT_RECV // when dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA
; {
; DWORD dwRequestID;
; DWORD dwObjectID;
; DWORD dwDefineID;
; DWORD dwFlags; // SIMCONNECT_DATA_REQUEST_FLAG
; DWORD dwentrynumber; // if multiple objects returned, this is number <entrynumber> out of <outof>.
; DWORD dwoutof; // note: starts with 1, not 0.
; DWORD dwDefineCount; // data count (number of datums, *not* byte count)
; SIMCONNECT_DATAV( dwData, dwDefineID, ); // data begins here, dwDefineCount data items
; };
Structure SIMCONNECT_RECV_SIMOBJECT_DATA Extends SIMCONNECT_RECV Align 1
dwRequestID.DWORD
dwObjectID.DWORD
dwDefineID.DWORD
dwFlags.DWORD
dwentrynumber.DWORD
dwoutof.DWORD
dwDefineCount.DWORD
dwData.DWORD
EndStructure
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
; Simmconect lib path.
CompilerIf Not Defined(SIMCONNECT_LIB_PATH, #PB_Constant)
#SIMCONNECT_LIB_PATH = "SimConnect.lib"
CompilerEndIf
;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Import #SIMCONNECT_LIB_PATH
SimConnect_Open(*hSimConnect, szName.s, hWnd.HWND, UserEventWin32.DWORD, hEventHandle.HANDLE, ConfigIndex.DWORD)
SimConnect_AddToDataDefinition(hSimConnect.HANDLE, DefineID.SIMCONNECT_DATA_DEFINITION_ID, *DatumName, *UnitsName, DatumType.SIMCONNECT_DATATYPE_TYPE = #SIMCONNECT_DATATYPE_FLOAT64, fEpsilon.f = 0, DatumID.DWORD = #SIMCONNECT_UNUSED)
SimConnect_RequestDataOnSimObject(hSimConnect.HANDLE, Request.DWORD, DefineID.SIMCONNECT_DATA_DEFINITION_ID, Period.DWORD, Flags.DWORD);
SimConnect_GetNextDispatch(hSimConnect.HANDLE, *pData.SIMCONNECT_RECV, DWORD);
SimConnect_Close(hSimConnect.HANDLE)
; SimConnect.h Prototypes:
; SimConnect_Open(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex);
; SimConnect_AddToDataDefinition(HANDLE hSimConnect, SIMCONNECT_DATA_DEFINITION_ID DefineID, const char * DatumName, const char * UnitsName, SIMCONNECT_DATATYPE DatumType = SIMCONNECT_DATATYPE_FLOAT64, float fEpsilon = 0, DWORD DatumID = SIMCONNECT_UNUSED);
; SimConnect_RequestDataOnSimObject(HANDLE hSimConnect, SIMCONNECT_DATA_REQUEST_ID RequestID, SIMCONNECT_DATA_DEFINITION_ID DefineID, +
; SIMCONNECT_OBJECT_ID ObjectID, +
; SIMCONNECT_PERIOD Period, +
; SIMCONNECT_DATA_REQUEST_FLAG Flags = 0);
; SimConnect_GetNextDispatch(HANDLE hSimConnect, SIMCONNECT_RECV ** ppData, DWORD * pcbData);
; SimConnect_Close(HANDLE hSimConnect);
EndImport
Code: Select all
EnableExplicit
XIncludeFile "SimConnect.pbi"
;//////////////////////////////////////////////////////////////////////////////////////////////////////
Define hSimConnect.HANDLE = #Null
Define hr.HRESULT
Enumeration Data_Define_ID
#Data_Defination
EndEnumeration
Enumeration Data_Request_ID
#Data_Request
EndEnumeration
Structure MSFS_Data Align 1
IALT.d
EndStructure
Global MSFS.MSFS_Data
Define pData.SIMCONNECT_RECV
Define cbData = #Null
;//////////////////////////////////////////////////////////////////////////////////////////////////////
Enumeration
#WIN
#TIMER
#IALT
EndEnumeration
Define Done
Define Event
;//////////////////////////////////////////////////////////////////////////////////////////////////////
hr = SimConnect_Open(@hSimConnect, "MSFS 2020", #Null, 0, 0, #SIMCONNECT_OPEN_CONFIGINDEX_LOCAL)
If hr <> 0
Debug "Open Error: " + Str(hr)
End
EndIf
hr = SimConnect_AddToDataDefinition(hSimConnect.HANDLE, #Data_Defination, "INDICATED ALTITUDE", "Feet")
If hr <> 0
Debug "Add Definition Error: " + Str(hr)
End
EndIf
hr = SimConnect_RequestDataOnSimObject(hSimConnect, #Data_Request, #Data_Defination, 0, #SIMCONNECT_PERIOD_VISUAL_FRAME);
If hr <> 0
Debug "Request Data Error: " + Str(hr)
End
EndIf
;////////////////////////////////////////////////////////////////////
;//// Errors out here... Pointer, to a pointer, to a pointer, yuck...
;////////////////////////////////////////////////////////////////////
; C++: SimConnect_GetNextDispatch(HANDLE hSimConnect, SIMCONNECT_RECV ** ppData, DWORD * pcbData);
hr = SimConnect_GetNextDispatch(hSimConnect, @pData, @cbData)
If hr <> 0
Debug "GetNext Disptach Error: " + Str(hr) ; -2147467259: Error
End
EndIf
OpenWindow(0, 5500, 1000, 195, 260, "MSFS 2020", #PB_Window_SystemMenu)
AddWindowTimer(#WIN,#TIMER ,15)
TextGadget(#IALT, 23, 42, 100, 25, "")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Done = #True
Case #PB_Event_Timer
If EventTimer() = #TIMER
;/////////////////////////////////////////////////////////////////
;/// I have no idea how to assign this, from c++ to PB:
;/////////////////////////////////////////////////////////////////
; pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
; If (pData->dwID == SIMCONNECT_RECV_ID_SIMOBJECT_DATA && pObjData->dwRequestID == REQUEST_AP_SETTINGS)
; {
; pAutopilotData = (AutopilotData*)&pObjData->dwData;
If @pData\dwID = #Data_Request
MSFS\iALT = *pData.\dwData ;This needs to be set correctly. It compiles...
SetGadgetText(#IALT,Str(MSFS\IALT))
EndIf
EndIf
EndSelect
Until Done = #True
CloseWindow(#WIN)
SimConnect_Close(hSimConnect)
https://drive.google.com/file/d/16wEBks ... sp=sharing
Re: MSFS SimConnect...
I did not jumped in, because I have no way to test it.
And I'm not willing to buy or install MS FS.
Is there an other way to 'connect' to a MS FS without having one running?
And I'm not willing to buy or install MS FS.
Is there an other way to 'connect' to a MS FS without having one running?
Re: MSFS SimConnect...
Hi Infratec,
Thanks for the reply, Mate!
I am not aware of a way for you to test a compiled PB program, calling a fictitious instance of SimConnect.
I am sorry I cannot provide you with a solution that would test the output of the final TextGadget. But I can test it. Once we get this working I want to post the code here for others to use in any project they like.
Eventually, I want to create the code to post data into SimConnect. But this get-code should be simpler to accomplish first. One step at a time.
The two lines of code that I commented on in the GetData.pb file are the two lines that need to be looked at.
This:
hr = SimConnect_GetNextDispatch(hSimConnect, @pData, @cbData)
The addresses of pData and/or cbData is not properly prototyped.
And this:
MSFS\iALT = *pData.\dwData
No clue. At one point I had it compiling but it appears to be a pointer to an address and not real data.
Thanks for looking at this if you can. I just need a much more experienced set of eyes and mind, like yours, to compile those structures properly.
Thanks for the reply, Mate!
I am not aware of a way for you to test a compiled PB program, calling a fictitious instance of SimConnect.
I am sorry I cannot provide you with a solution that would test the output of the final TextGadget. But I can test it. Once we get this working I want to post the code here for others to use in any project they like.
Eventually, I want to create the code to post data into SimConnect. But this get-code should be simpler to accomplish first. One step at a time.
The two lines of code that I commented on in the GetData.pb file are the two lines that need to be looked at.
This:
hr = SimConnect_GetNextDispatch(hSimConnect, @pData, @cbData)
The addresses of pData and/or cbData is not properly prototyped.
And this:
MSFS\iALT = *pData.\dwData
No clue. At one point I had it compiling but it appears to be a pointer to an address and not real data.
Thanks for looking at this if you can. I just need a much more experienced set of eyes and mind, like yours, to compile those structures properly.
Re: MSFS SimConnect...
You can try this:
Maybe you can try to change it later to p-unicode.
And
Code: Select all
SimConnect_Open(*hSimConnect, szName.p-ascii, hWnd.HWND, UserEventWin32.DWORD, hEventHandle.HANDLE, ConfigIndex.DWORD)
SimConnect_AddToDataDefinition(hSimConnect.HANDLE, DefineID.SIMCONNECT_DATA_DEFINITION_ID, DatumName.p-ascii, UnitsName.p-ascii, DatumType.SIMCONNECT_DATATYPE_TYPE = #SIMCONNECT_DATATYPE_FLOAT64, fEpsilon.f = 0, DatumID.DWORD = #SIMCONNECT_UNUSED)
SimConnect_RequestDataOnSimObject(hSimConnect.HANDLE, Request.DWORD, DefineID.SIMCONNECT_DATA_DEFINITION_ID, Period.DWORD, Flags.DWORD);
SimConnect_GetNextDispatch(hSimConnect.HANDLE, *pData.SIMCONNECT_RECV, DWORD);
SimConnect_Close(hSimConnect.HANDLE)
And
Code: Select all
EnableExplicit
XIncludeFile "SimConnect.pbi"
Enumeration Data_Define_ID
#Data_Definition
EndEnumeration
Enumeration Data_Request_ID
#Data_Request
EndEnumeration
Enumeration
#WIN
#TIMER
#IALT
EndEnumeration
Structure MSFS_Data Align 1
IALT.d
EndStructure
Define MSFS.MSFS_Data
Define hSimConnect.HANDLE
Define hr.HRESULT
Define *pData.SIMCONNECT_RECV
Define cbData.l
Define *pObjData.SIMCONNECT_RECV_SIMOBJECT_DATA
Define.i Done, Event
; Debug @SimConnect_Open()
; Debug @SimConnect_AddToDataDefinition()
; Debug @SimConnect_RequestDataOnSimObject()
; Debug @SimConnect_GetNextDispatch()
hr = SimConnect_Open(@hSimConnect, "MSFS 2020", #Null, 0, 0, #SIMCONNECT_OPEN_CONFIGINDEX_LOCAL)
If hr <> #S_OK
Debug "Open Error: " + Hex(hr)
End
EndIf
hr = SimConnect_AddToDataDefinition(hSimConnect, #Data_Definition, "INDICATED ALTITUDE", "Feet")
If hr <> #S_OK
Debug "Add Definition Error: " + Hex(hr)
End
EndIf
hr = SimConnect_RequestDataOnSimObject(hSimConnect, #Data_Request, #Data_Definition, #SIMCONNECT_OBJECT_ID_USER, #SIMCONNECT_PERIOD_VISUAL_FRAME)
If hr <> #S_OK
Debug "Request Data Error: " + Hex(hr)
End
EndIf
hr = SimConnect_GetNextDispatch(hSimConnect, @*pData, @cbData)
If hr <> #S_OK
Debug "GetNext Disptach Error: " + Hex(hr)
End
EndIf
Debug *pData
Debug cbData
OpenWindow(0, 5500, 1000, 195, 260, "MSFS 2020", #PB_Window_SystemMenu)
AddWindowTimer(#WIN,#TIMER ,15)
TextGadget(#IALT, 23, 42, 100, 25, "")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Done = #True
Case #PB_Event_Timer
If EventTimer() = #TIMER
*pObjData = *pData
If *pData\dwID = #SIMCONNECT_RECV_ID_SIMOBJECT_DATA And *pObjData\dwRequestID = #Data_Request
MSFS\iALT = *pObjData\dwData ;This needs to be set correctly. It compiles...
SetGadgetText(#IALT,Str(MSFS\IALT))
EndIf
EndIf
EndSelect
Until Done = #True
CloseWindow(#WIN)
SimConnect_Close(hSimConnect)
Last edited by infratec on Fri Apr 23, 2021 3:26 pm, edited 1 time in total.
Re: MSFS SimConnect...
Thank you for your help, Infratec!
I think we are close, but the GetNextDispatch has errored out. Here is a screen print of the code, with the program running and the debug window on top:
https://drive.google.com/file/d/1O3_79_ ... sp=sharing
That's a brilliant idea of debugging the addresses of the procedure calls. I am not sure why you are doing that. I will read up on that. You have your reasons. Checking to see if the SimConnect.dll has those procedures in it?
Pay close attention to the GetNextDispatch prototype in SimConnect.pbi, please. I may have set it wrong versus the c++ prototype. pcbData/cbData?
c++: SimConnect_GetNextDispatch(HANDLE hSimConnect, SIMCONNECT_RECV ** ppData, DWORD * pcbData);
Once we have this bad-boy working I plan on saving it, then re-wording the variables to something that makes more sense for all to read. I detest the way that c++ names everything so verbosely.
I think we are close, but the GetNextDispatch has errored out. Here is a screen print of the code, with the program running and the debug window on top:
https://drive.google.com/file/d/1O3_79_ ... sp=sharing
That's a brilliant idea of debugging the addresses of the procedure calls. I am not sure why you are doing that. I will read up on that. You have your reasons. Checking to see if the SimConnect.dll has those procedures in it?
Pay close attention to the GetNextDispatch prototype in SimConnect.pbi, please. I may have set it wrong versus the c++ prototype. pcbData/cbData?
c++: SimConnect_GetNextDispatch(HANDLE hSimConnect, SIMCONNECT_RECV ** ppData, DWORD * pcbData);
Once we have this bad-boy working I plan on saving it, then re-wording the variables to something that makes more sense for all to read. I detest the way that c++ names everything so verbosely.
Re: MSFS SimConnect...
I slightly changed my code above.
But since the parameters of SimConnect_GetNextDispatch() are only pointers, there can nothing fail.
The failure is before.
The function returns a pointer to a buffer and the length of it.
What does work: p-asci or p-unicode?
But since the parameters of SimConnect_GetNextDispatch() are only pointers, there can nothing fail.
The failure is before.
The function returns a pointer to a buffer and the length of it.
What does work: p-asci or p-unicode?
Re: MSFS SimConnect...
Sorry for the delay. I am working on a honey-do outside.
I added three Debug Hex(hr) after each procedure to see what hr was always returning. It still has an error after the third procedure call:
SimConnect_GetNextDispatch(hSimConnect, @*pData, @cbData) call.
Screenprint of main code with debugger:
https://drive.google.com/file/d/1huEd9f ... sp=sharing
I tried setting the three variables in the prototypes in SimConnect.pbi to either p-unicode or p-ascii and it did not make any difference. Screenprint of the code you sent me with other code commented out:
https://drive.google.com/file/d/1dXXvoz ... sp=sharing
I added three Debug Hex(hr) after each procedure to see what hr was always returning. It still has an error after the third procedure call:
SimConnect_GetNextDispatch(hSimConnect, @*pData, @cbData) call.
Screenprint of main code with debugger:
https://drive.google.com/file/d/1huEd9f ... sp=sharing
I tried setting the three variables in the prototypes in SimConnect.pbi to either p-unicode or p-ascii and it did not make any difference. Screenprint of the code you sent me with other code commented out:
https://drive.google.com/file/d/1dXXvoz ... sp=sharing