Customization > Automation Interface > Functions > Attribute Functions > GetAttribute2 function (automation interface)
GetAttribute2 function (automation interface)
Syntax:
GetAttribute2(<handle to listener dll>,<instance id>,"<class id>","<attribute>")
Where:
<handle to listenerdll> is a numeric value that specifies the handle to the listener.dll, which is returned by the CreateStateMachine and GetStateMachineHandle functions.
<instance id> is a numeric value that specifies the instance id of the state machine from which you want to get the Attribute value. The first instance is 1, second instance is 2, etc.
<class id> is a string that specifies the id of the Class that owns the state machine from which you want to get an Attribute value.
<attribute> is a string that specifies the name of the Attribute from which you want to get the value. Identifying attributes
This function returns as a string the value of an Attribute from a specific instance of a state machine.
The GetAttribute2 function replaces the GetAttribute function, which cannot work with different instances of a state machine.
Important:
The GetAttribute2 function returns "ART_DEFERRED" when the listener cannot retrieve the value in a timely manner; "ART_DEFERRED" is returned so as not to block the system. Shortly after returning "ART_DEFERRED", the Listener will typically retrieve the attribute value. The retrieved value is returned next time the GetAttribute2 function is used to get the attribute value, so it is important to repeat the GetAttribute2 function when "ART_DEFERRED" is returned.
The simplest way to process GetAttribute2 calls from an external application is to write a GetProperty function similar to this:
Private Function GetProperty(ByRef strPropertyName As String) As String
Dim attempts As Integer = 0
Dim strResult As String = "ART_DEFERRED"
Do Until strResult <> "ART_DEFERRED" Or attempts > 3
strResult = sim.GetAttribute2(hSM, InstanceId, strGUID, strPropertyName)
If strResult = "ART_DEFERRED" Then
'Pause for 1/10th of a second
attempts = attempts + 1
Sleep(100)
End If
Loop
GetProperty = strResult
End Function
In all but the most heavily loaded or high latency systems this preceding code should work successfully.
Examples
GetAttribute2 (57980432,1,"faa6c735-c46a-4c11-aa2f-3632ccc79d39","Status")