This GEMTool Java example uses the code generated from TransSECS using the Java/Javascript deployment option. Build and run this with the generated GEMToolRuntime.jar on the classpath.

import java.util.Random;
 
import com.ergotech.secs.SOFTREV;
import com.ergotech.secs.SecsException;
import com.ergotech.secs.gem.GemALID;
import com.ergotech.secs.gem.GemCEID;
import com.ergotech.secs.gem.GemHandler;
import com.ergotech.transsecs.secs.MessageNotifier;
import com.ergotech.transsecs.secs.TransSecsController;
import com.ergotech.transsecs.secs.VIBMessageBean;
import com.ergotech.util.SimulationManager;
import com.ergotech.vib.exceptions.BadParameterException;
import com.ergotech.vib.exceptions.VIBUpdateFailedException;
import com.ergotech.vib.utils.DataSourceContainer;
import com.ergotech.vib.valueobjects.DoubleValueObject;
import com.ergotech.vib.valueobjects.LongValueObject;
import com.ergotech.vib.valueobjects.StringValueObject;
 
import TransSECS.GemIDConnection;
import deploy.GEMTool.HostCommandReply;
import deploy.GEMTool.HostCommandSTART;
 
 
/* Demonstration code for using TransSECS for Java deployment.
   This sample demonstrations the tool side of TransSECS and 
   is used with the TransSECS "GEMTool" project.
 */
 
 
public class  GEMToolExample { 
	//the GEM tool
	static public GemIDConnection equipment = null;
	//the container keeps references to VIB data sources including SECS VIDs, etc.
	static public DataSourceContainer container = null;
	// the TransSECS Controller for this project
	static public TransSecsController controller = null;
	//gets and sets GEM variables
	static public GemHandler gemHandler = null;
 
	 public static void main(String[] args) {
		//Set environment to non-simulation mode 
		SimulationManager.getSimulationManager().setSimulating(false);
		// Create the tool by getting the GEM Connection.  
		//The name corresponds with the name in the TransSECS project.
		equipment = GemIDConnection.createConnection("GEMTool");
 
		//	TransSecsController tool = new deploy.SimpleGEMTool.EquipmentController();
		//	tool.init();
		//	tool.start();
 
		// If the connection is invalid a null value will be returned.
		if ( equipment == null ) {
			System.out.println("Tool Creation Failed");
			System.exit (-1); 
		}
 
		//note: online/offline and remote/local are usually set by a hardware switch on the tool 
		//  and read to get the actual values but here we set these values to defaults
 
		int online=1; //online if set to 1 (offline otherwise)
		int remote=1; //remote if set to 1 (local otherwise)
		// here we set the values of the VIDs 33006 (OnlineOfflineState) and 33005 (LocalRemoteState) 
		// to some initial values (usually read from the tool hardware switches)
		equipment.setIntValue(33006, online);//Go Online (still local)
		equipment.setIntValue(33005, remote);//Allow Local-Remote transition
		//When the Host sends an S1F13 (establish communications) followed by an S1F17 
		//(Request On-Line) the tool will be in Online-Remote state.
 
 
		//get the equipment controller so we can set or change some default controller parameters.  
		controller = equipment.getController();
 
		//The device id and port are the default values in the project but can be changed here
		controller.setDeviceId(1);
		controller.setPort(5010); 
 
		//the gemHandler gives us an alternative way to set VID valuse using the VID name and a value
		gemHandler = (GemHandler) controller.getGemHandler();
 
		//E005 allows 20 character MDLN/SOFTREV
 
		SOFTREV.maxLength=20; //allows 20 chars for both -- be sure your host accepts 20 characters (or only the default 6)
 
		//an example of using the VID Name instead of the VID itself to set a VID Value. 
		gemHandler.setValue("MDLN",new StringValueObject("Test 123  456"));
 
		//or, as an alternative to setting the OnlineOfflineState with VID 33006 above, we could do this:
		//gemHandler.setValue("OnlineOfflineState", new LongValueObject(1));
 
		//example of setting a VID using the gemHandler:
		gemHandler.setValue("WaferCount",new LongValueObject(1));
 
		//get the data source container for this tool so we can access data sources (VIDs)
		try {
			container =  DataSourceContainer.getRootContainer().getContainer("GEMTool");
		} catch (BadParameterException e1) {
			System.out.println("Internal error: could not get data source container for GEMTool"); 
			System.out.println(e1.getStackTrace());	  
			System.exit (-1);   
		}
 
		// create a notifier for the simple HostCommand message in the tool (See HostCommandNotifier.cs)
		Boolean success = controller.registerForReceiveNotification("HostCommandSTART", new HostCommandSTARTNotifier());
		if ( !success ) {
			System.out.println("Host Command START Notifier Registration failed");
		} else {
			System.out.println("Host Command START Notifier registration sucessful");
		}
 
 
		System.out.println("Simple GEM Tool set up on Port 5010 and Device ID 1");
 
		//for this demo, we will change some SVID values and trigger an alarm and event once in awhile
		Random r = new Random();
		long cycles = 0; 
		long waferCount = 0;
 
		//test event triggered periodically (events will not be triggered unless host has enabled them)
		GemCEID gemEvent=null;
		try {
			gemEvent = (GemCEID)gemHandler.getServerForName("CEID.Completed");
		} catch (BadParameterException e1) {
			System.out.println("Problem accessing server for CEID \"Completed\"");
			System.exit (-1); 
		} 
 
		//set up a test alarm (will not be triggered unless host has enabled this alarm, or all alarms)
		GemALID alarm=null;
		Boolean alarmset = false;
		try {
			alarm = (GemALID)gemHandler.getServerForName("ALID.TemperatureProblem");
		} catch (BadParameterException e2) {
			System.out.println("Problem accessing server for ALID \"TemperatureProblem\"");
			System.exit (-1); 
		} 
 
		//start the test cycles where we change the process variable values 
		//and trigger the test alarm and event periodically
		while ( true ) {
			cycles ++;
			gemHandler.setValue("ProcessTemperature", new DoubleValueObject(r.nextDouble()*10+120.0));
			gemHandler.setValue("GasFlow", new DoubleValueObject(r.nextDouble()*1+1));
			// increment the wafer count every 20 cycles
			if ((cycles %20) == 0) {
				waferCount++;
				gemHandler.setValue("WaferCount", new LongValueObject(waferCount));
			}
			if ((cycles % 120)==0) { //every 120 cycles set an event, otherwise unset it       
				try {
					gemEvent.setBooleanValue(true);
					System.out.println("Event Triggered");
				} catch (VIBUpdateFailedException e) {
					System.out.println(e.getStackTrace());	
				}
			}
			else {
				try {
					gemEvent.setBooleanValue(false);
				} catch (VIBUpdateFailedException e) {
					System.out.println(e.getStackTrace());	
				}
			}
			//check for an alarm
			//get the current process variable value
			double temperature = 0;
			try {
				temperature = gemHandler.getServerForName("VID.ProcessTemperature").getFloatValue();
			} catch (BadParameterException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			// System.out.println(temperature);	
			if ((temperature>128.5) && (alarmset==false)) { //trigger the alarm
				try {
					alarm.set();
				} catch (SecsException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				alarmset=true;
				//System.out.println("Alarm Triggered");	
			} else  
				if (alarmset==true) { //unset/clear the alarm
					try {
						alarm.clear();
					} catch (SecsException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					alarmset=false;
					//System.out.println("Alarm Cleared");			  
				}
 
 
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
 
 
 
	}	
 
	/** Example of handing an unsolicited incoming message (Host Command)  */
	 /* This could be (and usually is) a separate non static class in its own file) */
	public static class HostCommandSTARTNotifier implements MessageNotifier  {
		public void messageReceived(int status, VIBMessageBean message) {
			// the status will be -1 to indicate an unsolicited message.
			System.out.println("Message Received in Host Command START Notifier: "  + message);
			HostCommandSTART hostCommand = (HostCommandSTART)message;
			String command = hostCommand.getCommand();
			System.out.println("Host Command is " + command);
			if (!(command.equals("START")) ) {
				System.out.println("Host Command Rejected");
				sendErrorResponse(1); //1=bad command
				return;
			}   
			//everything checks out ok, so send OK response
			System.out.println("Host Command START Accepted");
			//do something for START
			sendOKResponse(); 
 
		}
 
		//Send the S2F42 response as an error
		// error codes are 1=unknown parameter, 2=bad value, etc. per SECS E05 specification
		// This is an example of setting a parameter in a message before sending it
		public void sendErrorResponse(int hcack) {     
			GemIDConnection connection = GemIDConnection.createConnection("GEMTool"); 
			HostCommandReply response = null; 
			//ACK is a byte array (byte type), initialize it with the hcack value
			byte[] acks= new byte[(int)1];		
			try {
				response = (HostCommandReply)connection.getController().getMessageBean("HostCommandReply");
				response.setHCACK(acks);
				response.sendMessage();
			} catch (Exception e)  {
				System.out.println(e.getStackTrace());
			}	
		}
 
		// parameters are all OK, so send ACK (no parameters to set in the message, use the default as defined)
		public void sendOKResponse() {
			GemIDConnection connection = GemIDConnection.createConnection("GEMTool"); 
			HostCommandReply response = null;
			try {
				response = (HostCommandReply)connection.getController().getMessageBean("HostCommandReply");
				response.sendMessage();
			} catch (Exception e) { 
				System.out.println(e.getStackTrace());
			}
		}  
 
	};
 
}
  • gemtool_java_example.txt
  • Last modified: 2020/05/12 18:32
  • by wikiadmin