gem300_scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gem300_scripts [2024/02/01 14:25]
wikiadmin [E94 Service Wrapper]
gem300_scripts [2025/02/28 20:17] (current)
wikiadmin
Line 173: Line 173:
  }  }
 </code> </code>
-        +==== E40 Java Example ==== 
 +=== E40 Java Using the Service wrapper calls to process a job === 
 +Executing a job through E40 requires indicating to the process job the current state of the process. For example: 
 +<code java> 
 +Initialize the handlers: 
 +    try { 
 +      E39MessageHandler.addMessageHandler(equipmentController.getControllerName()); 
 +      E40MessageHandler.addMessageHandler(); 
 +      E94MessageHandler.addMessageHandler(); 
 +      E87MessageHandler.addMessageHandler(2,4); 
 +    } catch (BadParameterException e) { 
 +      e.printStackTrace(); 
 +    } 
 +    E40ServiceWrapper.getInstance().registerCallback(new E40Callback()); 
 +[...] 
 + /** Process a Job. */ 
 +  protected void processJob() { 
 +    ProcessJob[] allProcessJobs = E40ServiceWrapper.getInstance().getAllPRJobs(); 
 +    if ( allProcessJobs.length > 0 ) { 
 +      ProcessJob processJob = allProcessJobs[0]; 
 +      processJob.allocated(); 
 +      processJob.materialArrived(); 
 +      wait500(); 
 +      processJob.readyToStart(); 
 +      while ( processJob.getPrJobState() == ProcessJobStates.WAITINGFORSTART.getStateId() ) { 
 +        wait500(); 
 +      } 
 +      wait500();    
 +      try { 
 +        processJob.complete(); 
 +        processJob.materialDeparted(); 
 +      } catch (InvalidStateTransitionException e) { 
 +        e.printStackTrace(); 
 +      } 
 +    } 
 +  } 
 +</code> 
 +Notification of changes in process are sent through the  
 +<code java> 
 +import com.ergotech.secs.e39.E39MessageHandler; 
 +import com.ergotech.secs.e40.E40MessageHandler; 
 +import com.ergotech.secs.e40.E40ServiceWrapper; 
 +import com.ergotech.secs.e40.E40CallbackInterface; 
 +import com.ergotech.secs.e40.ProcessJob; 
 +import com.ergotech.transsecs.secs.TransSecsController; 
 + 
 +public class E40Callback { 
 +    public E40Callback() { 
 +        System.out.println("Register GEM300"); 
 + 
 +        TransSecsController controller = TransSecsController.findController("GEM300Tool"); 
 +        } while (controller == null); 
 + 
 +        try { 
 +            E39MessageHandler.addMessageHandler(controller.getControllerName()); 
 +            E40MessageHandler.addMessageHandler(); 
 +        } catch (Exception e) { 
 +            System.out.println(e); 
 +        } 
 + 
 +        E40ServiceWrapper.getInstance().registerCallback(new E40CallbackInterface() { 
 +            @Override 
 +            public void prStateChange(ProcessJob prJob, int oldState, int newState) { 
 +                System.out.println("State Change for " + prJob.getPrJobId() + " From: " + 
 +                        ProcessJob.getStateName(oldState) + " to " + ProcessJob.getStateName(newState)); 
 +                 
 +             } 
 + 
 +            @Override 
 +            public void prJobCreate(ProcessJob prJob) { 
 +                System.out.println("Job Creation of " + prJob.getPrJobId() + " permitted"); 
 +                 
 +             } 
 + 
 +            @Override 
 +            public void prSetRecipeVariable(ProcessJob prJob, List<?> recVarList) { 
 +                if (recVarList != null) { 
 +                    for (Object recVar : recVarList) { 
 +                        System.out.println("Host Requested Recipe Variable \"" + recVar.toString() + "\" on " + prJob); 
 +                    } 
 +                } 
 +            } 
 + 
 +            @Override 
 +            public void prSetMtrlOrder(int prCurrentMtrlOrder, int prNewMtrlOrder) { 
 +                // Handle material order settings 
 +            } 
 + 
 +            @Override 
 +            public void prCommandCallback(ProcessJob prJob, String prCmd, List<?> prCmdParameterList) { 
 +                System.out.println("Host Requested \"" + prCmd + "\" on " + prJob + " with parameters " + prCmdParameterList); 
 +                 
 +                String[] cmds = {"NONE", "ABORT", "STOP", "CANCEL", "PAUSE", "RESUME", "STARTPROCESS"}; 
 +                int cmdId = Arrays.asList(cmds).indexOf(prCmd); 
 +                 
 +                  
 +                // Send the parameters 
 +                if (prCmdParameterList != null) { 
 +                    for (Object param : prCmdParameterList) { 
 +                        System.out.println("Host Requested Parameter \"" + param.toString() + "\" on " + prJob); 
 +                    } 
 +                } 
 + 
 +            } 
 +        }); 
 + 
 +        System.out.println("E40 Registered"); 
 +    } 
 +
 +</code> 
 +==== E40 Python Example ==== 
 +<code python> 
 +#!/usr/bin/python3 
 +import jpype 
 +from jpype import JProxy, JArray, JInt 
 +import jpype.imports 
 +from jpype.types import * 
 + 
 +jpype.startJVM(classpath=['.', './GEMTool.jar']) 
 + 
 +# Importing the necessary Java classes 
 +from com.ergotech.secs.e39 import E39MessageHandler 
 +from com.ergotech.secs.e40 import E40MessageHandler, E40ServiceWrapper, E40CallbackInterface, ProcessJob 
 +from com.ergotech.transsecs.secs import TransSecsController 
 +from java.lang import Thread 
 + 
 +# Create the callback interface using a proxy 
 +class E40CallbackImplementation(E40CallbackInterface): 
 +    def prStateChange(self, prJob, oldState, newState): 
 +        print(f"State Change for {prJob.getPrJobId()} From: {ProcessJob.getStateName(oldState)} to {ProcessJob.getStateName(newState)}"
 +        # Send the new state for the process job to the PLC 
 +        # /GEM300PLC/ProcessJobId->setStringValue(prJob.getPrJobId()); 
 +        # /GEM300PLC/CurrentProcessJobState->setIntValue(newState); 
 + 
 +    def prJobCreate(self, prJob): 
 +        print(f"Job Creation of {prJob.getPrJobId()} permitted"
 +        # Indicate that this job is not allocated 
 +        # /GEM300PLC/Allocated->setIntValue(0); 
 +        # Record the id 
 +        # /GEM300PLC/ProcessJobId->setStringValue(prJob.getPrJobId()); 
 + 
 +    def prSetRecipeVariable(self, prJob, recVarList): 
 +        if recVarList is not None: 
 +            for counter in range(recVarList.size()): 
 +                print(f"Host Requested Recipe Variable \"{recVarList.get(counter).getStringValue()}\" on {prJob}"
 + 
 +    def prSetMtrlOrder(self, prCurrentMtrlOrder, prNewMtrlOrder): 
 +        # Set the order in which process jobs should be processed 
 +        pass 
 + 
 +    def prCommandCallback(self, prJob, prCmd, prCmdParameterList): 
 +        print(f"Host Requested \"{prCmd}\" on {prJob} with parameters {prCmdParameterList}"
 +        cmds = ['NONE', 'ABORT', 'STOP', 'CANCEL', 'PAUSE', 'RESUME', 'STARTPROCESS'
 +        # First indicate which process job the command is being executed on 
 +        # /GEM300PLC/ProcessJobId->setStringValue(prJob.getPrJobId()); 
 + 
 +        if prCmdParameterList is not None: 
 +            for counter in range(prCmdParameterList.size()): 
 +                print(f"Host Requested Parameter \"{prCmdParameterList.get(counter).getStringValue()}\" on {prJob}"
 + 
 +        # Get the index of the command 
 +        cmdId = cmds.index(prCmd) 
 +        # /GEM300PLC/PrCmd->setIntValue(cmdId); 
 + 
 +# Instantiate the callback 
 +E40Callback = E40CallbackImplementation() 
 + 
 +# Main Python code 
 +print("Register GEM300"
 + 
 +controller = None 
 +while controller is None: 
 +    Thread.sleep(50)  # wait 50 ms 
 +    controller = TransSecsController.findController("GEM300PLCTool"
 + 
 +try: 
 +    E39MessageHandler.addMessageHandler(controller.getControllerName()) 
 +    E40MessageHandler.addMessageHandler() 
 +except Exception as e: 
 +    print(e) 
 + 
 +# Register the callback 
 +E40ServiceWrapper.getInstance().registerCallback(E40Callback) 
 + 
 +print("E40 Registered"
 + 
 +</code>
 ==== E94 ==== ==== E94 ====
  
Line 273: Line 459:
       // carrier has departed       // carrier has departed
       e87ServiceWrapper.carrierDeparted(carrier.getLoadPortId(), carrier.getCarrierId());       e87ServiceWrapper.carrierDeparted(carrier.getLoadPortId(), carrier.getCarrierId());
 +</code>
 +
 +The most commonly used methods to manage an E87 carrier are contained in the Facade interface:
 +<code java>
 +package  com.ergotech.secs.e87;
 +
 +
 +import com.ergotech.secs.SecsException;
 +import com.ergotech.secs.SecsFormat00;
 +import com.ergotech.secs.e39.InvalidStateTransitionException;
 +import com.ergotech.secs.e87.E87ServiceWrapper.CMStatus;
 +import com.ergotech.vib.exceptions.BadParameterException;
 +
 +
 +
 +/** This implements the E87 services. It is normally called from E39. */
 +public interface E87ServiceWrapperFacadeInterface {
 +  /** Creates the load port object for the specific id.
 +   * @param loadPortId the id of the load port to create
 +   * @param readyForService true if the load port is ready for service, otherwise false.
 +   * If this parameter is true then the load port will transition to "IN SERVICE"
 +   * and so to "READY TO LOAD" as soon as it is created.
 +   * @return a new LoadPort
 +   * @throws BadParameterException thrown if a load port with the given id already exists.
 +   */
 +  public void createLoadPort(int loadPortId, boolean readyForService)throws BadParameterException;
 +
 +  /** This service shall associate a CarrierID to a load port and shall cause 
 +   * the load port to transition to the RESERVED state.
 +   * @param portId the port id where the carrier is expected.
 +   * @param carrierId the expected carrierID.
 +   * @return CMStatus information concerning the result of the service
 +   */
 +  public CMStatus bind ( int portId, String carrierId);
 +
 +
 +  /** This service cancels a CarrierID to load port association and shall cause
 +    the load port to transition to the NOT RESERVED state.
 +   * @param loadPortId the portID for which to cancel the load port to carrier 
 +   * association.  Either PortID or CarrierID must be specified.
 +   * @param carrierId the CarrierId for which to cancel the load port to carrier 
 +   * association.  Either PortID or CarrierID must be specified.
 +   * @return information concerning the result of the service
 +   */
 +  public CMStatus cancelBind ( int loadPortId, String carrierId );
 +
 +  /** This service shall Cancel the current carrier related action, and the 
 +   * production equipment shall return the carrier to the unload position
 +   * of the load port.
 +   * @param carrierId the carrierID to cancel
 +   * @param portId the PortID where the carrier object is located.  This
 +   * parameter is not required if the carrier object has previously been 
 +   * instantiated.
 +   @return information concerning the result of the service
 +   */
 +  public CMStatus cancelCarrier ( int portId, String carrierId);
 +
 +  /** This service shall Cancel the current carrier related action,
 +   * and the production equipment shall return the carrier to the unload 
 +   * position of the load port.
 +   * @param portId any carrier that exist on the load port specified shall be 
 +    made ready for unloading.
 +   * @return information concerning the result of the service
 +   */
 +  public CMStatus cancelCarrierAtPort ( int portId );
 +
 +  /** Create a carrier.  This can be mocked for unit testing. 
 +   * @throws BadParameterException thrown if a Carrier with the given ID already
 +   * exists.
 +   * @throws SecsException thrown if the properties list contains a slot map 
 +   * or a content map who's size does not match the capacity of the carrier.
 +   */
 +  public Carrier createCarrier (String carrierId, int loadPortId,  SecsFormat00 propertiesList, int transition ) throws BadParameterException, SecsException;
 +
 +  /** Stores the callback object.
 +   * @see com.ergotech.secs.e87.E87Interface#registerCallBack(com.ergotech.secs.e87.E87CallbackInterface)
 +   */
 +  public void registerCallBack(E87CallbackInterface callback);
 +
 +  /** Attempt the state transition on the port.  The port is not checked for
 +   * validity and an attempt to call this method on an invalid port will cause
 +   * a null pointer exception.
 +   */
 +  public void setLoadPortTransferState(int port, int stateTransition) throws InvalidStateTransitionException;
 +
 +  /** Return the transfer state of the port.  The port is not checked for
 +   * validity and an attempt to call this method on an invalid port will cause
 +   * a null pointer exception.
 +   * @see com.ergotech.secs.e87.E87Interface#getLoadPortTransferState(int)
 +   */
 +  public int getLoadPortTransferState(int port);
 +
 +  /** Attempt the state transition on the port.  The port is not checked for
 +   * validity and an attempt to call this method on an invalid port will cause
 +   * a null pointer exception.
 +   */
 +  public void setLoadPortAccessState(int port, int state) throws InvalidStateTransitionException, SecsException;
 +
 +  /** Returns the current access state of the port.  The port is not checked for
 +   * validity and an attempt to call this method on an invalid port will cause
 +   * a null pointer exception.
 +   * @see com.ergotech.secs.e87.E87Interface#getLoadPortAccessState(int)
 +   */
 +  public int getLoadPortAccessState(int port);
 +
 +  /** 
 +   * Change the carrier access status.  There are three states:<p>
 +     begin=0<p>
 +     complete=1<p>
 +     stopped=2<p>
 +   * The carrier is not checked for validity and an attempt to access an invalid
 +   * carrier will result in a null pointer exception.
 +   * @throws InvalidStateTransitionException thrown if the access attempt is invalid
 +   * @throws SecsException thrown if the status is an invalid request.
 +   */
 +  public void accessCarrier(String carrierID, Carrier.CarrierAccessE87State state) throws InvalidStateTransitionException, SecsException;
 +
 +  /** Request to put the port in service.  The port is not checked for
 +   * validity and an attempt to call this method on an invalid port will cause
 +   * a null pointer exception.
 +   * @throws InvalidStateTransitionException
 +   * @see com.ergotech.secs.e87.E87Interface#getLoadPortAccessState(int)
 +   */
 +  public void requestInService(int port) throws InvalidStateTransitionException;
 +
 +  /** Request to put the port in service.  
 +   * The port is not checked for validity and an attempt to call this 
 +   * method on an invalid port will cause a null pointer exception.
 +   * @throws InvalidStateTransitionException
 +   * @see com.ergotech.secs.e87.E87Interface#requestOutOfService(int)
 +   */
 +  public void requestOutOfService(int port) throws InvalidStateTransitionException;
 +
 +   /**
 +   * The application will invoke this when a carrier has arrived at a given port,
 +   * after it has read the carrier id.
 +   
 +   * @param carrierId
 +   * @param port The load port.  The port is not checked for validity and an 
 +               attempt to call this method on an invalid port will cause a 
 +               null pointer exception.
 +   * @param readOK the carrier id read is valid.
 +   * @param bypassReadId if this is true, the carrierID and readOK flags
 +          are ignored and processing continues with the carrier that is at the
 +          provided port.
 +   * @return 0:verified, 2:waiting for host proceed (or cancel), 3: duplicate id
 +   * @throws InvalidStateTransitionException
 +   * @throws BadParameterException
 +   */
 +  public int carrierArrived(String carrierId, int port, boolean readOK, boolean bypassReadId, boolean hostVerification ) throws InvalidStateTransitionException, BadParameterException;
 +
 +  /** When the carrier arrives, the LoadPort may already be in the "Transfer Blocked" state (eg as part of E84).
 +   * This method will check the current state of the load port.  If it is not in "Transfer Blocked" it will attempt
 +   * the transition 6.  If that transition is invalide, the method will throw.
 +   
 +   * @param loadPort the load port on which to execute the transition.
 +   * @throws InvalidStateTransitionException thrown if load port transition 6 is not a valid transition.
 +   */
 +  public void conditionalLoadPortTransition6(LoadPort loadPort) throws InvalidStateTransitionException;
 +
 +  /** When the carrier departs, the LoadPort may not be in the "Transfer Blocked" state (eg as part of E84).
 +   * This method will check the current state of the load port.  If it is not in "Transfer Blocked" it will attempt
 +   * the transition 6.  If that transition is invalide, the method will throw.
 +   
 +   * @param loadPort the load port on which to execute the transition.
 +   * @throws InvalidStateTransitionException thrown if load port transition 6 is not a valid transition.
 +   */
 +  public void conditionalLoadPortTransition8(LoadPort loadPort) throws InvalidStateTransitionException;
 +
 +  /** Execute transition21 to indicate that the carrier has departed.  This also destroys the 
 +   * carrier instance.
 +   * Set the carrier to null to indicate that it has departed.
 +   * The port is not checked for validity and an attempt to call this 
 +   * method on an invalid port will cause a null pointer exception.
 +   * @throws InvalidStateTransitionException
 +   * @see com.ergotech.secs.e87.E87Interface#carrierDeparted(int)
 +   */
 +  public void carrierDeparted(int port, String carrierId ) throws InvalidStateTransitionException;
 +
 +  /** 
 +   * The port is not checked for validity and an attempt to call this 
 +   * method on an invalid port will cause a null pointer exception.
 +   * @throws InvalidStateTransitionException
 +   * @see com.ergotech.secs.e87.E87Interface#carrierDeparted(int)
 +   */
 +  public void carrierDeparted(int port) throws InvalidStateTransitionException;
 +
 +  /** Cancel the carrier at the port.
 +   * The port is not checked for validity and an attempt to call this 
 +   * method on an invalid port will cause a null pointer exception.
 +   * @throws InvalidStateTransitionException
 +   */
 +  public void cancelCarrier(int port) throws InvalidStateTransitionException;
 +  
 +  /** Returns all carriers
 +   * @return  an array of all carriers.
 +   */
 +  public Carrier[] getAllCarriers();
 +
 +  /** Return the carrier instance for the ID, or null if the carrier does not exist. 
 +   
 +   * @param carrierId the carrier id
 +   */
 +  public Carrier getCarrier ( String carrierId );
 +
 +}
 </code> </code>
  
  • gem300_scripts.1706819155.txt.gz
  • Last modified: 2024/02/01 14:25
  • by wikiadmin