Crazy number outputs from simconnect, not sure where to start.

Discuss on the SimConnect SDK can be used by programmers to write add-on components for Prepar3D
Locked
haroldFDavidson
Posts: 9
Joined: Thu Jun 01, 2017 12:24 am

Crazy number outputs from simconnect, not sure where to start.

Post by haroldFDavidson »

Hi, i'm working on some external gauges for Prepar3d, and i can't understand some of the values that Simconnect is outputting.
One of them is the ELECTRICAL BATTERY VOLTAGE Simulation variable, which seems to dart around numbers like 3.058675e+28, and other times it just outputs NaN. The variables unit is Volts, so obviously this number is incorrect.

Wondering if anyone has any insight into this,
Thanks
JB3DG
Posts: 609
Joined: Mon Jan 09, 2012 6:44 pm

Re: Crazy number outputs from simconnect, not sure where to start.

Post by JB3DG »

What do your structs look like? Are all the variables in them doubles?
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun
haroldFDavidson
Posts: 9
Joined: Thu Jun 01, 2017 12:24 am

Re: Crazy number outputs from simconnect, not sure where to start.

Post by haroldFDavidson »

Here is the Struct Definition:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct Struct1
{
public float voltage;
public float ampPercent;
};

Here is the data going into the Struct:

simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ELECTRICAL BATTERY VOLTAGE", "Volts", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ELECTRICAL BATTERY BUS AMPS", "Amperes", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED); [/code]


The variables are using floats, as there was not supposed to be anything over 1000, and presumed that there would not be any floating point data loss.

Is there a different reason I should consider Doubles here? This program will run in Realtime, so speed is important.
Thanks,
User avatar
WarpD
Posts: 1469
Joined: Mon Feb 14, 2011 5:29 am

Re: Crazy number outputs from simconnect, not sure where to start.

Post by WarpD »

You absolutely must use doubles.... all variables returned are doubles, no matter their possible range.

Size of the variable cannot possibly impact performance.
Ed Wilson
Senior Developer
Mindstar Aviation
haroldFDavidson
Posts: 9
Joined: Thu Jun 01, 2017 12:24 am

Re: Crazy number outputs from simconnect, not sure where to start.

Post by haroldFDavidson »

Okay thanks for that..

I have converted to software to use Doubles, and the same issue persists.
I'm just going to put it down to the flight models i'm testing with (which all seem inconsistent in the variables that they output)

Thanks all for the advice.
JB3DG
Posts: 609
Joined: Mon Jan 09, 2012 6:44 pm

Re: Crazy number outputs from simconnect, not sure where to start.

Post by JB3DG »

Would be helpful to see your code since the changes
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun
Locked