You should be able to use AddPIACEContextSchedule method. But please note that this is not a documented feature and may not continue in some future versions.
Adds or modifies the scheduling information for a context in an ACE module.
AddPIACEContextSchedule (ContextPath, ScheduleInfo)
ContextPath: Full path string for the context
ScheduleInfo: Namedvalues collection containing the scheduling information. It should contain the schedule type, priority, and offset and period for clock-scheduled calculations or latency and trigger tags, which must be identified by "Tag1", "Tag2", etc., for natural-scheduled calculations.
It is important to identify the values in the Namedvalues collection by proper names: the schedule type by gcstrType, the priority by gcstrPriority, the offset by gcstrOffset, the period by gcstrPeriod, and the latency by gcstrLatency.
The function returns True if successful and False if failed. The error message can be retrieved by calling GetLastPIACECommonError.
Dim ScheduleInfo as New NamedValues Dim ContextPath as String ContextPath = "Localhost\ACEExe1\ACEModule1\ACEContext1" ScheduleInfo.Add gcstrType, stClockScheduled ScheduleInfo.Add gcstrPeriod, 60 ScheduleInfo.Add gcstrOffset, 0 ScheduleInfo.Add gcstrPriority, pcNormal If Not AddPIACEContextSchedule(ContextPath, ScheduleInfo) Then Debug.Print GetLastPIACECommonError End If
Imports PISDKCommon Imports OSIsoft.PI.ACE Imports OSIsoft.PI.ACE.PIACENetInternalFunctions.PIACEMDBFunctions Dim mdbFunc As New PIACEMDBFunctions Dim ScheduleInfo As New NamedValues Dim ContextPath As String ContextPath = "myserver\myexe\myclass\\\myserver\mycontextmodule" ScheduleInfo.Add("Priority", 3) ScheduleInfo.Add("Type", 1) ScheduleInfo.Add("Latency", 15) ScheduleInfo.Add("Tag1", "cdm158") Try mdbFunc.AddPIACEContextSchedule(ContextPath, ScheduleInfo) Catch ex As Exception Debug.WriteLine(ex.Message) End Try
Constant, Value, Description
stScheduleNotSet, -1, Schedule type has not been set
stClockScheduled, 0, Clock scheduled calculations
stNaturalScheduled, 1, Natural scheduled calculations
Constant, Value, Description
pcHigh, 1, ACE Context has the highest priority
pcAboveNormal, 2, ACE Context has the above-normal priority
pcNormal, 3, ACE Context has the normal priority
pcBelowNormal, 4, ACE Context has the below-normal priority
pcLow, 5, ACE Context has the lowest priority
Hope it helps!
Thank you Ahmad. it really helped.
Thanks for closing the loop Kireet and glad we could help
This is a useful function.if you have to add a context via code.
We have a situation, where we need to know if a context is naturally scheduled or if it is clock scheduled. The underlying code will output the values at different timestamps for naturally scheduled calculations and clock scheduled calculations.
Is there a possiblity to use ScheduleInfo Object to "get" the schedule info of current context?..
Appreciate your help.
Yes, it is possible to do that. However, you will also need to use the functionality of PISDK for that in order to access the MDB. As an example, this will retrieve the trigger tag for Context1 of my ACE module.
Dim scheduler As PIModule = GetSchedulerModule("eugeneaf", "default") Dim m As PIModule = scheduler.PIModules("exe").PIModules("classmod").PIModules("Context1") Dim s As String = m.PIProperties("ScheduleInfo").PIProperties("Tag1").Value Debug.Print(s)
Thank you for the quick response.
I tried your code out, but it threw an error saying that the object is not found in collection.
I am assuming that, the "context1" in your code refers to the internal context naming that PI ACE does?... how can it be mapped from the context Path that we get from Mybase.Context to the internal naming like "Context1", "Context2" ,.. etc
Basically, our calculation has about 45 contexts, out of which about 20 are naturally scheduled, the only information that we get inside ACECalculations() sub is "mybase.context", we need to get scheduling information using this.
Is there any way to do that?
First, verify all the parameters are correct. In my case,
eugeneaf = PI Server
default = Name of the ACE Scheduler
exe = Name of ACE executable
classmod = Name of ACE module
I think that Context1 is hardcoded similar to how Tag1 is as Ahmad mentioned in his post above ("which must be identified by "Tag1", "Tag2""). However, it is possible to map this to "mybase.context". The way I would do it is to loop through the 45 contexts that you have. Within the loop, you can have an IF statement to check for one of the PIProperties which should correspond to "mybase.context". Once you found that, then you can return the results as a PIModule and then continue using this PIModule to get the scheduling information that you desire.
Even I thought of looping through the 45 odd contexts to find the right one. But I thought it may cause unnecessary load each time a context is executed.
Hence, I decided against it, - instead created another class module, and put all naturally scheduled calculations into that class module.
So basically, I have two sets of similar (almost same) code now, one for naturally scheduled (driven by Manual entry) and another for clock scheduled
I had a deadline to meet, so went for this solution... maybe next time, I will go for the looping solution.
Best would be if ACE can tell directly if a context is naturally scheduled similar to IsRecalculating or IsTrigger flags.. .. if there is an IsNaturallyScheduled flag, it would have been pretty straightforward for my requirement ..
Thank you very much for your help!
Sorry for replying a little late but you or other users may find the information useful.
OSI.PI.ACE namespace has a PIACEScheduleInfo object but the use is intended for internal purposes. One can create a new instance of PIACEScheduleInfo but I wasn't able to assign a reference to the current classes context.
We have internal (not publicly visible) enhancement request 18157OSI8 about offering the ScheduleInfo publicly, so users could use it within their ACE code to retrieve schedule information during runtime. It's however very unlikely that the enhancement will ever be implemented. PI ACE has a heritage. Current development efforts focus on PI Asset Based Analytics. There's no further release scheduled for PI ACE. Please also refer to the PI System Roadmap.
This said, reading the scheduler info from Module Database is so far the only known workaround. Since changing the schedule requires a restart, it's not necessary to lookup the information with every execution. Doing this in the
ModuleDependentInitialization and storing the result in a local variable inside the class should suffice.
Unfortunately Me.Context contains context information but doesn't reference where in PI Module Database PI ACE is maintaining the schedule (\\<Servername>\%OSI\<ACESchedulerVersion>\<SchedulerName>\<ExecutableName>). The structure can be quite complex especially since multiple (redundant) ACE Schedulers can be installed in parallel with the latest release (PI ACE 2010 R2 SP1 (2.1.50)). A universal code would need to browse the MDB structure underneath %OSI until the correct context is found.
Another possible approach is checking each Input of an ACE Calculation for the IsTrigger property. If none of the points has triggered the actual calculation, it will be clock scheduled. When the amount of IsTrigger is 1 or greater (I expect it to be either 0 or 1), the calculation will be naturally scheduled or clock scheduled and with natural scheduling set up for recalculation. Because of this one may want to first verify if the current execution is a recalculation. Please see below example
Public Overrides Sub ACECalculations() Dim iTriggerCount As Integer = 0 If (IsRecalculating) Then ' Your code for triggered recalculations Else If (IsManualRecalculating) Then ' Your code for manual recalculation (initiated through PI ACE Manager) Else If (Input1.IsTrigger()) Then iTriggerCount = iTriggerCount + 1 If (Input1.IsTrigger()) Then iTriggerCount = iTriggerCount + 1 If iTriggerCount > 0 Then ' Your code for a Natural schedule Else ' Your code in case of clock schedule End If End If End If End Sub
Thank you for your detailed reply!.
I hope PI ACE is supported by OSISoft for some more time - basically what we like about ACE is the flexiblity to change output timestamp and the ability to recalculate manually as well automatically.
We have used Asset Based Analytics (ABA) in one of our recent projects, but still I could not fully use them for reporting type of calculations( the one's were some inputs are manually driven, and we have to do YTD and MTD aggregation) .. I did put all process calculations in ABACUS, and templatization feature has come in real handy!. So I see why it is the future calculation engine for PI.
Your logic to detect if its a naturally triggered calculation using IsTrigger is quite helpful. Thank you for sharing it!.
For now, I have gone on to use two seperate set of codes, but I will definitely refer to your solution next time.