示例#1
0
        /// <summary>
        /// Подписаться на сигнал
        /// </summary>
        /// <param name="pars">Параметр (массив: идентификатор группы сигналов + KKS_NAME сигнала)</param>
        private void groupSignals_OnEvtAdviseItem(object pars)
        {
            long err        = -1;
            int  idGrpSgnls = (int)(pars as object [])[0];

            string [] kks_names = ((string)(pars as object [])[1]).Split(new string [] { @"," },StringSplitOptions.RemoveEmptyEntries);
            string    strErr    = string.Empty
            ,strIds             = @" [" + PlugInId + @", key=" + idGrpSgnls + @"]: ";
            // переменные для вызова 'm_torIsData.ReadItem'
            int    quality,status;
            int    type = 3;
            object value;
            double timestamp;

            if (IsStarted == false)
            {
                return;
            }
            else
            {
                ;
            }

            if (m_dictSignalsAdvised == null)
            {
                m_dictSignalsAdvised = new Dictionary <string,int> ();
            }
            else
            {
                ;
            }

            foreach (string kks_name in kks_names)
            {
                if (m_dictSignalsAdvised.ContainsKey(kks_name) == true)
                {
                    return;
                }
                else
                {
                    ;
                }

                err = m_torIsData.AdviseItems(kks_name);

                if (!(err == 0))
                {
                    switch (err)
                    {
                    case 1: strErr = "ETORIS_NOTCONFIG"; break;

                    case 2: strErr = "ETORIS_INVALIDITEM"; break;

                    case 3: strErr = "ETORIS_INVALIDATTR"; break;

                    case 4: strErr = "ETORIS_INVALIDTYPE"; break;

                    case 5: strErr = "ETORIS_INVALIDHANDLE"; break;

                    case 6: strErr = "ETORIS_NOTREGISTER"; break;

                    case 7: strErr = "ETORIS_ALREADYADVISED"; break;

                    case 8: strErr = "ETORIS_INVALIDITEMTYPE"; break;

                    case 9: strErr = "ETORIS_SHUTDOWN"; break;

                    default: strErr = "Неизвестная ошибка " + strErr.ToString(); break;
                    }

                    Logging.Logg().Error(@"Ошибка подписки на сигнал" + strIds + kks_name + " - " + strErr,Logging.INDEX_MESSAGE.NOT_SET);
                    continue;
                }
                else
                {
                    ;
                }

                m_dictSignalsAdvised.Add(kks_name,idGrpSgnls);

                //Logging.Logg ().Action (@"Подписка на сигнал" + strIds + kks_name, Logging.INDEX_MESSAGE.NOT_SET);

                err = m_torIsData.ReadItem(kks_name,ref type,out value,out timestamp,out quality,out status);
                if (!(err == 0))
                {
                    Logging.Logg().Error(@"Ошибка вызова ReadItem для" + strIds + kks_name + " - " + err.ToString(),Logging.INDEX_MESSAGE.NOT_SET);
                    continue;
                }
                else
                {
                    ;
                }

                torIsData_ItemSetValue(kks_name,type,value,timestamp,quality,status);
            }
        }
        /// <summary>
        /// Подписаться на сигнал
        /// </summary>
        /// <param name="pars">Параметр (массив: идентификатор группы сигналов + KKS_NAME сигнала)</param>
        private void groupSignals_OnEvtAdviseItem(object pars)
        {
            long err        = -1;
            int  idGrpSgnls = (int)(pars as object [])[0];

            string [] kks_names = ((string)(pars as object [])[1]).Split(new string [] { @"," },StringSplitOptions.RemoveEmptyEntries);
            string    strErr    = string.Empty
            ,strIds             = string.Format(@" [ID={0}:{1}, key={2}]: ",_iPlugin._Id,_iPlugin.KeySingleton,idGrpSgnls);
            // переменные для вызова 'm_torIsData.ReadItem'
            int    quality,status;
            int    type = 3;
            object value;
            double timestamp;

            if (IsStarted == false)
            {
                return;
            }
            else
            {
                ;
            }

            if (m_dictSignalsAdvised == null)
            {
                m_dictSignalsAdvised = new Dictionary <string,int> ();
            }
            else
            {
                ;
            }

            Logging.Logg().Action($@"::groupSignals_OnEvtAdviseItem () - начало подписки  {strIds}, сигналов <{kks_names.Length}>...",Logging.INDEX_MESSAGE.NOT_SET);

            foreach (string kks_name in kks_names)
            {
                try {
                    if (m_dictSignalsAdvised.ContainsKey(kks_name) == true)
                    {
                        return;
                    }
                    else
                    {
                        ;
                    }

                    err = m_torIsData.AdviseItems(kks_name);

                    if (!(err == 0))
                    {
                        switch ((ERROR)err)
                        {
                        case ERROR.ETORIS_NOTCONFIG:
                        case ERROR.ETORIS_INVALIDITEM:
                        case ERROR.ETORIS_INVALIDATTR:
                        case ERROR.ETORIS_INVALIDTYPE:
                        case ERROR.ETORIS_INVALIDHANDLE:
                        case ERROR.ETORIS_NOTREGISTER:
                        case ERROR.ETORIS_ALREADYADVISED:
                        case ERROR.ETORIS_INVALIDITEMTYPE:
                        case ERROR.ETORIS_SHUTDOWN:
                            strErr = ((ERROR)err).ToString();
                            break;

                        default:
                            strErr = "Неизвестная ошибка " + strErr.ToString();
                            break;
                        }

                        Logging.Logg().Error(@"Ошибка подписки на сигнал" + strIds + kks_name + " - " + strErr,Logging.INDEX_MESSAGE.NOT_SET);
                        continue;
                    }
                    else
                    {
                        ;
                    }

                    m_dictSignalsAdvised.Add(kks_name,idGrpSgnls);

                    Logging.Logg().Action(@"Подписка на сигнал" + strIds + kks_name,Logging.INDEX_MESSAGE.NOT_SET);

                    err = m_torIsData.ReadItem(kks_name,ref type,out value,out timestamp,out quality,out status);
                    if (!(err == 0))
                    {
                        Logging.Logg().Error(@"Ошибка вызова ReadItem для" + strIds + kks_name + " - " + err.ToString(),Logging.INDEX_MESSAGE.NOT_SET);
                        continue;
                    }
                    else
                    {
                        ;
                    }

                    torIsData_ItemSetValue(kks_name,type,value,timestamp,quality,status);
                } catch (Exception e) {
                    Logging.Logg().Exception(e,$@"[{strIds}, kks-code={kks_name}]",Logging.INDEX_MESSAGE.NOT_SET);
                }
            } // for

            Logging.Logg().Action($@"::groupSignals_OnEvtAdviseItem () - подписка завершена {strIds}, сигналов <{kks_names.Length}>...",Logging.INDEX_MESSAGE.NOT_SET);
        }