Using AsyncMode
AsyncMode allows you to execute Spel methods while other methods are executing. Only the following Spel class methods are allowed to execute asynchronously:
Using AsyncMode
Arc | Jump3 |
Arc3 | Jump3CP |
BGo | MCal |
BMove | Move |
CVMove | Pass |
Go | PTran |
Home | Pulse |
JTran | TGo |
Jump | TMove |
To execute a method asynchronously, set the AsyncMode property to True, then execute the method. When the AsyncMode property is true and you execute an asynchronous method, the method will be started and control will return immediately back to the .NET application for further processing. If you execute another asynchronous method while a previous one is executing, SPEL will wait for the first method to complete, then start the next method and return back to .NET.
To wait for an asynchronous method to complete, you can use one of the following:
- Execute the WaitCommandComplete method.
- Set AsyncMode property to False.
If an asynchronous command cannot be started due to an error (e.g. point does not exist), then an exception will occur immediately. However, if an error occurs during a command running asynchronously, the error exception occurs on the next execution of an asynchronous command or execution of WaitCommandComplete, or AsyncMode is set to False. If the exception occurs on the next command, you do not know which statement caused the error (the previous statement or the current statement). If you need to check if an asynchronous command completed successfully before executing another command, then call WaitCommandComplete before the next command. If an error occurred during the previous asynchronous command, a SpelException exception will occur with the error number and message. See the example below.
VB Example:
Try
m_spel.AsyncMode = True
m_spel.Go(1)
' do other things here during motion
' When Go(2) executes, an exception occurs if Go(1) had an error during execution,
' so we don't know if error occurred for Go(1) or Go(2)
m_spel.Go(2)
m_spel.Go(3)
' do other things here during motion
' Check if Go(3) was successful
m_spel.WaitCommandComplete() ' Exception occurs if Go(3) had an error
m_spel.Go(4)
Catch ex As SpelException
' Handle the error exception
End Try
C# Example:
try {
m_spel.AyncMode = true;
m_spel.Go(1);
//do things here during motion
//When Go(2) executes, an exception occurs if Go(1) had an error during execution,
//so we don’t know if error occurred for Go(1) or Go(2)
m_spel.Go(2);
m_spel.Go(3);
//do things here during motion
//Check if Go(3) was successful
m_spel.WaitCommandComplete();
//Exception occurs if Go(3) had an error
m_spel.Go(4);
}
catch(RCAPINet.SpelException ex) {
//Handle the error exception
}