Hello,
We are developing an ACE module working on multiple PI-MDB contexts.
In this module, we need to add an annotation to the written value. To perform this task, we are using the UpdateValues method.
Here below is our procedure used to write to PI (this procedure is called from our ACE module):
Code:'Annotations Writing into PI.
Public Sub Write_Annotations(ByVal Passed_PIServer As Server, ByVal Passed_Tag As String, _
ByVal Passed_Timestamp As PITime, ByVal Passed_Value As String, _
ByVal Passed_AnnotationCollection As PIAnnotations)
'Variables.
Dim ObjPITag As PISDK.PIPoint
Dim MergeCst As PISDK.DataMergeConstants
Dim MyPIValues As New PISDK.PIValues
Dim MyPIValue As PISDK.PIValue
Dim MynvAtts As New PISDKCommon.NamedValues
Dim MynvAtt As PISDKCommon.NamedValue
Dim MynvCurrentAtt As PISDKCommon.NamedValue
Dim MyData As PISDK.PIData
Dim MyIPIData2 As PISDK.IPIData2
Dim AttrAnnotExisting As Boolean
'Init.
MergeCst = PISDK.DataMergeConstants.dmReplaceDuplicates
AttrAnnotExisting = False
'Set the PI Point object.
ObjPITag = Passed_PIServer.PIPoints(Passed_Tag)
'Get the data object for the tag.
MyData = ObjPITag.Data
MyPIValues.ReadOnly = False
'Test if there is at least one annotation (in the collection) to be associated to the PI value.
If Passed_AnnotationCollection.Count > 0 Then
'Test if the annotations flag is already declared.
If MyData.RetrievalAttributes.Count > 0 Then
For Each MynvCurrentAtt In MyData.RetrievalAttributes
If MynvCurrentAtt.Name = "Annotations" Then
AttrAnnotExisting = True
Exit For
End If
Next
End If
If AttrAnnotExisting = False Then
'Set the annotations flag.
MyData.RetrievalAttributes.Add("Annotations", 1)
End If
'Add the annotations collection to the value.
MynvAtt = MynvAtts.Add("Annotations", Passed_AnnotationCollection)
End If
MyPIValue = MyPIValues.Add(Passed_Timestamp, Passed_Value, MynvAtts)
'Add a value with annotations.
MyIPIData2 = MyData
MyIPIData2.UpdateValues(MyPIValues, MergeCst)
MyPIValues.ReadOnly = True
MynvAtts = Nothing
End Sub
In
debug mode (so with only one context), there is no problem. However, when we use the module with PI-ACE scheduler (with for example: 10 contexts), we get the following error “
The application called an interface that was marshalled for a different thread.”. This must be due to the fact that PI-SDK objects are instantiated Single Threaded Apartments.
In our case, how is-it possible to avoid / correct this error?
Thanks for your help
Regards
Gael