Beispiel #1
0
        public void SaveSettings()
        {
            try {
                IniFile iniFile = new IniFile(PIBUtils.GetIniFile());
                try {
                    iniFile.WriteBool("Trends", "AutoScaleMax", fAutoScaleMax);
                    iniFile.WriteBool("Trends", "AutoScaleMin", fAutoScaleMin);
                    iniFile.WriteFloat("Trends", "Max", fMax);
                    iniFile.WriteFloat("Trends", "Min", fMin);
                    iniFile.WriteBool("Trends", "ShowSource", fShowSource);
                    iniFile.WriteInteger("Trends", "PostAction", (int)((sbyte)fSeries.PostAction));

                    FilterOptions filter = fSeries.Filter;
                    iniFile.WriteInteger("Trends", "Filter.Mode", (int)((sbyte)filter.Mode));
                    iniFile.WriteFloat("Trends", "Filter.BandWidth", filter.BandWidth);
                    iniFile.WriteBool("Trends", "Filter.Overshoot", filter.Overshoot);
                    iniFile.WriteInteger("Trends", "Filter.FrequencyResolution", filter.FrequencyResolution);
                    iniFile.WriteInteger("Trends", "Filter.SuppressionDegree", (int)((sbyte)filter.SuppressionDegree));
                    iniFile.WriteInteger("Trends", "Filter.SubstractionNoiseDegree", (int)((sbyte)filter.SubstractionNoiseDegree));
                } finally {
                    iniFile.Dispose();
                }
            } catch (Exception ex) {
            }
        }
 private void CheckModifyTagList()
 {
     if (!string.IsNullOrEmpty(fCurTagListFile) && fModified)
     {
         using (IniFile iniFile = new IniFile(fCurTagListFile)) {
             if (PIBUtils.ShowQuestionYN(string.Concat(new string[] {
                 "List of tags: \"",
                 Path.GetFileName(fCurTagListFile),
                 "\" is changed. Save changes?"
             })))
             {
                 for (int i = 1; i <= MAX_TRENDS; i++)
                 {
                     TrendObj trendObj = TrendChart1[i - 1];
                     iniFile.WriteString("Trends", "Trend" + Convert.ToString(i), trendObj.Tag);
                     iniFile.WriteInteger("Trends", "PostAction" + Convert.ToString(i), (int)trendObj.PostAction);
                     if (trendObj.PostAction != PostAction.paNone)
                     {
                         iniFile.WriteInteger("Trends", "Mode" + Convert.ToString(i), (int)trendObj.Filter.Mode);
                         iniFile.WriteFloat("Trends", "BandWidth" + Convert.ToString(i), trendObj.Filter.BandWidth);
                         iniFile.WriteBool("Trends", "Overshoot" + Convert.ToString(i), trendObj.Filter.Overshoot);
                         iniFile.WriteInteger("Trends", "FrequencyResolution" + Convert.ToString(i), trendObj.Filter.FrequencyResolution);
                         iniFile.WriteInteger("Trends", "SuppressionDegree" + Convert.ToString(i), (int)trendObj.Filter.SuppressionDegree);
                         iniFile.WriteInteger("Trends", "SubstractionNoiseDegree" + Convert.ToString(i), (int)trendObj.Filter.SubstractionNoiseDegree);
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
        public void LoadSettings()
        {
            try {
                IniFile iniFile = new IniFile(PIBUtils.GetIniFile());
                try {
                    fAutoScaleMax      = iniFile.ReadBool("Trends", "AutoScaleMax", true);
                    fAutoScaleMin      = iniFile.ReadBool("Trends", "AutoScaleMin", true);
                    fMax               = iniFile.ReadFloat("Trends", "Max", 0);
                    fMin               = iniFile.ReadFloat("Trends", "Min", 0);
                    fShowSource        = iniFile.ReadBool("Trends", "ShowSource", false);
                    fSeries.PostAction = (PostAction)iniFile.ReadInteger("Trends", "PostAction", 0);

                    FilterOptions filter = fSeries.Filter;
                    filter.Mode                    = (FilterMode)iniFile.ReadInteger("Trends", "Filter.Mode", 0);
                    filter.BandWidth               = iniFile.ReadFloat("Trends", "Filter.BandWidth", 0);
                    filter.Overshoot               = iniFile.ReadBool("Trends", "Filter.Overshoot", false);
                    filter.FrequencyResolution     = iniFile.ReadInteger("Trends", "Filter.FrequencyResolution", 0);
                    filter.SuppressionDegree       = (FilterDegree)iniFile.ReadInteger("Trends", "Filter.SuppressionDegree", 0);
                    filter.SubstractionNoiseDegree = (FilterDegree)iniFile.ReadInteger("Trends", "Filter.SubstractionNoiseDegree", 0);

                    fSeries.ApplyFilter();
                } finally {
                    iniFile.Dispose();
                }
            } catch (Exception ex) {
            }
        }
        public void tbTLSaveClick(object sender, EventArgs e)
        {
            sdTagList.Filter           = "Tags list file (*.lst)|*.lst|All files|*.*";
            sdTagList.InitialDirectory = PIBUtils.GetAppPath();

            if (sdTagList.ShowDialog() == DialogResult.OK)
            {
                using (IniFile iniFile = new IniFile(sdTagList.FileName)) {
                    for (int i = 1; i <= MAX_TRENDS; i++)
                    {
                        TrendObj trendObj = TrendChart1[i - 1];
                        iniFile.WriteString("Trends", "Trend" + Convert.ToString(i), trendObj.Tag);
                        iniFile.WriteInteger("Trends", "PostAction" + Convert.ToString(i), (int)trendObj.PostAction);
                        if (trendObj.PostAction != PostAction.paNone)
                        {
                            iniFile.WriteInteger("Trends", "Mode" + Convert.ToString(i), (int)trendObj.Filter.Mode);
                            iniFile.WriteFloat("Trends", "BandWidth" + Convert.ToString(i), trendObj.Filter.BandWidth);
                            iniFile.WriteBool("Trends", "Overshoot" + Convert.ToString(i), trendObj.Filter.Overshoot);
                            iniFile.WriteInteger("Trends", "FrequencyResolution" + Convert.ToString(i), trendObj.Filter.FrequencyResolution);
                            iniFile.WriteInteger("Trends", "SuppressionDegree" + Convert.ToString(i), (int)trendObj.Filter.SuppressionDegree);
                            iniFile.WriteInteger("Trends", "SubstractionNoiseDegree" + Convert.ToString(i), (int)trendObj.Filter.SubstractionNoiseDegree);
                        }
                    }
                }

                CaptionTagList = "Current list of tags: " + Path.GetFileName(sdTagList.FileName);
                fModified      = false;
            }
        }
        public void tbAnalysisClick(object sender, EventArgs e)
        {
            StringList strList = new StringList();

            try {
                for (int i = 0; i < MAX_TRENDS; i++)
                {
                    TrendObj trendObj = TrendChart1[i];

                    if (!string.IsNullOrEmpty(trendObj.Tag))
                    {
                        strList.Add(string.Concat(new string[] {
                            trendObj.Tag,
                            ": ",
                            "MIN: ",
                            AnalitikMIN[i].ToString(),
                            "| ",
                            "MAX: ",
                            AnalitikMAX[i].ToString(),
                            "| ",
                            "AVG: ",
                            AnalitikAVG[i].ToString(),
                            "\n\r"
                        }));
                    }
                }

                if (strList.Text != "")
                {
                    PIBUtils.ShowMessage("Analysis results:\n\r" + strList.Text);
                }
            } catch (Exception ex) {
                strList.Dispose();
            }
        }
        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 tbTLLoadClick(object sender, EventArgs e)
        {
            CheckModifyTagList();

            odTagList.Filter           = "Tags list file (*.lst)|*.lst|All files|*.*";
            odTagList.InitialDirectory = PIBUtils.GetAppPath();

            if (odTagList.ShowDialog() == DialogResult.OK)
            {
                for (int i = 0; i < lvTags.Items.Count; i++)
                {
                    lvTags.Items[i].Checked = false;
                }

                LoadListTrend(odTagList.FileName);

                fCurTagListFile = odTagList.FileName;
                if (!string.IsNullOrEmpty(fCurTagListFile))
                {
                    CaptionTagList = "Current list of tags: " + Path.GetFileName(fCurTagListFile);
                }
                else
                {
                    CaptionTagList = "No loaded tag lists";
                }
                fModified = false;
            }
        }
        public void cmbTagSearch_DropDown(object sender, EventArgs e)
        {
            try {
                IniFile iniFile = new IniFile(PIBUtils.GetIniFile());
                try {
                    cmbTagSearch.Items.Clear();
                    for (int i = 0; i < 10; i++)
                    {
                        string text;
                        try {
                            text = iniFile.ReadString("Common", "PreFind" + Convert.ToString(i), "");
                        } catch (Exception ex) {
                            iniFile.WriteString("Common", "PreFind" + Convert.ToString(i), "");
                            text = "";
                        }

                        if (text != "" || text == " ")
                        {
                            cmbTagSearch.Items.Add(text);
                        }
                    }
                } finally {
                    iniFile.Dispose();
                }
            } catch (Exception ex) {
            }
        }
        public void cmbTagSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return && cmbTagSearch.Text != "*")
            {
                UpdateTagsList();
                ClearTagsList();
                LVTagsClick(sender, null);
                cmbTagSearch_DropDown(sender, null);

                if (cmbTagSearch.Items.IndexOf(cmbTagSearch.Text) == -1 && cmbTagSearch.Items.Count < 10)
                {
                    cmbTagSearch.Items.Add(cmbTagSearch.Text);
                }

                try {
                    IniFile iniFile = new IniFile(PIBUtils.GetIniFile());
                    try {
                        for (int i = 0; i < cmbTagSearch.Items.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(cmbTagSearch.Items[i].ToString()))
                            {
                                iniFile.WriteString("Common", "PreFind" + Convert.ToString(i), cmbTagSearch.Items[i].ToString());
                            }
                        }
                    } finally {
                        iniFile.Dispose();
                    }
                } catch (Exception ex) {
                }
            }
        }
Beispiel #10
0
        public void cbPeriodChange(object sender, EventArgs e)
        {
            int itemIndex = cmbPeriod.SelectedIndex;

            if (itemIndex != 0)
            {
                if (itemIndex != 1)
                {
                    if (itemIndex == 2)
                    {
                        fSession        = -1;
                        txtSession.Text = "";
                    }
                }
                else
                {
                    fSession        = -1;
                    txtSession.Text = "";
                }
            }
            else
            {
                fSession        = PIBUtils.GetSession(DateTimePicker1.Value);
                txtSession.Text = Convert.ToString(fSession);
            }

            RefreshTrends();
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        private void SelectTag(string tagName)
        {
            lvTags.Focus();
            ListViewItem item = PIBUtils.FindCaption(lvTags, tagName);

            if (item != null)
            {
                PIBUtils.SelectItem(lvTags, item);
            }
        }
Beispiel #13
0
 public void SaveConnectionSettings()
 {
     try {
         using (IniFile iniFile = new IniFile(PIBUtils.GetIniFile())) {
             iniFile.WriteString(PIBUtils.AppName, "ConServerName", ConServerName);
             iniFile.WriteString(PIBUtils.AppName, "ConUser", ConUser);
         }
     } catch (Exception ex) {
     }
 }
Beispiel #14
0
 public static void AboutDialog()
 {
     using (var fmAbout = new AboutDlg()) {
         fmAbout.lblProduct.Text   = "PI Browser";
         fmAbout.lblVersion.Text   = "Version " + PIBUtils.GetFileVersion();
         fmAbout.lblCopyright.Text = "© 2007-2012, 2017 Sergey V. Zhdanovskih";
         fmAbout.lblMail.Text      = "mailto:[email protected]";
         fmAbout.ShowDialog();
     }
 }
Beispiel #15
0
 public void LoadConnectionSettings()
 {
     try {
         using (IniFile iniFile = new IniFile(PIBUtils.GetIniFile())) {
             ConServerName = iniFile.ReadString(PIBUtils.AppName, "ConServerName", "");
             ConUser       = iniFile.ReadString(PIBUtils.AppName, "ConUser", "");
         }
     } catch (Exception ex) {
         ResetConnectionSettings();
     }
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
 public void ClearSettings()
 {
     try {
         IniFile iniFile = new IniFile(PIBUtils.GetIniFile());
         try {
         } finally {
             iniFile.Dispose();
         }
         Init();
     } catch (Exception ex) {
     }
 }
Beispiel #18
0
 public void FiltersApply()
 {
     for (int i = 0; i < fTrends.Count; i++)
     {
         if (fTrends[i].Visible)
         {
             try {
                 fTrends[i].Series.ApplyFilter();
             } catch (Exception ex) {
                 PIBUtils.ShowMessage("Error type #8: " + ex.Message);
             }
         }
     }
 }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public PIBrowserWin()
        {
            InitializeComponent();
            fInstance    = this;
            fmConnection = new ConnectionDlg();

            Assembly assembly = typeof(PIBrowserWin).Assembly;

            tbAbout.Image   = PIBUtils.LoadResourceImage(assembly, "PIBrowser.Resources.about.gif");
            tbOptions.Image = PIBUtils.LoadResourceImage(assembly, "PIBrowser.Resources.options.gif");
            tbPrint.Image   = PIBUtils.LoadResourceImage(assembly, "PIBrowser.Resources.print.gif");
            tbTLLoad.Image  = PIBUtils.LoadResourceImage(assembly, "PIBrowser.Resources.load.gif");
            tbTLSave.Image  = PIBUtils.LoadResourceImage(assembly, "PIBrowser.Resources.save.gif");
        }
Beispiel #21
0
        public void LoadListTrend(string trendListFile)
        {
            using (IniFile iniFile = new IniFile(trendListFile)) {
                for (int k = 1; k <= MAX_TRENDS; k++)
                {
                    TrendChart1[k - 1].Tag = iniFile.ReadString("Trends", "Trend" + Convert.ToString(k), "");
                }

                for (int i = 0; i < MAX_TRENDS; i++)
                {
                    TrendObj trendObj = TrendChart1[i];

                    if (!string.IsNullOrEmpty(trendObj.Tag))
                    {
                        ListViewItem listItem = PIBUtils.FindCaption(lvTags, trendObj.Tag);
                        if (listItem != null)
                        {
                            listItem.Checked = true;
                            SetTagByItem(trendObj, listItem);
                            trendObj.PostAction = (PostAction)iniFile.ReadInteger("Trends", "PostAction" + Convert.ToString(i), 1);
                            if (trendObj.PostAction != PostAction.paNone)
                            {
                                FilterOptions filter = trendObj.Filter;
                                filter.Mode                    = (FilterMode)iniFile.ReadInteger("Trends", "Mode" + Convert.ToString(i), 1);
                                filter.BandWidth               = iniFile.ReadFloat("Trends", "BandWidth" + Convert.ToString(i), 0.1);
                                filter.Overshoot               = iniFile.ReadBool("Trends", "Overshoot" + Convert.ToString(i), false);
                                filter.FrequencyResolution     = iniFile.ReadInteger("Trends", "FrequencyResolution" + Convert.ToString(i), 5);
                                filter.SuppressionDegree       = (FilterDegree)iniFile.ReadInteger("Trends", "SuppressionDegree" + Convert.ToString(i), 0);
                                filter.SubstractionNoiseDegree = (FilterDegree)iniFile.ReadInteger("Trends", "SubstractionNoiseDegree" + Convert.ToString(i), 0);
                            }
                        }
                        else
                        {
                            PIBUtils.ShowWarning("Tag " + trendObj.Tag + " not exists");
                            trendObj.Tag = "";
                            fModified    = true;
                        }
                    }
                }

                TrendChart1.FiltersApply();
                SelectTag(TrendChart1[0].Tag);
                LVTagsClick(lvTags, null);
            }

            CaptionTagList = "Current list of tags: " + Path.GetFileName(trendListFile);
        }
Beispiel #22
0
        private void GetTimeRange(ref DateTime d1, ref DateTime d2)
        {
            int itemIndex = cmbPeriod.SelectedIndex;

            if (itemIndex >= 2)
            {
                if (itemIndex == 2)
                {
                    DateTime dummy = DateTime.Now;
                    PIBUtils.SessionRangeGen(fCurrentDate.AddDays(-7.0), fSession, ref d1, ref dummy, false);
                    PIBUtils.SessionRangeGen(fCurrentDate, fSession, ref dummy, ref d2, false);
                }
            }
            else
            {
                PIBUtils.SessionRangeGen(fCurrentDate, fSession, ref d1, ref d2, false);
            }
        }
Beispiel #23
0
 public void DrawTrends()
 {
     Clear();
     for (int i = 0; i < fTrends.Count; i++)
     {
         TrendObj trendObj = fTrends[i];
         if (fTrends[i].Visible)
         {
             try {
                 if (!string.IsNullOrEmpty(trendObj.Tag))
                 {
                     PrepareArray("", "", "", trendObj);
                 }
             } catch (Exception ex) {
                 PIBUtils.ShowMessage("Error type #8: " + ex.Message);
             }
         }
     }
 }
Beispiel #24
0
        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();
            }
        }
Beispiel #25
0
        public void LVTagsItemChecked(object sender, ItemCheckedEventArgs e)
        {
            var item = PIBUtils.GetSelectedItem(lvTags);

            if (item != null && item.Checked)
            {
                int used = 0;
                for (int i = 0; i < lvTags.Items.Count; i++)
                {
                    if (lvTags.Items[i].Checked)
                    {
                        used++;
                    }
                }
                if (used > MAX_TRENDS)
                {
                    item.Checked = false;
                }
            }
            SelectTags();
        }
Beispiel #26
0
        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;
            }
        }
Beispiel #27
0
        public static bool piServerConnect(string serverName, string userName, string password)
        {
            int num = -1;

            return(PIBUtils.piServerConnectEx(serverName, userName, password, ref num) == 0 && num == 2);
        }
Beispiel #28
0
        public void cmbTagSearch_TextChanged(object sender, EventArgs e)
        {
            var item = PIBUtils.FindCaption(lvTags, cmbTagSearch.Text);

            PIBUtils.SelectItem(lvTags, item);
        }
Beispiel #29
0
        private void LoadTrendData(DataLoadKind loadKind, DateTime aBeg, DateTime aEnd)
        {
            RefreshNavigation();

            if (loadKind == DataLoadKind.dlkByStart)
            {
                for (int i = 0; i < MAX_TRENDS; i++)
                {
                    TrendChart1[i].Clear();
                }
            }

            DateTime begDateTime = DateTime.Now;
            DateTime endDateTime = DateTime.Now;

            GetTimeRange(ref begDateTime, ref endDateTime);

            TrendChart1.BegDateTime = begDateTime;
            TrendChart1.EndDateTime = endDateTime;
            TrendChart1.ForeColor   = Color.Black;
            TrendChart1.RulerColor  = Color.Black;
            TrendChart1.XAxisColor  = Color.Black;
            TrendChart1.CrossRuler  = true;
            TrendChart1.DateCode    = 0;
            TrendChart1.DayCode     = 0;
            TrendChart1.MonthCode   = 0;
            TrendChart1.YearCode    = 0;
            TrendChart1.AroundZoom  = true;
            TrendChart1.Legend      = true;

            TrendChart1.BeginUpdate();
            for (int k = 0; k < MAX_TRENDS; k++)
            {
                int num2 = k / 4;
                int num3 = k % 4;

                TrendObj trendObj = TrendChart1[k];
                //if (trendObj == null) continue;

                switch (k)
                {
                case 0:
                    trendObj.Color = Color.Red;
                    break;

                case 1:
                    trendObj.Color = Color.Green;
                    break;

                case 2:
                    trendObj.Color = Color.Black;
                    break;

                case 3:
                    trendObj.Color = Color.Blue;
                    break;

                case 4:
                    trendObj.Color = Color.Fuchsia;
                    break;

                case 5:
                    trendObj.Color = Color.Navy;
                    break;

                case 6:
                    trendObj.Color = Color.Olive;
                    break;

                case 7:
                    trendObj.Color = Color.Purple;
                    break;
                }

                trendObj.AxisSign   = "[" + Convert.ToString(k) + "]";
                trendObj.ScaleIndex = num3 + 1;
                trendObj.PosY       = num2 + 1;

                if (!string.IsNullOrEmpty(trendObj.Tag))
                {
                    float zero, span;
                    PIBUtils.piLoadTrend(trendObj.Series, trendObj.Tag, (LoadFlags)0, aBeg, aEnd, out zero, out span);

                    double sum = 0.0;
                    if (trendObj.Series.Count > 0)
                    {
                        AnalitikMAX[k] = trendObj.Series[0].pValue;
                        AnalitikMIN[k] = trendObj.Series[0].pValue;
                    }
                    else
                    {
                        AnalitikMAX[k] = 0.0;
                        AnalitikMIN[k] = 0.0;
                    }

                    for (int i = 0; i < trendObj.Series.Count; i++)
                    {
                        TrendPoint trendPt = trendObj.Series[i];
                        sum = (sum + trendPt.pValue);
                        if (trendPt.pValue >= AnalitikMAX[k])
                        {
                            AnalitikMAX[k] = trendPt.pValue;
                        }
                        if (trendPt.pValue <= AnalitikMIN[k])
                        {
                            AnalitikMIN[k] = trendPt.pValue;
                        }
                    }

                    if (trendObj.Series.Count != 0)
                    {
                        AnalitikAVG[k] = (sum / (double)trendObj.Series.Count);
                    }
                    else
                    {
                        AnalitikAVG[k] = 0.0;
                    }

                    if (trendObj.Series.Count > 0)
                    {
                        fLastUpdate = trendObj.Series[trendObj.Series.Count - 1].pTime;
                    }
                    else
                    {
                        fLastUpdate = 0;
                    }
                }
                else
                {
                    trendObj.Visible = false;
                    AnalitikMAX[k]   = 0.0;
                    AnalitikMIN[k]   = 0.0;
                }
            }

            TrendChart1.FiltersApply();
            TrendChart1.DrawTrends();
            TrendChart1.EndUpdate();
            TrendChart1.Invalidate();
        }
Beispiel #30
0
 public bool Connect()
 {
     return(PIBUtils.piServerConnect(ConServerName, ConUser, ConPassword));
 }