Example #1
0
        void HandleClock(ValueEventArgs e)
        {
            GXDLMSClock c = e.Target as GXDLMSClock;

            if (e.Index == 2)
            {
                c.Time = c.Now();
            }
        }
Example #2
0
 /// <summary>
 /// Generate random value for profile generic.
 /// </summary>
 /// <param name="args"></param>
 public override void PreGet(ValueEventArgs[] args)
 {
     foreach (ValueEventArgs e in args)
     {
         if (e.Target is GXDLMSProfileGeneric)
         {
             //We want to save values to the file right a way.
             GXDLMSProfileGeneric pg = (GXDLMSProfileGeneric)e.Target;
             //Get entries in use if not know yet.
             if (pg.EntriesInUse == 0)
             {
                 pg.EntriesInUse = GetProfileGenericDataCount(pg);
             }
             string   name   = GetProfileGenericName(pg);
             object[] values = new object[pg.CaptureObjects.Count];
             int      pos    = 0;
             lock (pg)
             {
                 foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in pg.CaptureObjects)
                 {
                     if (it.Key is GXDLMSClock && it.Value.AttributeIndex == 2)
                     {
                         GXDLMSClock c = (it.Key as GXDLMSClock);
                         c.Time = c.Now();
                     }
                     else if (it.Key == temperature && it.Value.AttributeIndex == 2)
                     {
                         //Get CPU temperature.
                         UpdateTemperature();
                     }
                     values[pos] = it.Key.GetValues()[it.Value.AttributeIndex - 1];
                     ++pos;
                 }
                 ++pg.EntriesInUse;
                 //Remove first row if maximum row count is received.
                 if (pg.ProfileEntries != 0 && pg.EntriesInUse >= pg.ProfileEntries)
                 {
                     RemoveRows(name, pg.EntriesInUse - pg.ProfileEntries);
                     pg.EntriesInUse = pg.ProfileEntries;
                 }
                 using (var writer = File.AppendText(name))
                 {
                     StringBuilder sb = new StringBuilder();
                     for (int c = 0; c != values.Length; ++c)
                     {
                         if (c != 0)
                         {
                             sb.Append(';');
                         }
                         object col = values[c];
                         if (col is DateTime)
                         {
                             sb.Append(((DateTime)col).ToString(CultureInfo.InvariantCulture));
                         }
                         else
                         {
                             sb.Append(Convert.ToString(col));
                         }
                     }
                     sb.AppendLine("");
                     writer.Write(sb.ToString());
                 }
             }
             e.Handled = true;
         }
     }
 }