コード例 #1
0
        public static int piServerConnectEx(string serverName, string userName, string password, ref int valid)
        {
            int num = PIAPI32.piut_setservernode(serverName);

            if (num == 0)
            {
                num = PIAPI32.piut_login(userName, password, out valid);
            }
            return(num);
        }
コード例 #2
0
        public unsafe static int pipt_descriptorex(int pt, out string desc)
        {
            byte[] strbuf = new byte[256];
            fixed(byte *lpStr = strbuf)
            {
                int len    = 255;
                int result = PIAPI32.pipt_descriptorx(pt, lpStr, ref len);

                desc = Encoding.UTF8.GetString(strbuf, 0, len);
                return(result);
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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;
            }
        }