Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,

Problem:

Writing an offset using SetValue() method ignores the value passed in as parameter.

Consider this code:

 

var thrustInput1Offset = new Offset<short>(0x089A, true); //write
				int value3 = 9000;
				var convertedValue = Convert.ChangeType(value3, typeof(short));
				thrustInput1Offset.SetValue(convertedValue); // <= The internal value of the offset is not changed after this call
				FSUIPCConnection.Process();

 

Posted

Hi,

The SetValue() and GetValue() methods should not be visible when using the Offset<> class. It's an oversight on my part.

If you're using the strong-typing class like Offset<short> you should be setting the value with 

thrustInput1Offset.Value = convertedValue;

I'll hide these two methods in the next release.

Paul

Posted

The SetValue() and GetValue() methods should not be visible when using the Offset<> class. " - No, the design is fine. I need to use Offsets polymorphically, therefore, just fix the methods, don't change the design.

Posted

The original design was that if you need polymorphism then you use the Offset base class directly, without the strong-typing like this:

            var thrustInput1Offset = new Offset(0x089A, 2, true); // Untyped offset - Must always set the length
            int value3 = 9000;
            var convertedValue = Convert.ChangeType(value3, typeof(short));
            thrustInput1Offset.SetValue(convertedValue); 
            FSUIPCConnection.Process();
            // Read like this...
            short readValue = thrustInput1Offset.GetValue<short>();
            // or like this...
            short readValue2 = (short)thrustInput1Offset.GetValue(typeof(short));

However, I've now overridden SetValue() and GetValue() in the strongly-typed Offset<> class to handle the extra stuff that's needed for Offset<>. Both methods should now work with the Offset<> class.

There is a new preview release on NuGet 3.2.22-beta2. Check the [include pre-release] box to see it,

Paul

Posted

Excellent, thank you.

"thrustInput1Offset.GetValue<short>();" - This is still using static typing so it is limited in use, ... The static typing is an issue when you are setting the value SetValue<short>(). For GetValue it usually doesn't matter because you have to cast the returned value back to specific data type unless you are displaying it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.