Ejemplo n.º 1
0
        bool Connect(TheProcessMessage pMsg)
        {
            bool bSuccess = false;

            try
            {
                MyBaseThing.StatusLevel = 4; // ReaderThread will set statuslevel to 1
                foreach (var field in MyModFieldStore.TheValues)
                {
                    var p = MyBaseThing.GetProperty(field.PropertyName, true);
                    p.cdeM = "MODPROP";
                    p.UnregisterEvent(eThingEvents.PropertyChangedByUX, null);
                    p.RegisterEvent(eThingEvents.PropertyChangedByUX, sinkPChanged);
                }
                SetupModbusProperties(true, pMsg);
                IsConnected             = true;
                MyBaseThing.LastMessage = $"{DateTime.Now} - Device Connecting";
                TheBaseAssets.MySYSLOG.WriteToLog(10000, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM(MyBaseThing.EngineName, MyBaseThing.LastMessage, eMsgLevel.l4_Message));
                TheCommonUtils.cdeRunAsync($"ModRunThread{MyBaseThing.FriendlyName}", true, (o) =>
                {
                    ReaderThread();
                });
                bSuccess = true;
            }
            catch (Exception e)
            {
                MyBaseThing.StatusLevel = 3;
                string error = $"Error connecting: {e.Message}";
                MyBaseThing.LastMessage = $"{DateTimeOffset.Now}: {error}";
                TheBaseAssets.MySYSLOG.WriteToLog(10000, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseThing.EngineName, error, eMsgLevel.l1_Error, e.ToString()));
                IsConnected = false;
            }
            return(bSuccess);
        }
Ejemplo n.º 2
0
 private void SetPropertyIfNotExist(string propName, object defaultValue, bool setAlways = false)
 {
     if (setAlways || MyBaseThing.GetProperty(propName) != null)
     {
         MyBaseThing.SetProperty(propName, defaultValue);
     }
 }
Ejemplo n.º 3
0
 public cdeP GetProperty(string pName, bool DoCreate)
 {
     if (MyBaseThing != null)
     {
         return(MyBaseThing.GetProperty(pName, DoCreate));
     }
     return(null);
 }
Ejemplo n.º 4
0
        private void ShowKPI(int pFldOrder, string pLabel, string pUpdName, int MaxVal = 100, int AveVal = 50, string pUnits = "bytes")
        {
            TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.TileGroup, pFldOrder, 0, 0, null, null, new nmiCtrlTileGroup {
                ParentFld = 300, TileWidth = 6
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.SmartLabel, pFldOrder + 1, 0, 0, null, null, new nmiCtrlSmartLabel {
                ParentFld = pFldOrder, Text = pLabel, NoTE = true, TileFactorY = 2, TileHeight = 1, TileWidth = 5, ClassName = "cdeTileGroupHeaderSmall"
            });
            var tBut = TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.TileButton, pFldOrder + 2, 2, 0, "V-Tise", null, new nmiCtrlTileButton {
                ParentFld = pFldOrder, NoTE = true, TileFactorY = 2, TileHeight = 1, TileWidth = 1, ClassName = "cdeGlassButton"
            });

            tBut.RegisterUXEvent(MyBaseThing, eUXEvents.OnClick, $"But{pUpdName}", (sender, para) =>
            {
                TheThing tT = TheThingRegistry.GetThingByID(MyBaseEngine.GetEngineName(), $"ISO{MyBaseThing.cdeMID}:{pUpdName}");
                if (tT == null)
                {
                    TheKPIReport tRep = new TheKPIReport(null, MyPlugin);
                    TheThing.SetSafePropertyGuid(tRep, "RealSensorThing", MyBaseThing.cdeMID);
                    tRep.GetBaseThing().ID = $"ISO{MyBaseThing.cdeMID}:{pUpdName}";
                    MyBaseThing.GetProperty(pUpdName, true);
                    TheThing.SetSafePropertyString(tRep, "RealSensorProperty", pUpdName);
                    TheThing.SetSafePropertyNumber(tRep, "StateSensorMaxValue", MaxVal);
                    TheThing.SetSafePropertyNumber(tRep, "StateSensorAverage", AveVal);
                    TheThing.SetSafePropertyNumber(tRep, "StateSensorSteps", MaxVal / 15);
                    TheThing.SetSafePropertyString(tRep, "StateSensorValueName", pLabel);
                    TheThing.SetSafePropertyString(tRep, "StateSensorUnit", pUnits);
                    TheThing.SetSafePropertyString(tRep, "FriendlyName", MyBaseThing.FriendlyName);
                    TheThing.SetSafePropertyString(tRep, "ReportName", $"ISO-KPI: {MyBaseThing.FriendlyName} - {pLabel}");
                    TheThing.SetSafePropertyString(tRep, "ReportCategory", "ISO KPI Reports");
                    ThePluginInfo tI = MyPlugin.GetBaseEngine().GetPluginInfo();
                    if (tI != null)
                    {
                        TheThing.SetSafePropertyString(tRep, "SerialNumber", TheCommonUtils.CStr(tI.CurrentVersion));
                        TheThing.SetSafePropertyString(tRep, "VendorName", TheCommonUtils.CStr(tI.Developer));
                        TheThing.SetSafePropertyString(tRep, "ProductName", TheCommonUtils.CStr(tI.ServiceDescription));
                        TheThing.SetSafePropertyString(tRep, "ProductText", TheCommonUtils.CStr(tI.LongDescription));
                        TheThing.SetSafePropertyString(tRep, "VendorText", TheCommonUtils.CStr(tI.DeveloperUrl));
                        TheThing.SetSafePropertyString(tRep, "ProductID", TheCommonUtils.CStr(tI.cdeMID));
                    }
                    TheThingRegistry.RegisterThing(tRep);
                    MyBaseEngine.ProcessMessage(new TheProcessMessage(new TSM(MyBaseEngine.GetEngineName(), "REFRESH_DASH")));
                }
                else
                {
                    TheCommCore.PublishToOriginator((para as TheProcessMessage).Message, new TSM(eEngineName.NMIService, "NMI_TTS", tT.cdeMID.ToString()));
                }
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.SmartLabel, pFldOrder + 3, 0, 0, null, pUpdName, new nmiCtrlSingleEnded {
                ParentFld = pFldOrder, TileWidth = 2
            });
            TheNMIEngine.AddSmartControl(MyBaseThing, mMyForm, eFieldType.BarChart, pFldOrder + 4, 0, 0, null, pUpdName, new nmiCtrlBarChart()
            {
                ParentFld = pFldOrder, MaxValue = MaxVal, TileWidth = 4, NoTE = true, Foreground = "blue"
            });
        }
Ejemplo n.º 5
0
        public override bool DoInit()
        {
            if (MyBaseThing.StatusLevel != 1)
            {
                MyBaseThing.LastMessage = "Tag Ready";
                MyBaseThing.StatusLevel = 0;
            }
            cdeP Mon = MyBaseThing.GetProperty("DontMonitor", true);

            Mon.RegisterEvent(eThingEvents.PropertyChanged, sinkPChanged);
            MyBaseThing.RegisterEvent(eThingEvents.PropertyChanged, sinkUXUpdatedThing);
            MyBaseThing.RegisterEvent(eThingEvents.ValueChanged, sinkRulesUpdatedThing);
            return(true);
        }
Ejemplo n.º 6
0
 public cdeP GetProperty(string pName, bool DoCreate)
 {
     return(MyBaseThing?.GetProperty(pName, DoCreate));
 }
Ejemplo n.º 7
0
        private void sinkInit(ICDEThing sender, object pPara)
        {
            if (string.IsNullOrEmpty(MyBaseThing.ID))
            {
                MyBaseThing.ID = Guid.NewGuid().ToString();
            }

            if (m_Method != null)
            {
                if (m_Method.MyOPCServer == null)
                {
                    return;
                }
                if (string.IsNullOrEmpty(MyBaseThing.Address))
                {
                    MyBaseThing.Address = string.Format("{2}:;:{0}:;:{1}", m_Method.ParentId, m_Method.TagRef, m_Method.MyOPCServer.GetBaseThing().ID);
                    FormTitle           = "OPC UA Method: " + m_Method.DisplayName;
                    TileWidth           = 3;
                    TileHeight          = 1;
                    Flags    = 0;
                    FldOrder = 0;
                }
                if (string.IsNullOrEmpty(MyBaseThing.FriendlyName))
                {
                    MyBaseThing.FriendlyName = m_Method.DisplayName;
                }
                if (ControlType == "")
                {
                    ControlType = ((int)eFieldType.SingleEnded).ToString();
                }

                m_Method.MyBaseThing   = this.MyBaseThing;
                ServerID               = m_Method.MyOPCServer.GetBaseThing().ID;
                ServerName             = m_Method.MyOPCServer.GetBaseThing().FriendlyName;
                MyBaseThing.EngineName = m_Method.MyOPCServer.GetBaseThing().EngineName;

                lock (m_Method)
                {
                    if (m_Method.Args != null)
                    {
                        int tInputArgCnt  = 0;
                        int tOutputArgCnt = 0;
                        InputArgs  = new List <TheOPCProperties>();
                        OutputArgs = new List <TheOPCProperties>();
                        foreach (TheOPCTag tTag in m_Method.Args)
                        {
                            foreach (TheOPCProperties tpro in tTag.PropAttr)
                            {
                                cdeP pProp = MyBaseThing.GetProperty(tpro.BrowseName, false);
                                if (pProp == null)
                                {
                                    MyBaseThing.SetProperty(tpro.BrowseName, tpro.Value == null ? "" : tpro.Value.WrappedValue.ToString(), tpro.DataType);
                                }
                                else
                                {
                                    pProp.cdeT = (int)tpro.DataType;
                                    if (tpro.Value != null)
                                    {
                                        pProp.Value = tpro.Value.WrappedValue.ToString();
                                    }
                                }
                                if (tTag.BrowseName == "InputArguments")
                                {
                                    tInputArgCnt++;
                                    tpro.cdeProperty = pProp;
                                    InputArgs.Add(tpro);
                                }
                                else if (tTag.BrowseName == "OutputArguments")
                                {
                                    tOutputArgCnt++;
                                    tpro.cdeProperty = pProp;
                                    OutputArgs.Add(tpro);
                                }
                            }
                        }
                        bool ForceUX = false;
                        if (InputArgCnt != tInputArgCnt)
                        {
                            InputArgCnt = tInputArgCnt;
                            ForceUX     = true;
                        }
                        if (OutputArgCnt != tOutputArgCnt)
                        {
                            ForceUX      = true;
                            OutputArgCnt = tOutputArgCnt;
                        }
                        if (ForceUX || !IsDynUXCreated)
                        {
                            CreateDynUX(ForceUX);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void sinkInit(ICDEThing sender, object pPara)
        {
            if (SampleRate > 0 && SampleRate < 50)
            {
                SampleRate = 50;
            }
            if (string.IsNullOrEmpty(MyBaseThing.ID))
            {
                MyBaseThing.ID = Guid.NewGuid().ToString();
            }

            if (m_Tag != null)
            {
                if (string.IsNullOrEmpty(MyBaseThing.Address))
                {
                    MyBaseThing.Address = string.Format("{0}:;:{1}", m_Tag.Parent, m_Tag.NodeIdName);
                    FormTitle           = "My OPC Tags";
                    TileWidth           = 3;
                    TileHeight          = 1;
                    Flags      = 0;
                    FldOrder   = 0;
                    SampleRate = m_Tag.SampleRate;
                }
                if (string.IsNullOrEmpty(MyBaseThing.FriendlyName))
                {
                    MyBaseThing.FriendlyName = m_Tag.DisplayName;
                }

                if (ControlType == "")
                {
                    ControlType = ((int)eFieldType.SingleEnded).ToString();
                }
                if (m_Tag.PropAttr != null)
                {
                    foreach (TheOPCProperties tpro in m_Tag.PropAttr)
                    {
                        if (tpro.BrowseName == "Value")
                        {
                            continue;
                        }
                        cdeP pProp = MyBaseThing.GetProperty(tpro.BrowseName, false);
                        if (pProp == null)
                        {
                            MyBaseThing.SetProperty(tpro.BrowseName, tpro.Value.WrappedValue.ToString(), tpro.DataType);
                        }
                        else
                        {
                            pProp.Value = tpro.Value.WrappedValue.ToString();
                        }
                    }
                }
                m_Tag.MyBaseThing = this.MyBaseThing;
                if (m_Tag.MyOPCServer != null)
                {
                    ServerID   = m_Tag.MyOPCServer.GetBaseThing().ID;
                    ServerName = m_Tag.MyOPCServer.GetBaseThing().FriendlyName;
                    m_Tag.MyOPCServer.GetBaseThing().RegisterEvent("DisconnectComplete", sinkDisconnected);
                    MyBaseThing.EngineName = m_Tag.MyOPCServer.GetBaseThing().EngineName;
                    var subscription = m_Tag.MyOPCServer.GetOrCreateSubscription(m_Tag.SampleRate);
                    if (subscription != null)
                    {
                        string error;
                        TheBaseAssets.MySYSLOG.WriteToLog(78102, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM(MyBaseThing.EngineName, $"Tag init for tag {m_Tag}", eMsgLevel.l4_Message, ""));
                        m_Tag.MonitorTag(subscription, out error);
                        MyBaseThing.LastMessage = "Tag alive";
                        MyBaseThing.StatusLevel = 1;
                    }
                }
            }
        }