Associates a thread event with a latch result queue.
Latch.ThreadEvent( robot ) = event_mask
-or-
…Latch.ThreadEvent(robot )
Prerequisites
Requires that the Encoder Latching or Advanced Controls or Conveyor Tracking License be installed on the controller.
Parameters
robot
An optional numeric expression that specifies the robot queue to be accessed. If not specified, a default value of 1 is assumed.
Remarks
This property associates an event for the current thread with the latch result queue specified by the robot parameter. Setting a value of zero cancels any event assignment in effect. Only one thread may have events associated with a specific latch result queue. The last thread to set this property gets the assignment.
The get property returns the mask for any current event assignment. A value of zero indicates no assignment is in effect.
The event_mask is described in the dictionary page for the thread_object.SendEvent method.
When an event mask is defined, an event is sent to the thread that set the Latch.ThreadEvent property whenever:
- The ThreadEvent property is set, and the latch queue is not empty.
- A new latch result is added to the latch queue.
A thread can efficiently wait for latch results by using the Thread.WaitEvent method.
It is possible for more than one latch result to be placed in the queue when an event is set. It is also possible for a thread event to be sent even when no items are placed in the queue. It should not be assumed that there is a single latch result ready just because an event is received. Verify that a latch result is present by using the Latch.Count property or checking if the Latch.Result returns Nothing.
Examples
Dim lat As Latch
Latch.ThreadEvent(1) = 1 ' Send event 1 to current thread
While True
Thread.WaitEvent(1, -1) ' Wait for event 1
lat = Latch.Result(1)
While Not lat Is Nothing
Console.WriteLine(CStr(lat.Signal) & ": " & _
CStr(lat.Timestamp) & ", " & _
CStr(lat.Angle(1)))
lat = Latch.Result(1)
End While
End While
See Also