public void btnConClick(object sender, EventArgs e) { if (this.cmbServer.Text != "" && this.txtUser.Text != "" && this.txtPassword.Text != "") { this.gbCon.Enabled = false; try { PIBrowserWin.Instance.ConServerName = this.cmbServer.Text; PIBrowserWin.Instance.ConUser = this.txtUser.Text; PIBrowserWin.Instance.ConPassword = this.txtPassword.Text; if (!PIBrowserWin.Instance.Connect()) { PIBUtils.ShowError("The data entered does not match. Try again"); } else { if (this.cmbServer.Items.IndexOf(this.cmbServer.Text) == -1) { this.cmbServer.Items.Insert(0, this.cmbServer.Text); } PIBrowserWin.Instance.SaveConnectionSettings(); base.Hide(); PIBrowserWin.Instance.Timer1.Enabled = false; PIBrowserWin.Instance.Timer1.Interval = 30000; PIBrowserWin.Instance.Timer1.Enabled = true; PIBrowserWin.Instance.Show(); } } finally { this.gbCon.Enabled = true; } } }
public void Timer1Timer(object sender, EventArgs e) { fRI++; string captionTagList = Convert.ToString(fRI); CaptionTagList = captionTagList; try { if (!fRefreshed) { DateTime tDateTime = DateTime.Now; try { fRefreshed = true; DateTime right = DateTime.Now; DateTime right2 = DateTime.Now; PIBUtils.SessionRangeGen(fCurrentDate, fSession, ref right, ref right2, false); if (!(tDateTime >= right) || !(tDateTime <= right2)) { } else { LoadTrendData(DataLoadKind.dlkByTimer, DateTime.FromOADate(fLastUpdate), tDateTime); } } finally { fRefreshed = false; } } } catch (Exception ex) { PIBUtils.ShowError("Timer1Timer " + ex.Message); } }
public double FindValue(DateTime dtx) { double fdt = dtx.ToOADate(); double result = 0.0; try { bool flag = fSeries.PostAction != PostAction.paNone && (fSeries.PostAction == PostAction.paNone || !fShowSource); int num = 0; int num2 = fSeries.Count - 1; if (num <= num2) { do { int num3 = (int)((uint)(num + num2) >> 1); int num4 = TrendObj.FindValue_CompareValue(fSeries[num3].pTime, fdt); if (num4 < 0) { num = num3 + 1; } else { num2 = num3 - 1; if (num4 == 0) { num = num3; } } } while (num <= num2); } int num5 = num; if (num5 >= 0 && num5 < fSeries.Count) { if (flag) { result = fSeries[num5].pFilteredValue; } else { result = fSeries[num5].pValue; } } else { result = 0.0; } } catch (Exception ex) { PIBUtils.ShowError("Error type #4: " + ex.Message); } return(result); }
public double GetLastTime() { double result = 0.0; try { if (fSeries.Count > 0) { result = fSeries[fSeries.Count - 1].pTime; } } catch (Exception ex) { PIBUtils.ShowError("Error type #2: " + ex.Message); } return(result); }
private void UpdateTagsList() { this.lvTags.ItemChecked -= new System.Windows.Forms.ItemCheckedEventHandler(this.LVTagsItemChecked); lvTags.BeginUpdate(); lvTags.Items.Clear(); try { int num = PIAPI32.piut_isconnected(); if (num != 1) { PIBUtils.ShowError("Not connection"); } else { string text = cmbTagSearch.Text; string tagname; int found, pt, numfound; num = PIAPI32.pipt_wildcardsearchex(text, 0, out found, out tagname, out pt, out numfound); while (numfound >= 1) { int ptNum; if (PIAPI32.pipt_findpointex(tagname, out ptNum) == 0) { ListViewItem item = lvTags.Items.Add(tagname); string desc; PIAPI32.pipt_descriptorex(ptNum, out desc); item.SubItems.Add(desc); item.Tag = ptNum; } num = PIAPI32.pipt_wildcardsearchex(text, 1, out found, out tagname, out pt, out numfound); Application.DoEvents(); } } } finally { lvTags.EndUpdate(); this.lvTags.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.LVTagsItemChecked); UpdateStatusBar(); } }
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; } }