activex Posted October 6, 2022 Report Posted October 6, 2022 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();
Paul Henty Posted October 6, 2022 Report Posted October 6, 2022 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
activex Posted October 6, 2022 Author Report Posted October 6, 2022 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.
Paul Henty Posted October 6, 2022 Report Posted October 6, 2022 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
activex Posted October 6, 2022 Author Report Posted October 6, 2022 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now