public TrendObj() { fAutoScaleMax = true; fAutoScaleMin = true; fBreakupInterval = DateTime.FromOADate(0.0); fDeltaMultiplier = 0.025; fGridShow = false; fMax = 0.0; fMin = 0.0; fScaleIndex = 1; fSeries = new TrendSeries(); fShowSource = false; fStdLevel = 0.0; fStdName = ""; fStdShow = false; fTag = ""; fVisible = true; }
public static void piLoadTrend(TrendSeries trend, string tagName, LoadFlags flags, DateTime aBeg, DateTime aEnd, out float zero, out float span, int interval = 10, bool autoRange = false) { DateTime dtNow = DateTime.Now; Season daylightOffset = PIBUtils.GetDaylightOffset(dtNow); aBeg.AddHours(-PIBUtils.GetOffset(daylightOffset, PIBUtils.GetDaylightOffset(aBeg))); aEnd.AddHours(-PIBUtils.GetOffset(daylightOffset, PIBUtils.GetDaylightOffset(aEnd))); int tagNum; int res = PIAPI32.pipt_findpointex(tagName, out tagNum); if (autoRange) { TimeSpan ts = (aEnd - aBeg); double d = ts.TotalHours; if (d >= 24 * 7) { interval *= 9; } else if (d >= 24) { interval *= 3; } else if (d >= 12) { interval *= 2; } } if (res == 0) { _PIvaluetype elem; PIAPI32.pipt_pointtypex(tagNum, out elem); PIAPI32.pipt_scale(tagNum, out zero, out span); DateTime tm = aBeg; int cnt = 0; while (tm <= aEnd && (tm <= dtNow)) { cnt++; tm = tm.AddSeconds(interval); } try { float[] rvals = new float[cnt * 4]; int[] times = new int[cnt * 4]; int[] istats = new int[cnt * 4]; try { tm = aBeg; cnt = 0; while (tm <= aEnd && tm <= dtNow) { int timedate = PIBUtils.TimeToPITime(tm); times[cnt] = timedate; cnt++; tm = tm.AddSeconds(interval); } if (cnt != 0) { switch (PIBUtils.ArchiveRetrievalMode) { case PIArchiveRetrievalMode.armTimeInterpolated: res = PIAPI32.piar_timedvaluesex(tagNum, ref cnt, ref times, out rvals, out istats, 0); break; case PIArchiveRetrievalMode.armInterpolated: res = PIAPI32.piar_interpvaluesex(tagNum, ref cnt, ref times, out rvals, out istats); break; case PIArchiveRetrievalMode.armCompressed: res = PIAPI32.piar_compvaluesex(tagNum, ref cnt, ref times, out rvals, out istats, 0); break; } if (res == 0) { for (int i = 0; i < cnt; i++) { double rval = (double)rvals[i]; DateTime dtx = PIBUtils.PITimeToTime(times[i]); dtx.AddHours(+PIBUtils.GetOffset(daylightOffset, PIBUtils.GetDaylightOffset(dtx))); int num14 = istats[i]; if (Array.IndexOf(PIBUtils.PIFloatTypes, elem) >= 0) { bool valid = true; if (num14 != 0) { if ((flags & LoadFlags.lfValidity) == (LoadFlags)0) { continue; } valid = false; } if ((flags & LoadFlags.lfNegativeCut) != (LoadFlags)0 && rval < 0.0) { rval = 0.0; } trend.AddValue(dtx.ToOADate(), rval, valid); } else if (Array.IndexOf(PIBUtils.PIIntTypes, elem) >= 0) { rval = (double)num14; trend.AddValue(dtx.ToOADate(), rval, true); } } } } } finally { } } catch (Exception ex) { PIBUtils.ShowError("Error type #44: " + ex.Message); } } else { zero = 0; span = 0; } }