5. Executing Methods, Programs, Tasks
EPSON RC+ 7.0 option RC+ API 7.0 Rev.16 9
5. Executing Methods, Programs, Tasks
5.1 Executing Methods
There are several methods in the Spel class. For descriptions of available methods, see the
section 14.3 Spel Class Methods. When you execute a method, the associated internal
functions are called in the EPSON RC+ server process, which in turn communicates with the
Controller to execute the associated function. There are two types of methods: immediate and
asynchronous. For immediate methods, the internal function is executed in the Controller and
the reply is returned immediately. Immediate commands include all I/O commands. For
asynchronous methods, the associated function is started in the Controller, and then the Spel
class instance waits for an event from the EPSON RC+ server process indicating that the
function has completed. Asynchronous methods include all robot motion commands. While
waiting for command completion, the Spel class instance dispatches Windows events, so that
the user GUI is still responsive. For example, when the Go method is called, the robot is
moving to a point, and the user may want to stop it by clicking a button. You can disable
Windows event dispatching during asynchronous methods by setting DisableMsgDispatch to
True. You can also wait for asynchronous methods to finish in your program by setting
AsyncMode to True.
5.1.1 Using Multiple Threads
You can execute Spel methods in multiple threads in your application. The sections below
describe the various scenarios.
One Spel class instance used in multiple threads
You can execute methods with the same Spel class instance in multiple threads, but only one
asynchronous command at a time. If you attempt to execute an asynchronous command in one
thread while another asynchronous command is already executing in another thread, you will
get a “command in cycle” error. You can execute an immediate command in one thread while
executing an asynchronous command in another thread.
Separate Spel class instance used in each thread
For each Controller connection, you can have one or more Spel class instances. The first
instance for each Controller initializes an EPSON RC+ 7.0 server process and connects to the
specified Controller. To use one or more additional instances in other threads to communicate
with the same Controller, you must specify the ServerInstance property to be the same value.
You call Initialize for the first instance before using additional Spel class instances.
' Initialize Spel class instance for thread 1
m_spel_1 = New Spel
m_spel_1.ServerInstance = 1
m_spel_1.Initialize()
m_spel_1.Project = "c:\EpsonRC70\Projects\MyProject\MyProject.sprj"
m_spel_1.Connect(1)
' Initialize Spel class instance for thread 2
' This instance uses the same controller as m_spel_1
m_spel_2 = New Spel
m_spel_2.ServerInstance = 1
Thread 1
' Uses instance m_spel_1 for motion
m_spel_1.Robot = 1
Do
m_spel_1.Go(1)
m_spel_1.Go(2)
Loop Until m_stop
Thread 2
' Uses instance m_spel_2 for I/O