/// <summary>
 /// Copies the values of the objects to capture
 /// into the buffer by reading capture objects.
 /// </summary>
 public void Capture(GXDLMSServer server)
 {
     lock (this)
     {
         object[]         values = new object[CaptureObjects.Count];
         int              pos    = 0;
         ValueEventArgs[] args   = new ValueEventArgs[] { new ValueEventArgs(server, this, 2, 0, null) };
         server.PreGet(args);
         if (!args[0].Handled)
         {
             foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
             {
                 values[pos] = it.Key.GetValues()[it.Value.AttributeIndex - 1];
                 ++pos;
             }
             lock (Buffer)
             {
                 //Remove first items if buffer is full.
                 if (ProfileEntries != 0 && ProfileEntries == Buffer.Count)
                 {
                     --EntriesInUse;
                     Buffer.RemoveAt(0);
                 }
                 Buffer.Add(values);
                 ++EntriesInUse;
             }
         }
         server.PostGet(args);
         server.NotifyAction(args);
         server.NotifyPostAction(args);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Copies the values of the objects to capture
 /// into the buffer by reading capture objects.
 /// </summary>
 internal void Capture(GXDLMSServer server)
 {
     lock (this)
     {
         GXByteBuffer     bb   = new GXByteBuffer();
         ValueEventArgs[] args = new ValueEventArgs[] { new ValueEventArgs(server, this, 2, 0, null) };
         Buffer = null;
         if (server != null)
         {
             server.PreGet(args);
         }
         if (!args[0].Handled)
         {
             foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
             {
                 ValueEventArgs e     = new ValueEventArgs(server, it.Key, it.Value.AttributeIndex, 0, null);
                 object         value = (it.Key as IGXDLMSBase).GetValue(server == null ? null : server.Settings, e);
                 DataType       dt    = (it.Key as IGXDLMSBase).GetDataType(it.Value.AttributeIndex);
                 if ((value is byte[] || value is GXByteBuffer[]) && (dt == DataType.Structure || dt == DataType.Array))
                 {
                     GXByteBuffer tmp;
                     if (value is byte[])
                     {
                         tmp = new GXByteBuffer((byte[])value);
                     }
                     else
                     {
                         tmp = (GXByteBuffer)value;
                     }
                     CaptureArray(server, tmp, bb, it.Value.DataIndex - 1);
                 }
                 else
                 {
                     GXByteBuffer tmp = new GXByteBuffer();
                     GXCommon.SetData(server == null ? null : server.Settings, tmp, dt, value);
                     //If data is empty.
                     if (tmp.Size == 1)
                     {
                         bb.SetUInt8(0);
                     }
                     else
                     {
                         tmp.Position = 1;
                         bb.Set(tmp);
                     }
                 }
             }
             Buffer = bb.Array();
         }
         if (server != null)
         {
             server.PostGet(args);
             server.NotifyAction(args);
             server.NotifyPostAction(args);
         }
     }
 }