Visit Captain Sim web site  
  Welcome, Guest. Please Login or Register

 

Page Index Toggle Pages: 1 2 [3]  Send TopicPrint
 25 SDK (Read 8737 times)
Edo
Full Member
*
Offline



Posts: 7
Location: Milano, Italy
Joined: Apr 21st, 2020
Gender: Male
Re: SDK
Reply #30 - Dec 7th, 2020 at 2:39pm
Print Post  
Hello, I was tryin to read Lua events for the Eicas and ADI display but looks like no data is available out of those...can you confirm?
  
Back to top
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
SimConnect C++ and CS767 LVARS...
Reply #31 - Mar 19th, 2021 at 3:18am
Print Post  
Does anyone have any experience writing a C++ or C# application that uses SimConnect.  Specifically, I am writing an application that needs to R/W the CS767 LVARS for my home cockpit.  See other post recently here by me - I am subscribing to SIOC events (for my OpenCockpits hardware) and need to sync button presses etc in my hardware to the SIM.  Additionally, I will need to read values from CS767 LVARS to update my various LEDs etc.  Any advice would be greatly appreciated.
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #32 - Mar 19th, 2021 at 8:58pm
Print Post  
I am aware how to create individual LUA scripts for each LVAR that I wish to set, however, since I have a opencockpits program I am writing to get the state of all of my various switches, buttons, etc, I would like to set those LVARS from in that same program as doing all kinds of LUA mini scripts is cumbersome and wouldn't be tied to my actual hardware.
Perhaps the CaptaimSim folk can do a short description of how to access LVARS ???
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: 767 - SDK - Scripting Issues FSX / Mobiflight
Reply #33 - Mar 19th, 2021 at 10:06pm
Print Post  
flyingjayaraj wrote on Aug 17th, 2020 at 7:43pm:
Hello everone, i am stuck at a point where i am unable to program my MCP, due to limited knowledge in coding and deciphering the 757/767 SDK.

CS-767 & 757 - FSX - FSUIPC - Mobiflight

To increase or decrease the airspeed value - i followed the instructions from the SDK

I created a lua file - CS757SPEEDDEC.LUA

ipc.writeLvar(“L:klid",-1703010)

and another - CS757SPEEDINC.LUA

ipc.writeLvar(“L:klid", 1703010)

These lua files now show up in my FSUIPC list.

Now the next step is to add an entry to auto-run the lua, i have made that entry too.

[Auto]
1=Lua CS757SPEEDINC
2=Lua CS757SPEEDDEC

Now in the macro file, what is the entry that i have to have ?
i tried different entry but none seem to work.

Could anyone please share some script that has worked ? or the steps, assigning the ID to a variable has got me stuck for weeks now, been searching for the forms but unable to find any definite answer.  Cry


I have not yet tried this myself, but it looks like you are missing a trigger to cause these events to happen.  You would need to map a joystick button or keypress to trigger one of these LUA scripts to execute.  I have seen a decent YouTube video to explain this step (https://www.youtube.com/watch?v=mOO32FiMNS0).  Hopefully that helps.
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #34 - Mar 19th, 2021 at 10:13pm
Print Post  
You could also look at this video as well...
https://youtu.be/_NVpSf4SZJM

He also shows a section in FSUIPC.ini called [LuaFiles] that you may need to add (in addition to your Lua entries in [Auto]) if you are saving FSUIPC macros that call on the scripts.

  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #35 - Mar 19th, 2021 at 10:17pm
Print Post  
Captain Sim wrote on Jun 4th, 2020 at 2:55pm:
Kees wrote on Jun 3rd, 2020 at 8:45pm:
I hope you will reconsider this option.

Well, you are asking us to re-build the entire 767 code from scratch (which is years of work) just to make it fit better one particular homepit needs.
The answer is no, sorry.


So, I suspect that the main need isn't to necessarily write those values directly, but instead get a fast performance so that rotary inputs can change values quickly.  I haven't gotten to actually try this out yet (hopefully this weekend), but I wonder if the slow response is because it is calling LUA scripts to access LVARS as opposed to a more performant environment like C++/SimConnect.  Anyway, I do not know how to access LVARS outsite of a Lua script (yet), but hopefully there is a way...
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SimConnect C++ and CS767 LVARS...
Reply #36 - Mar 19th, 2021 at 10:33pm
Print Post  
Dave Snyder WI wrote on Mar 19th, 2021 at 3:18am:
Does anyone have any experience writing a C++ or C# application that uses SimConnect.  Specifically, I am writing an application that needs to R/W the CS767 LVARS for my home cockpit.  See other post recently here by me - I am subscribing to SIOC events (for my OpenCockpits hardware) and need to sync button presses etc in my hardware to the SIM.  Additionally, I will need to read values from CS767 LVARS to update my various LEDs etc.  Any advice would be greatly appreciated.


Found a great video on YouTube () that I think gets me very close...

I'll paste in the code that looks to at least get the built-in variables for generic aircraft, just not quite sure how to change the request for LVARS - I wonder if it is simple as putting in the klid number instead of the #define of the variable?

#include <windows.h>
#include <iostream>
#include "SimConnect.h"

int quit = 0;
HANDLE hSimConnect = NULL;

static enum DATA_DEFINE_ID {
     DEFINITION_1,
};

static enum DATA_REQUEST_ID {
     REQUEST_1,
     REQUEST_2,
};

struct SimResponse {
     double altitude;
     int32_t heading;
     int32_t speed;
     int32_t vertical_speed;
};

void CALLBACK MyDispatchProc1(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) {
     switch (pData->dwID)
     {

     case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
     {
           SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;

           switch (pObjData->dwRequestID)
           {
           case REQUEST_1:

                 SimResponse* pS = (SimResponse*)&pObjData->dwData;

                 std::cout
                       
                       << "\rAltitude: " << pS->altitude
                       << " - Heading: " << pS->heading
                       << " - Speed (knots): " << pS->speed
                       << " - Vertical Speed: " << pS->vertical_speed
                       
                       << std::flush;

                 break;
           }
           break;
     }

     case SIMCONNECT_RECV_ID_QUIT:
     {
           quit = 1;
           break;
     }

     default:
           break;
     }
}

bool initSimEvents() {
     HRESULT hr;

     if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Client Event Demo", NULL, 0, NULL, 0))) {
           std::cout << "\nConnected To Microsoft Flight Simulator 2020!\n";

           // DATA
           hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Indicated Altitude", "feet");
           hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "HEADING INDICATOR", "degrees", SIMCONNECT_DATATYPE_INT32);
           hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Airspeed Indicated", "knots", SIMCONNECT_DATATYPE_INT32);
           hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "VERTICAL SPEED", "Feet per second", SIMCONNECT_DATATYPE_INT32);

           // EVERY SECOND REQUEST DATA FOR DEFINITION 1 ON THE CURRENT USER AIRCRAFT (SIMCONNECT_OBJECT_ID_USER)
           hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_1, DEFINITION_1, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND);

           // Process incoming SimConnect Server messages
           while (quit == 0) {
                 // Continuously call SimConnect_CallDispatch until quit - MyDispatchProc1 will handle simulation events
                 SimConnect_CallDispatch(hSimConnect, MyDispatchProc1, NULL);
                 Sleep(1);
           }

           hr = SimConnect_Close(hSimConnect);
           return true;
     }
     else {
           std::cout << "\nFailed to Connect!!!!\n";
           return false;
     }
}

int main() {
     initSimEvents();
     return 0;
}


For example, in the code above, I could try replacing "HEADING INDICATOR" with the numeric klid?

Anyone know?  I'll code this up this weekend and find out...

  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #37 - Mar 19th, 2021 at 10:35pm
Print Post  
Oops - forgot to post the YouTube link - https://www.youtube.com/watch?v=M9dWihPtkrQ

The person who did the video wrote the above code.
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #38 - Mar 19th, 2021 at 10:48pm
Print Post  
Ugh - digging further, it seems this might now work for LVARS as those would only be accessible in-proc (and not from separate process of P3D).  Other sites have discussed making a custom C/C++ gauge control and that seems to be able to access LVARS.  Anyway, just putting this info out here for the future when someone will be able to answer...
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK (LVARS and C/C++)
Reply #39 - Apr 14th, 2021 at 2:00am
Print Post  
BUMP! - Does anyone on the CaptainSim team actually know how to access LVARS via C/C++ or SimConnect???  Seems like someone should know how to interact with these outside the LUA script method...
  
Back to top
 
IP Logged
 
Dave Snyder WI
Full Member
*
Offline



Posts: 34
Joined: May 22nd, 2020
Re: SDK
Reply #40 - Aug 6th, 2021 at 3:06pm
Print Post  
One more bump...

Anyone out there interested in trying to solve this?  I have a full-size 767 cockpit that I am desperately trying to port over from LD767 and FSX to P3D CS767 and need this functionality.

Summary: Need a C++ way to Read/Write CS767 LVARS.

Specifically, It looks like I need to build a custom gauge DLL (that is in-proc w/ P3D) that can r/w the LVARS in CS767 and then does an IPC (maybe socket) to a module that can talk via SimConnect or FSUIPC and my OpenCockpits Modules.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 
Send TopicPrint
 
  « Board Index ‹ Board  ^Top