Executing Methods

There are several methods in the Spel class. For descriptions of available methods, see below.
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.

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+ 8.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.

VB Example:

' 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:\EpsonRC80\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  
Do  
m_spel_2.On(1)  
m_spel_2.Delay(500)  
m_spel_2.Off(1)  
m_spel_2.Delay(500)  
Loop Until m_stop  

C# Examples:

// Initialize Spel class instance for thread 1  
RCAPINet.Spel m_spel_1 = new RCAPINet.Spel();  
m_spel_1.ServerInstance = 1;  
m_spel_1.Initialize();  
m_spel_1.Project = @"c:\EpsonRC80\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  
RCAPINet.Spel m_spel_2 = new RCAPINet.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);  
}while(\!m_stop);  
Thread 2  
// Uses instance m_spel_2 for I/O  
do{  
m_spel_2.On(1);  
m_spel_2.Delay(500);  
m_spel_2.Off(1);  
m_spel_2.Delay(500);  
}while(\!m_stop);  

Using API threads in the Controller
By default, only one API thread is supported in the Controller. In this case, asynchronous methods are executed one at a time in the Controller, even when controlling multiple robots. For most applications that use one robot, or execute robot motion using SPEL+ tasks, this is sufficient, but you can configure the system to use up to 10 API tasks in the Controller to allow parallel processing for your .NET threads, such as when you are controlling more than one robot from the same Controller.

There are two basic steps required to use more than one API task in the Controller.

  1. In the Epson RC+ GUI, connect to the Controller, then open [Setup]-[System Configuration]-[Controller]-[Preferences]. Set “Reserved tasks for API” to the desired number of API tasks. Note that the more tasks you reserve for the API, the fewer tasks will be available for your SPEL+ programs. For example, if you reserve 5 API tasks, then there will be 27 tasks (32 – 5) available for SPEL+.
  2. In your application, set the CommandTask property to specify which API task you want to execute methods on.

In the simple example below, there is one thread for each robot in the same Controller. The robot motion commands will execute in parallel, since a different CommandTask is used in each thread, and ServerInstance is set to 1 for both Spel instances.

VB Example:

' Initialize Spel class instance for thread 1  
m_spel_1 = New Spel  
m_spel_1.ServerInstance = 1  
m_spel_1.CommandTask = 1  
m_spel_1.Initialize()  
m_spel_1.Project = "c:\EpsonRC80\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,  
' And uses the second CommandTask in the controller.  
m_spel_2 = New Spel  
m_spel_2.ServerInstance = 1  
m_spel_2.CommandTask = 2  
  
Thread 1  
' Uses instance m_spel_1 for Robot 1 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 Robot 2 motion  
m_spel_2.Robot = 2  
Do  
m_spel_2.Go(1)  
m_spel_2.Go(2)  
Loop Until m_stop  

C# Examples:

// Initialize Spel class instance for thread 1  
RCAPINet.Spel m_spel_1 = new RCAPINet.Spel();  
m_spel_1.ServerInstance = 1;  
m_spel_1.CommandTask = 1;  
m_spel_1.Initialize();  
m_spel_1.Project = @"c:\EpsonRC80\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,  
// And uses the second CommandTask in the controller.  
RCAPINet.Spel m_spel_2 = new RCAPINet.Spel();  
m_spel_2.ServerInstance = 1;  
m_spel_2.CommandTask = 2;  
  
Thread 1  
// Uses instance m_spel_1 for Robot 1 motion  
m_spel_1.Robot = 1;  
do{  
m_spel_1.Go(1);  
m_spel_1.Go(2);  
}while(\!m_stop);  
  
Thread 2  
// Uses instance m_spel_2 for Robot 2 motion  
m_spel_2.Robot = 2;  
do{  
m_spel_2.Go(1);  
m_spel_2.Go(2);  
}while(\!m_stop);