Page 1 of 1

reading data in multiple .xaml files in WPF

Posted: Tue Sep 12, 2017 5:09 am
by ppp333ddd_
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

Re: reading data in multiple .xaml files in WPF

Posted: Wed Sep 13, 2017 6:52 pm
by Clifton Crane
Hi Jeff,

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

Thanks.

Re: reading data in multiple .xaml files in WPF

Posted: Thu Sep 14, 2017 2:54 am
by ppp333ddd_
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