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); }
public void FireEvent(string pEventName, ICDEThing sender, object pPara, bool FireAsync) { if (MyBaseThing != null) { MyBaseThing.FireEvent(pEventName, sender, pPara, FireAsync); } }
public void ExecuteSimulation() { try { var timestamp = DateTimeOffset.Now; var dict = new Dictionary <string, object>(); dict["Timestamp"] = timestamp; foreach (var field in MyModFieldStore.TheValues) { double rndVal = TheCommonUtils.GetRandomDouble() * 1000.0; if (field.SourceType == "double") { dict[field.PropertyName] = rndVal; } else if (field.SourceType == "float") { dict[field.PropertyName] = rndVal; } } MyBaseThing.SetProperties(dict, timestamp); } catch (Exception) { // Console.WriteLine("Ignoring exception: " + ex.Message); //Console.WriteLine(ex.StackTrace); } }
private void CreateRule(string pFriendlyName, TheThing pTriggerThing, string pTriggerProperty, eRuleTrigger pTriggerCondition, string pTriggerValue, bool pDoLogRule, bool bIsRuleActive) { TriggerStartTime = DateTimeOffset.MinValue; TriggerEndTime = DateTimeOffset.MaxValue; //TriggerObjectType = "CDE_THING"; TriggerObject = pTriggerThing.cdeMID.ToString(); if (!TheCommonUtils.IsNullOrWhiteSpace(pTriggerProperty)) { TriggerProperty = pTriggerProperty; } else { pTriggerProperty = "Value"; } TriggerCondition = pTriggerCondition; TriggerValue = pTriggerValue; FriendlyName = pFriendlyName; IsRuleLogged = pDoLogRule; IsRuleActive = bIsRuleActive; if (string.IsNullOrEmpty(MyBaseThing.EngineName)) { MyBaseThing.EngineName = eEngineName.ThingService; } MyBaseThing.DeviceType = eKnownDeviceTypes.TheThingRule; MyBaseThing.ID = MyBaseThing.cdeMID.ToString(); RegisterEvent("RuleFired", null); MyBaseThing.SetIThingObject(this); }
public void UnregisterEvent(string pName, Action <ICDEThing, object> pCallBack) { if (MyBaseThing != null) { MyBaseThing.UnregisterEvent(pName, pCallBack); } }
public virtual bool Init(bool declareInit) { if (mIsInitCalled) { return(false); } mIsInitCalled = true; IsConnected = false; MyBaseThing.StatusLevel = 0; MyBaseThing.LastMessage = "Service is ready"; MyBaseThing.RegisterStatusChanged(sinkUpdateUX); MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); TheThing.SetSafePropertyBool(MyBaseThing, "IsStateSensor", true); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorType", "analog"); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorUnit", "ms"); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue", 100); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorAverage", 50); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMinValue", 0); //TheThing.SetSafePropertyString(MyBaseThing, "StateSensorName", MyBaseThing.FriendlyName); TheRulesFactory.CreateOrUpdateRule(new TheThingRule(Guid.NewGuid(), "NetService:" + MyBaseThing.FriendlyName + " Failed", MyBaseThing, "StatusLevel", eRuleTrigger.Larger, "1", true, true)); } if (declareInit) { mIsInitialized = true; } return(true); }
public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.StatusLevel = 4; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, sinkRegistered); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, sinkRegistered); if (EnableTracing) { Opc.Ua.Utils.SetTraceOutput(Utils.TraceOutput.FileOnly); Opc.Ua.Utils.SetTraceLog("opcclient.log", false); } else { Opc.Ua.Utils.SetTraceOutput(Utils.TraceOutput.Off); } if (EnableTracingToLog) { Opc.Ua.Utils.Tracing.TraceEventHandler += OnOpcLibraryTrace; } TheCommonUtils.cdeRunAsync("Init OPC Servers", true, (a) => { InitServers(); mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }); return(false); }
public override bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnDeletedThing); MyBaseEngine.RegisterEvent(eEngineEvents.ThingRegistered, OnThingRegistered); MyBaseEngine.RegisterEvent(eEngineEvents.ShutdownEvent, OnShutdown); TheCommonUtils.cdeRunAsync("Init Prometheus Exporters", false, (state) => { try { InitServers(); } catch (Exception e) { TheBaseAssets.MySYSLOG.WriteToLog(181001, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(MyBaseThing.EngineName, "Error initializing instances", eMsgLevel.l1_Error, e.ToString())); } mIsInitialized = true; FireEvent(eThingEvents.Initialized, this, true, true); MyBaseEngine.ProcessInitialized(); }, null); return(false); }
private void onPingTimeoutChanged(cdeP obj) { MyBaseThing.DeclareSensorProperty(nameof(RoundTripTime), ePropertyTypes.TNumber, new cdeP.TheSensorMeta { RangeMin = 0, RangeMax = PingTimeOut, Units = "ms" }); //MyBaseThing.DeclareSensorProperty(nameof(MyBaseThing.Value), ePropertyTypes.TNumber, new cdeP.TheSensorMeta { RangeMin = 0, RangeMax = PingTimeOut, Units = "ms" }); }
public override bool Init() { if (!mIsInitCalled) { mIsInitCalled = true; MyBaseThing.StatusLevel = 4; SetMessage("Service has started", DateTimeOffset.Now); MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); // If not lengthy initialized you can remove cdeRunasync and call this synchronously TheCommonUtils.cdeRunAsync(MyBaseEngine.GetEngineName() + " Init Services", true, (o) => { // Perform any long-running initialization (i.e. network access, file access) here that must finish before other plug-ins or the C-DEngine can use the plug-in InitServices(); // Declare the thing initialized mIsInitialized = true; // For future IsInit() calls FireEvent(eThingEvents.Initialized, this, true, true); // Notify the C-DEngine and other plug-ins that the thing is initialized MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages }); } return(false); }
void SetupModbusProperties(bool bReload, TheProcessMessage pMsg) { if (MyModConnectForm != null) { List <TheFieldInfo> tLst = TheNMIEngine.GetFieldsByFunc(s => s.FormID == MyModConnectForm.cdeMID); foreach (TheFieldInfo tInfo in tLst) { if (tInfo.FldOrder >= 600 && TheCommonUtils.CInt(tInfo.PropBagGetValue("ParentFld")) == 500) { TheNMIEngine.DeleteFieldById(tInfo.cdeMID); } } List <cdeP> props = MyBaseThing.GetPropertiesMetaStartingWith("MODPROP"); int fldCnt = 600; foreach (var p in props) { var field = MyModFieldStore.MyMirrorCache.GetEntryByFunc(s => s.PropertyName == p.Name); if (field != null) { TheNMIEngine.AddSmartControl(MyBaseThing, MyModConnectForm, eFieldType.SingleEnded, fldCnt++, field.AllowWrite ? 2 : 0, 0, p.Name, p.Name, new nmiCtrlSingleEnded() { TileWidth = 6, ParentFld = 500 }); } } MyModConnectForm.Reload(pMsg, bReload); } }
public cdeP SetProperty(string pName, object pValue) { if (MyBaseThing != null) { return(MyBaseThing.SetProperty(pName, pValue)); } return(null); }
public TheOPCUATagThing(TheThing pThing, TheOPCTag pTag) : base(pThing) { MyBaseThing.DeviceType = eOPCDeviceTypes.OPCLiveTag; Reset(); MyBaseThing.RegisterEvent("OnInitialized", sinkInit); MyBaseThing.SetIThingObject(this); }
public cdeP GetProperty(string pName, bool DoCreate) { if (MyBaseThing != null) { return(MyBaseThing.GetProperty(pName, DoCreate)); } return(null); }
public TheSineWave(TheThing pThing, IBaseEngine pEngine) : base(pThing) { MyBaseThing = pThing ?? new TheThing(); MyBaseEngine = pEngine; MyBaseThing.DeviceType = eVThings.eSineWave; MyBaseThing.EngineName = pEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); }
public bool HasRegisteredEvents(string pEventName) { if (MyBaseThing != null) { return(MyBaseThing.HasRegisteredEvents(pEventName)); } return(false); }
public TheVStateSensor(TheThing pThing, IBaseEngine pEngine) : base(pThing) { MyBaseThing = pThing ?? new TheThing(); MyBaseThing.DeviceType = eVThings.eVStateSensor; MyBaseThing.EngineName = pEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); }
public override bool Init() { if (!mIsInitStarted) { mIsInitStarted = true; MyBaseThing.StatusLevel = 4; MyBaseThing.LastMessage = "Logger Service has started"; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); MyBaseEngine.RegisterEvent(eEngineEvents.ThingDeleted, OnThingDeleted); cdeP tP = null; if (TheBaseAssets.MyServiceHostInfo.DisableConsole) { TheThing.SetSafePropertyBool(MyBaseThing, "DisableStandardLog", TheBaseAssets.MyServiceHostInfo.DisableConsole); } else { tP = GetProperty("DisableStandardLog", true); } tP.RegisterEvent(eThingEvents.PropertyChanged, sinkDisableChanged); if (TheCommonUtils.CBool(tP.ToString())) { TheBaseAssets.MyServiceHostInfo.DisableConsole = true; } if (TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat) { tP = TheThing.SetSafePropertyBool(MyBaseThing, "UseGELF", TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat); } else { tP = GetProperty("UseGELF", true); } tP.RegisterEvent(eThingEvents.PropertyChanged, sinkGELF); if (TheCommonUtils.CBool(tP.ToString())) { TheBaseAssets.MyServiceHostInfo.UseGELFLoggingFormat = true; } bool DoLogKPIs = TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("LogKPIs")); if (DoLogKPIs) { TheThing.SetSafePropertyBool(MyBaseThing, "LogKPIs", true); } TheQueuedSenderRegistry.RegisterHealthTimer(sinkTimer); // If not lengthy initialized you can remove cdeRunasync and call this synchronously TheCommonUtils.cdeRunAsync(MyBaseEngine.GetEngineName() + " Init Services", true, (o) => { // Perform any long-running initialization (i.e. network access, file access) here InitServices(); MyBaseEngine.ProcessInitialized(); //Set the status of the Base Engine according to the status of the Things it manages mIsInitCompleted = true; }); } return(false); }
public TheOPCUAMethodThing(TheThing pThing, string pEngineName) : base(pThing) { MyBaseThing.DeviceType = eOPCDeviceTypes.OPCMethod; MyBaseThing.EngineName = pEngineName; Reset(); MyBaseThing.RegisterEvent("OnInitialized", sinkInit); MyBaseThing.SetIThingObject(this); }
public override bool Init() { if (!mIsInitialized) { mIsInitialized = true; MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage); } return(true); }
private void sinkEngineShutdown(ICDEThing sender, object NOP) { if (MyServiceHealth != null) { MyServiceHealth.Shutdown(); } MyBaseThing.UnregisterEvent(eEngineEvents.ShutdownEvent, sinkEngineShutdown); MyBaseThing.UnregisterEvent(eEngineEvents.IncomingMessage, HandleMessage); //Event when C-DEngine has new Telegram for this service as a subscriber (Client Side) }
public override bool Delete() { MyBaseThing.UnregisterStatusChanged(sinkUpdateUX); GetProperty("StatusLevel", true).UnregisterEvent(eThingEvents.PropertyChanged, sinkUpdateUX); MyBaseThing.UnregisterEvent(eEngineEvents.IncomingMessage, HandleMessage); Disconnect(); mIsInitialized = false; return(true); }
public TheBitmapImage(TheThing tBaseThing, ICDEPlugin pPluginBase) { MyBaseThing = tBaseThing ?? new TheThing(); MyBaseEngine = pPluginBase.GetBaseEngine(); MyBaseThing.EngineName = MyBaseEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); MyBaseThing.DeviceType = eImageTypes.Bitmap; TheThing.SetSafePropertyBool(MyBaseThing, "IsCamera", true); }
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" }); }
public TheNMIElement(TheThing pThing, IBaseEngine pEngine) : base(pThing) { MyBaseThing = pThing ?? new TheThing(); MyBaseEngine = pEngine; MyBaseThing.DeviceType = eVThings.eNMIElement; MyBaseThing.EngineName = pEngine.GetEngineName(); MyBaseThing.SetIThingObject(this); TheBaseEngine.WaitForEnginesStarted(sinkUpdateControls); }
public override bool DoInit() { base.DoInit(); IsActive = false; TheThing.SetSafePropertyBool(MyBaseThing, "IsStateSensor", true); MyBaseThing.StatusLevel = 4; if (string.IsNullOrEmpty(MyBaseThing.ID)) { MyBaseThing.ID = Guid.NewGuid().ToString(); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorType", "analog"); TheThing.SetSafePropertyString(MyBaseThing, "StateSensorUnit", "units"); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMaxValue", 100); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorAverage", 50); TheThing.SetSafePropertyNumber(MyBaseThing, "StateSensorMinValue", 0); TheThing.SetSafePropertyNumber(MyBaseThing, "Interval", 500); } TheThing.SetSafePropertyString(MyBaseThing, "StateSensorIcon", "/P066/Images/iconVThingsRest.png"); GetProperty("FriendlyName", true).RegisterEvent(eThingEvents.PropertyChanged, sinkNameChanged); cdeP tRW = GetProperty("RawValue", true); tRW.RegisterEvent(eThingEvents.PropertyChanged, sinkPrePro); cdeP.SetSafePropertyBool(tRW, "IsStateSensor", true); cdeP.SetSafePropertyString(tRW, "StateSensorType", "analog"); cdeP.SetSafePropertyString(tRW, "StateSensorUnit", "°F"); cdeP.SetSafePropertyNumber(tRW, "StateSensorMaxValue", 100); cdeP.SetSafePropertyNumber(tRW, "StateSensorAverage", 50); cdeP.SetSafePropertyNumber(tRW, "StateSensorMinValue", 0); if (!string.IsNullOrEmpty(TheThing.GetSafePropertyString(MyBaseThing, "RealSensorThing")) && !string.IsNullOrEmpty(TheThing.GetSafePropertyString(MyBaseThing, "RealSensorProperty"))) { EngageMapper(); } GetProperty("IsGlobal", true).RegisterEvent(eThingEvents.PropertyChanged, (p) => { if (TheCommonUtils.CBool(p.ToString())) { TheThingRegistry.RegisterThingGlobally(MyBaseThing); } else { TheThingRegistry.UnregisterThingGlobally(MyBaseThing); } }); GetProperty("Interval", true).RegisterEvent(eThingEvents.PropertyChanged, (p) => { changeInterval(TheCommonUtils.CInt(p.ToString())); }); MyBaseThing.SetPublishThrottle((int)TheThing.GetSafePropertyNumber(MyBaseThing, "Interval")); //TheQueuedSenderRegistry.RegisterHealthTimer(checkMapperHealth); return(true); }
public override bool Init() { if (!mIsInitCalled) { mIsInitCalled = true; MyBaseThing.RegisterEvent(eEngineEvents.FileReceived, sinkFileReceived); MyBaseThing.LastMessage = "Thing has started"; MyBaseThing.StatusLevel = 1; mIsInitialized = true; } return(true); }
public override cdeP SetProperty(string pName, object pValue) { if (MyBaseThing != null) { if (pName == "LastMessage") { SetLastMessage(TheScopeManager.GetTokenFromScrambledScopeID(), pValue.ToString()); } return(MyBaseThing.SetProperty(pName, pValue)); } return(null); }
public cdeP SetProperty(string pName, object pValue) { if (MyBaseThing != null) { if (pName.ToLower() == "logvisitor" && MyVisitorLog != null && pValue != null && TheCommonUtils.CGuid(pValue) == Guid.Empty) //Visitors Log - Requires StorageEngine { MyVisitorLog.LogVisitor(pValue.ToString(), "CMyVisitorLog SetP"); } return(MyBaseThing.SetProperty(pName, pValue)); } return(null); }
public TheSMSMessage(TheThing tBaseThing, ICDEPlugin pPluginBase) { if (tBaseThing != null) { MyBaseThing = tBaseThing; } else { MyBaseThing = new TheThing(); } MyBaseEngine = pPluginBase.GetBaseEngine(); MyBaseThing.SetIThingObject(this); }