SecsToHost.Net Code Snippet

Integrating SecsToHost.Net into your equipment application is a easy. With just a few lines of codes you can turn your equipment application into a SECS/GEM compliant.

The following sample code assumes that you have done the tool configuration file EquipmentTemplate.xml with the Model Builder.

Initialization

Once you have defined your Equipment configuration with the Model Builder, you will need to initialize the GEMController.

// Subscribe to the primary message event
gemController.PrimaryMessageIn +=new EquipmentController.SECsPrimaryInEventHandler(OnPrimaryMessageIn);
				
// Subscribe to the secondary message event
gemController.SecondaryMessageIn += new EquipmentController.SECsSecondaryInEventHandler(OnSecondaryMessageIn);
				
// Subscribe to the Message Trace event generated by the GEM controller. 
gemController.MessageActivityTrace += new EquipmentController.SECsMessageActivityEventHandler(OnMessageActivityTrace);

// Subscribe to the Communication state transition event
gemController.CommunicationStateChanged += new Insphere.Connectivity.Application.SecsToHost. EquipmentController.SECsEventHandler(OnCommunicationStateChanged);
			
// Subscribe to the GEM control state transition event
gemController.ControlStateChanged += new Insphere.Connectivity.Application.SecsToHost. EquipmentController.SECsEventHandler(OnControlStateChanged);
				
// Subscribe to the GEM processing state transition event
gemController.ProcessingStateChanged += new Insphere.Connectivity.Application.SecsToHost. EquipmentController.SECsEventHandler(OnProcessingStateChanged);

// Subscribe to the GEM spooling state transition event
gemController.SpoolingStateChanged += new Insphere.Connectivity.Application.SecsToHost. EquipmentController.SECsEventHandler(OnSpoolingStateChanged);

// Initialize GEM Controller
gemController.Initialize(AppDomain.CurrentDomain.BaseDirectory + "\\EquipmentTemplate.xml", @"C:\LogFiles");

Communication

All the HSMS settings (IP address, port, etc) are defined in the tool model.

To establish connection and S1F13 communication to Host:

gemController.SetEnable();

To terminate the connection:

gemController.SetDisable();

Once you subscribed to CommunicationChanged event, you can handle all the connection notification by the GEMController.

private void OnCommunicationStateChanged(object sender, SECsEventArgs e) {
        switch (gemController.CommunicationState) {
          case CommunicationState.Disabled:
          break;

          case CommunicationState.Enabled:
          break;

          case CommunicationState.EnabledNotCommunicating:
          break;

          case CommunicationState.EnabledCommunicating:
          break;

          case CommunicationState.WaitCRA:
          break;

          case CommunicationState.WaitDelay:
          break;
       }
			
}

Control

Not code required. All the control state and requirements are implemented within the GEMController object. You can use the following methods to change the control state:

gemController.SetOnline(); // Switch to Online mode.

gemController.SetOffline(); // Switch to Offline mode.

gemController.SetLocal(); // Set the control substate to Local mode.

gemController.SetRemote()' // Set the control substate to Remote mode.

Event Data Collection

SECsMessage message = ServiceManager.DataCollection.EventReportSend(eventLogicalName);
gemController.Send(message);

As shown above, you only need to specify the event logical name and GEMController does all the works for you. (Check whether event is enabled/disabled, event->report->variables association, etc)

Variable Data Collection 

No code required. GEMController handles all the host requests (S1F3, S1F11, S2F13, S2F15, etc) automatically.

Trace Data Collection 

No code required. GEMController handles all the host requests (S2F23, S6F1) automatically.

Alarm Management

All the host requests pertaining to Alarm are automatically handled by the GEMController. The equipment application simply need to set/clear the alarm to notify the Host.

gemController.SetAlarm(alarmLogicalName); // Set or raise the alarm
gemController.ClearAlarm(alarmLogicalName); // Clear previous set alarm

After you triggered alarm set/clear, the GEMController proceed to send the S6F11 with the CEID associated with the alarm set and clear.

Process Program Management

All the host requests pertaining to Process Program are automatically handled by the GEMController. The equipment application simply need to handle the Upload/Download of process program. Below code snippet shows how to handle the process program upload request by Host:

private void OnHostRecipeUploadRequest(SECsPrimaryInEventArgs e) {
    // Retrieving the requested Recipe File
    string recipeFileName = e.Inputs.DataItem["PPID"].ToString();
    recipeFileName = this.gemController.ProcessProgramPath + "\\" + recipeFileName;
 
    // Trying to open the request recipe file
    FileStream fs = new FileStream(recipeFileName, FileMode.Open, FileAccess.Read);
    
    // Create binary reader
    BinaryReader r = new BinaryReader(fs);
     // Read the binary content
     byte[] ppbody = r.ReadBytes((int)fs.Length);
    
     // Send the recipe body in the reply
     SECsMessage recipeToReply = ServiceManager.ProcessProgram.ProcessProgramData(recipeFileName, ppbody);
     gemController.SendReply(recipeToReply, e.TransactionID);
 }

Spooling

No code required. GEMController handles all the Host requests (S2F15, S2F43, S6F23) and spooling state model automatically.

Many More...

For other functionalities, please request for the evaluation copy which will include a complete sample program.