1) Correct.
I tested this solution (replace the last line of the function):
try
{
return new DateTime(Year, Month, Day, Hour, Min, Sec);
}
catch (System.ArgumentOutOfRangeException)
{
return new DateTime(0);
}
2) I'm working on the massive test/compilation of 1.3.0 release that is coming out.
If I find 5 min of free time I will implement it, or, if you have a snippet feel free to post it ;)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Davide,
The following line in snap7.net.cs (1.3.0.0):
this.pData = handle.AddrOfPinnedObject() + Offset * Marshal.SizeOf(typeof(T));
fails on my VisualStudio.
should be:
this.pData = (IntPtr)(handle.AddrOfPinnedObject().ToInt32() + Offset * Marshal.SizeOf(typeof(T)));
I just re-tested it with VS2012 and VS2013 without errors trying debug/release/x86/x64/anycpu.
What release are you using ?
And, are you completely sure that "ToInt32" is good enough also for x64 systems ?
Humm. I'm using VS2008 x86 and tested also with anycpu.
Attached error.
Maybe testing Inptr.Size to convert correctly (I think it sholud be: 4 in x86 and 8 in x64)
So, does this work for you ?
if (IntPtr.Size==4)
this.pData = (IntPtr)(handle.AddrOfPinnedObject().ToInt32() + Offset * Marshal.SizeOf(typeof(T)));
else
this.pData = (IntPtr)(handle.AddrOfPinnedObject().ToInt64() + Offset * Marshal.SizeOf(typeof(T)));
Works for me. ;-)
Just two little more things.
1.- GetDateTimeAt() crash if data in buffer is 0.
Maybe could be checked and return a DateTime.MinValue
2.- GetStringAt() and SetStringAt() on my to-do list if not in yours.
Thanks for all.
1) Correct.
I tested this solution (replace the last line of the function):
try
{
return new DateTime(Year, Month, Day, Hour, Min, Sec);
}
catch (System.ArgumentOutOfRangeException)
{
return new DateTime(0);
}
2) I'm working on the massive test/compilation of 1.3.0 release that is coming out.
If I find 5 min of free time I will implement it, or, if you have a snippet feel free to post it ;)
Something as simple as this works for me.
Last edit: Pablo Agirre 2014-12-18
I like them, simple and clean.
I will add them to S7 class.
Thanks
Davide
(Your name ? just for the "thanks line")
Last edit: Davide Nardella 2014-12-19
All thanks to you for this great project.
Last edit: Pablo Agirre 2014-12-19