reading data in multiple .xaml files in WPF

ppp333ddd_
Posts: 26
Joined: Fri Aug 18, 2017 1:04 am

reading data in multiple .xaml files in WPF

Postby ppp333ddd_ » Tue Sep 12, 2017 5:09 am

Hi,

In my project, the WPF interface contains many .xaml user controls (or you can call them subwindows). Therefore, I need to read data from P3D in multiple .xaml files at the same time.

I found that using only one SimConnect object is not enough for this (If one object is enough, please tell me how to do it). So I am tring to use 2 SimConnect objects for 2 .xaml files' data reading. I created a new SimConnect object and imitate everything from the codes for successful data reading. However, the struct I defined returns NULL value in function RecieveSimObjectGeneralQuery_ATCL as shown below.

internal struct SimObjectGeneral
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]

/* 2.declare parameters in SimObjectGeneral */
public string Title;

public Int32 IAS;
public Int32 CAS;
public Int32 GROSSWEIGHT;
... ...
}


internal struct SimObjectGeneral_ATCL
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]

/* 2.declare parameters in SimObjectGeneral */
public Int32 Altitude;
}

private void RecieveSimObjectGeneralQuery(SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
{
SimObjectGeneral? simObjectGeneral= data.dwData[0] as SimObjectGeneral_?;//it works
}

private void RecieveSimObjectGeneralQuery_ATCL(SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
{
SimObjectGeneral_ATCL? simObjectGeneral_ATCL = data.dwData[0] as
SimObjectGeneral_ATCL?;//it returns null value, why?
}

Can anyone helps? Thanks a lot!

Jeff

Clifton Crane
Lockheed Martin
Posts: 726
Joined: Tue Sep 25, 2012 2:34 pm

Re: reading data in multiple .xaml files in WPF

Postby Clifton Crane » Wed Sep 13, 2017 6:52 pm

Hi Jeff,

Are you passing the two separate window handles into the individual SimConnect constructors?

Thanks.
Clifton Crane
Prepar3D® Software Engineer

ppp333ddd_
Posts: 26
Joined: Fri Aug 18, 2017 1:04 am

Re: reading data in multiple .xaml files in WPF

Postby ppp333ddd_ » Thu Sep 14, 2017 2:54 am

Hi Clifton,

I created multiple handlers and used different handler in different constructors in DataModel.cs. And now I have changed the formal parameter of the constructor into UserControl(SubWindow) instead of Window(MainWindow).

I also created a function Connect_ATCL which is similar to function Connect. In this function, when creating a new SimConnect object, the data reading in another .xaml UI will be disabled, as shown below:

this.sim_ATCL = new SimConnect("Managed Simconnect Request", Handle_2, WM_USER_SIMCONNECT, null, 0);//This disables data reading in another UI. Why???

Can you see where is the collision here? Many thanks!

Best regards,
Jeff


Return to “SimConnect Interface Questions”

Who is online

Users browsing this forum: No registered users and 2 guests