User Events from SPEL+

You can cause events to occur in your .NET application from your SPEL+ programs. For example, you can inform the .NET application about a continuous cycle loop. This is a better method to use than polling for variable values in the Controller from .NET. To fire an event to .NET from SPEL+, use the SPELCom_Event command in a SPEL+ program statement.
For example:

SPELCom_Event 1000, cycNum, lot$, cycTime  

The SPELCom_Event command is similar to a Print command. You can specify one or more pieces of data to be sent to the .NET application. For details about “SPELCom_Event”, see below.
SPELCom_Event
Before you can receive events, you must declare your Spel class variable using the WithEvents clause.

Public WithEvents m_spel As RCAPINet.Spel  

Catch the event in the EventReceived routine for the Spel class instance. To edit this routine, in the module where the Spel class is declared select “m_spel” from the class name list and EventReceived from the procedure list.

Here is an example of code in the EventReceived routine that updates some labels when an event occurs.

VB Example:

Sub m_spel_EventReceived (ByVal sender As Object, _  
ByVal e As RCAPINet.SpelEventArgs) _  
Handles m_spel.EventReceived  
    Dim tokens() As String  
    Select Case e.Event  
        Case 2000  
           tokens = e.Message.Split(New [Char]() {" "c}, _  
System.StringSplitOptions.RemoveEmptyEntries)  
           lblCycCount.Text = tokens(0)  
           lblLotNumber.Text = tokens(1)  
           lblCycTime.Text = tokens(2)  
    End Select  
End Sub  

C# Examples:

void m_spel_EventReceived(object sender, SpelEventArgs e)  
{  
string[] tokens = new string[3];  
switch(e.Event)  
  {  
   case 2000:  
            tokens = e.Message.Split(' ');  
            lblCycCount.Text = tokens(0);  
            lblLotNumber.Text = tokens(1);  
            lblCycTime.Text = tokens(2);  
            break;  
   default:  
            break;  
    }  
}