• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Getting payload station weights

DragonflightDesign

Resource contributor
Messages
1,368
Country
northernireland
I'm being unkind to SimConnect again and it's repaying me with an exception 3: 'The client event, request ID, data definition ID, or object ID was not recognized.'

What I'm trying to do is get the payload station weights from an aircraft. Getting the number of payload stations is easy, but of course, it's an unknown quantity at runtime. So, what I have, looks like this. It's vb.Net but I'll accept any help in C# too :)
Code:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)>
    Structure PayloadStations

        Public station_weights() As Double

    End Structure

Code:
Enum P3Data
  REQUEST_PAYLOAD
    DEFINE_PAYLOAD
End Enum

Code:
' Build the data definition - don't forget payload station enumeration starts from one
For i = 1 To nPayloadStations
  dataRequest = "PAYLOAD STATION WEIGHT:" & i.ToString
    p3d_simconnect.AddToDataDefinition(P3Data.REQUEST_PAYLOAD, dataRequest, "pounds",SIMCONNECT_DATATYPE.FLOAT64, 0, 1500 + i)
Next

' Now request the payload station weights once only
p3d_simconnect.RequestDataOnSimObject(P3Data.REQUEST_PAYLOAD, P3Data.DEFINE_PAYLOAD, SIMCONNECT_SIMOBJECT_TYPE.USER, SIMCONNECT_PERIOD.ONCE, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0)
My starting point was this thread:
As soon as my code exits the function it is in (a button click) I get the exception.
 
I don't use C.DULL... but... I have an aircraft that obtains all of the payloads via SimConnect...

First, I had to do this:
Code:
simConnect->AddToDataDefinition( 0, "PAYLOAD STATION WEIGHT:1", "Pounds", SIMCONNECT_DATATYPE_FLOAT64, 0);
Second I had to do this:
Code:
simConnect->AddToDataDefinition(DATA_DEFINE_WEIGHT_BALANCE, "PAYLOAD STATION WEIGHT:1", "Pounds", SIMCONNECT_DATATYPE_FLOAT64, 0);
Then I did this:
Code:
simConnect->RequestDataOnSimObject( DATA_REQUEST_WEIGHT_BALANCE, DATA_DEFINE_WEIGHT_BALANCE,SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SIM_FRAME, 0);

The data will get returned as an array of double values.
 
Code:
RequestDataOnSimObject
That's interesting. Thanks Ed - I'll give that a try when I have time and get back to the thread.
 
The data will get returned as an array of double values.
Okay... it looks like that's the problem. In C you can declare an unsized array as in
Code:
// data struct
struct StationData
{
    float stations[];
};
vb.Net, bless its little cotton (Christmas) socks, will allow you to define an unsized array within the struct as in
Code:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)>
    Structure PayloadData
        Public payloadStations() As Double
    End Structure
but requires you to define the size of the array before you can use it. Unfortunately...

you can't define the size of an array inside a structure definition and to define it later, you need to make a copy
Code:
Dim payloadData2 as payloadData
Redim payloadData2.payloadStations(numStations)
...at which point SimConnect can no longer see it and you can't register it because it's not part of the original class. Using
Code:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)>
    Structure PayloadData
        Public payloadStations As List(Of Double)
    End Structure
doesn't work either because SimConnect doesn't know which list items to stuff its data in.


Bollox.


It's beginning to look very much like an incomplete port from C to vb.Net. I would like to say 'there has to be a solution to this' but I'm beginning to very much doubt it.

Well, there is a solution and that's to take the route of the previous thread poster and stuff an unfeasibly high number of payload stations in the struct, ignore station0 and stop checking for data after numStations is reached. Bleugh!!!!:banghead:

Oh - and the original expection was caused by the idiot behind this keyboard trying to build the same data definition every time the code passed through that part of the module. Absolutely not clever... :rolleyes:
 
Last edited:
Or stop using a language that still hasn't caught up with modern times. Just sayin...
 
My problem is that I never learned to build GUIs using MFC. I do have a copy of Petzold here but it's never been opened. Not enough time...

This: "It's beginning to look very much like an incomplete port from C to vb.Net " should really have said "It's beginning to look very much like an incomplete port from C to dotNet on Lockheed-Martin's side" rather than just blaming the vb side of it. I've seen a similar problem before; reported it and it was fixed (eventually).
 
Last edited:
The problem is that the station count is completely variable. You just can't hard code that.
 
No problem :). Place the data into your unfeasibly large structure, get 'PAYLOAD STATION COUNT', use that to loop through the required data and discard the rest. Works perfectly. I am going to publish the code, either as part of sd2gau or as a standalone in the Wiki. It was such a PITA to get it to work that it's pointless keeping the solution to myself.
 
Last edited:
Back
Top