예제 #1
0
        public ObjectKosm(ObjectIndex ind, string code)
        {
            Sn         = ind.Sn;
            NumType    = ind.NumType;
            Appartment = ind.Appartment;
            Out        = ind.Out;
            int    p = code.LastIndexOf(".");
            string s = p == -1 ? code : code.Substring(0, p);

            Inf = "Code=" + s + "; SN=" + Sn + "; NumType=" + NumType + ";Out=" + Out + "; Appartment=" + Appartment + ";";
        }
예제 #2
0
        //Добавляет один сигнал в список
        public ProviderSignal AddSignal(string signalInf, string code, DataType dataType, int idInClone = 0)
        {
            var sig = new ProviderSignal(signalInf, code, dataType, this, idInClone);
            //Заполнение SignalsLists
            var ind = new ObjectIndex
            {
                Sn         = sig.Inf.GetInt("SysNum"),
                NumType    = sig.Inf.GetInt("NumType"),
                Appartment = sig.Inf.GetInt("Appartment"),
                Out        = sig.Inf.GetInt("NumOut")
            };
            ObjectKosm obj;

            if (ind.Out == 1 && (ind.NumType == 1 || ind.NumType == 3 || ind.NumType == 32))
            {
                if (_analogs.ContainsKey(ind))
                {
                    obj = _analogs[ind];
                }
                else
                {
                    obj = new ObjectKosm(ind, sig.Code);
                    _analogs.Add(ind, obj);
                }
            }
            else
            {
                if (_outs.ContainsKey(ind))
                {
                    obj = _outs[ind];
                }
                else
                {
                    obj = new ObjectKosm(ind, sig.Code);
                    _outs.Add(ind, obj);
                }
            }
            var nsig = obj.AddSignal(sig);

            if (nsig == sig)
            {
                ProviderSignals.Add(sig.Code, nsig);
            }
            return(nsig);
        }
예제 #3
0
        //Получение значений аналоговых сигналов из рекорсета rec, который вернула комманда,
        //Если begtime != null, то такое время устанавливается для всех значений
        private KeyValuePair <int, int> ProcessAnalog(IDataReader rec, DateTime?begtime = null)
        {
            int dn = this is KosmotronikaRetroSource ? 1 : 0;
            int nread = 0, nwrite = 0;

            while (rec.Read())
            {
                nread++;
                var curInd = new ObjectIndex
                {
                    Sn                             = Convert.ToInt32(rec[0]),
                    NumType                        = Convert.ToInt32(rec[1]),
                    Appartment                     = this is KosmotronikaRetroSource?Convert.ToInt32(rec[2]) : 0,
                                               Out = 1
                };
                if (_analogs.ContainsKey(curInd))
                {
                    DateTime time = begtime ?? Convert.ToDateTime(rec[2 + dn]);
                    if (time < EndRead || time == BeginRead)
                    {
                        ObjectKosm ob    = _analogs[curInd];
                        int        ndint = Convert.ToInt32(rec[5 + dn]);
                        int        nd    = ndint.GetBit(15) || ndint.GetBit(5) ? 1 : 0;
                        int        pok   = Convert.ToInt32(rec[4 + dn]);
                        var        dMean = (Single)rec[7 + dn];
                        if (ob.ValueSignal != null && ob.ValueSignal.DataType == DataType.Real)
                        {
                            nwrite += ob.ValueSignal.AddMoment(time, dMean, nd);
                        }
                        if (ob.StateSignal != null)
                        {
                            nwrite += ob.StateSignal.AddMoment(time, ndint);
                        }
                        if (ob.PokSignal != null)
                        {
                            nwrite += ob.PokSignal.AddMoment(time, pok, nd);
                        }
                    }
                }
            }
            return(new KeyValuePair <int, int>(nread, nwrite));
        }
예제 #4
0
        //Получение значений выходов из рекорсета rec, который вернула комманда,
        //Tсли time != null, то такое время устанавливается для всех значений
        private KeyValuePair <int, int> ProcessOuts(IDataReader rec, DateTime?begtime = null)
        {
            int dn = this is KosmotronikaRetroSource ? 1 : 0;
            int nread = 0, nwrite = 0;

            while (rec.Read())
            {
                nread++;
                ObjectKosm ob = null;
                try
                {
                    var curSignal = new ObjectIndex
                    {
                        Sn                             = Convert.ToInt32(rec[0]),
                        NumType                        = Convert.ToInt32(rec[1]),
                        Appartment                     = this is KosmotronikaRetroSource?Convert.ToInt32(rec[2]) : 0,
                                                   Out = Convert.ToInt32(rec[5 + dn])
                    };
                    if (_outs.ContainsKey(curSignal))
                    {
                        DateTime time = begtime ?? Convert.ToDateTime(rec[2 + dn]);
                        if (time < _periodEnd || time == _periodBegin)
                        {
                            ob = _outs[curSignal];
                            int    ndint = Convert.ToInt32(rec[7 + dn]);
                            int    nd    = ndint.GetBit(15) || ndint.GetBit(5) ? 1 : 0;
                            int    pok   = Convert.ToInt32(rec[4 + dn]);
                            var    s     = (string)rec[8 + dn];
                            uint   iMean = 0;
                            double dMean = 0;
                            bool   isInt = false;
                            if (s.IndexOf("0x") >= 0)
                            {
                                iMean = Convert.ToUInt32((string)rec[8 + dn], 16);
                                isInt = true;
                            }
                            else
                            {
                                dMean = Convert.ToDouble((string)rec[8 + dn]);
                            }
                            if (ob.StateSignal != null)
                            {
                                nwrite += ob.StateSignal.AddMoment(time, ndint);
                            }
                            if (ob.PokSignal != null)
                            {
                                nwrite += ob.PokSignal.AddMoment(time, pok, nd);
                            }
                            if (ob.ValueSignal != null)
                            {
                                switch (ob.ValueSignal.DataType)
                                {
                                case DataType.Boolean:
                                    nwrite += ob.ValueSignal.AddMoment(time, isInt ? iMean > 0 : dMean > 0, nd);
                                    break;

                                case DataType.Integer:
                                    nwrite += ob.ValueSignal.AddMoment(time, isInt ? (int)iMean : Convert.ToInt32(dMean), nd);
                                    break;

                                case DataType.Real:
                                    nwrite += ob.ValueSignal.AddMoment(time, isInt ? iMean : dMean, nd);
                                    break;
                                }
                            }
                            foreach (int i in ob.BitSignals.Keys)
                            {
                                if (!isInt)
                                {
                                    iMean = Convert.ToUInt32(dMean);
                                }
                                nwrite += ob.BitSignals[i].AddMoment(time, iMean.GetBit(i), nd);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    AddErrorObject(ob == null ? "" : ob.Inf, "Ошибка при чтении значений из рекордсета", ex);
                }
            }
            return(new KeyValuePair <int, int>(nread, nwrite));
        }