YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

PI-ACE and PI-SDK (interface marshalled for a different thread) Options · View
Gael
#1 Posted : Wednesday, September 01, 2010 12:03:20 AM
Rank: Newbie
Groups: Member

Joined: 8/31/2010
Posts: 1
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
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.