Menu

(no subject)

2014-12-12
2014-12-19
  • Pablo Agirre

    Pablo Agirre - 2014-12-12

    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)));

     
  • Davide Nardella

    Davide Nardella - 2014-12-12

    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 ?

     
  • Pablo Agirre

    Pablo Agirre - 2014-12-12

    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)

     
  • Davide Nardella

    Davide Nardella - 2014-12-12

    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)));

     
  • Pablo Agirre

    Pablo Agirre - 2014-12-13

    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.

     
  • Davide Nardella

    Davide Nardella - 2014-12-15

    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 ;)

     
  • Pablo Agirre

    Pablo Agirre - 2014-12-18

    Something as simple as this works for me.

       public static string GetStringAt(byte[] Buffer, int Pos)
        {
            //int maxsize = (int)Buffer[Pos];
            int size = (int)Buffer[Pos + 1];
            return Encoding.ASCII.GetString(Buffer, Pos + 2, size);
        }
    
        public static void SetStringAt(byte[] Buffer, int Pos, int MaxLen, string Value)
        {
            int size = Value.Length;
            Buffer[Pos] = (byte)MaxLen;
            Buffer[Pos + 1] = (byte)size;
            Encoding.ASCII.GetBytes(Value, 0, size, Buffer, Pos + 2);
        }
    
     

    Last edit: Pablo Agirre 2014-12-18
  • Davide Nardella

    Davide Nardella - 2014-12-19

    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
  • Pablo Agirre

    Pablo Agirre - 2014-12-19

    All thanks to you for this great project.

     

    Last edit: Pablo Agirre 2014-12-19

Log in to post a comment.