Running Vision Sequences from SPEL+: VRun

You can run any vision sequence in the current project from a SPEL+ program using the VRun command. For example:

Function VisionTest  
  
  VRun seq1  
Fend  

The simple program above will run the sequence called “seq1” and display the graphical results on the Run window or Operator window, depending on where the program is started from.
The actions taken by VRun depend on the RuntimeAcquire sequence property. This property determines if a picture is taken or not before processing the sequence or if a strobe trigger is being used. The table below shows what happens when VRun executes for the different settings of RuntimeAcquire.

RuntimeAcquire VRun Actions Usage
0 - None

Do not take picture.

Use previous picture.

Run each sequence step.

Allows more than one sequence to run on the same picture. Normally, the first sequence takes the picture with RuntimeAcquire set to Stationary. Then the remaining sequences do not take a picture.
1 - Stationary

Acquire new picture.

Run each sequence step.

Default. This is the most common way to use VRun. Take a picture and run the sequence.
2 - Strobed

Wait for strobe input.

Acquire new picture.

Run each sequence step.

Used with strobe input. VRun will return immediately, then the system will wait for strobe trigger before taking a picture and running the sequence.

When the sequence property AsyncMode is True, VRun returns after the camera exposure, and continues in the background to finish the image grab, and then process the sequence. The next vision command for the same sequence, such as VGet, will automatically wait for processing to finish.
When RuntimeAcquire is set to Strobe, VRun arms the trigger, then returns. The system waits in the background for the trigger to fire and grab the image, then the sequence is processed.
You may want to wait for the grab to be completed before you retrieve results from the sequence. You can do this by checking the AcquireState sequence result.

Function VisionTest  
Integer state  
Boolean passed  
VRun strobedSequence  
' Wait for image to be grabbed  
Do  
  VGet strobedSequence.AcquireState, state  
Loop Until state = 3  
' Now retrieve the results  
VGet strobedSequence.AllPassed, passed  
Fend  

If you execute VRun with RuntimeAcquire = Strobe, and then you execute a second vision command, such as VGet, without waiting for AcquireState =3, then the second command will wait until the trigger is received and the sequence runs. If the trigger is never received, the SPEL+ task will have to be aborted.
When you run multiple SPEL+ tasks that run vision sequences, the images are grabbed and the sequences are processed in parallel if the cameras are not the same.
If multiple SPEL+ tasks use the same camera and RuntimeAcquire is set to Strobe, then you must only allow one sequence to process at a time using SyncLock and SyncUnlock. In the example below, sequences seq1 and seq2 both use camera 1.

Function visTask1  
  Integer state  
  Do  
    SyncLock 1 ' lock access to camera 1  
    VRun seq1  
    Do  
      VGet seq1.AcquireState, state  
    Loop Until state = 3  
    VGet <some results here>  
    SyncUnlock 1 ' unlock camera 1 access  
Fend  
  
Function visTask2  
  Integer state  
  Do  
    SyncLock 1 ' lock access to camera 1  
    VRun seq2  
    Do  
      VGet seq2.AcquireState, state  
    Loop Until state = 3  
    VGet <some results here>  
    SyncUnlock 1 ' unlock camera 1 access  
Fend  

For details on SyncLock and SyncUnlock, refer to the SPEL+ Language Reference Manual.

KEY POINTS


To use an ac2500-14gm/gc GigE camera in strobe mode (external trigger mode), an external strobe light is necessary.

If the strobe light is not used, the camera works in the rolling shutter mode and cannot recognize moving objects correctly.