Lean MES Open Source Manufacturing Execution System
Flexible Manufacturing Solutions through Open Standards and Free Software....

Instruction Handler Extensibility Template:    [Back to FMF]    [Back to Source Code Library]

Purpose: Use template to implement handling for a new type of instruction, functionality, interface(s) ...etc.


/// Copyright (c) 2010 LeanMES
// Licensed under the Academic Free License version 3.0
//
// History:
//    2010 November 14 Peter Tiagunov  Check In
//

/*
//if handler status: new,then initializing handler
//----------------------------------------------------------------------------------------------------------------------------------
if(ntQidxx_Handler[n]==1)then

    nQidxx_index=0;
    nQidxx_jndex=0;//reset HID table index
    //cycle HID table while not EOT, or not end of active HID(s)
    while ((nQidxx_jndex < GetLengthOfTable(ntQidxx_HID)) and not(ntQidxx_HID[nQidxx_jndex]==0))

        if(ntQidxx_HID[nQidxx_jndex]==n)then//active handler n is found

            nQidxx_lndex=ntQidxx_ILIDX[nQidxx_jndex];//get corresponding index to instruction table
            //-get instruction' parameters---------------------------------------------------------
            if(srGetInstrParameters(stQidxx_INSTRUCTIONS[nQidxx_lndex],
                                    stQidxx_iPARAMs, //transpose instruction's parameters from string to table
                                                      nQidxx_error)==0)then
                if(nQidxx_error==0)then

                    //---------------------------------------------
                    //*********************************************
                    //* Implement instruction initialization here *
                    //*********************************************
                    //---------------------------------------------
                                                                        
                    if(nQidxx_error>0)then
                        //update instruction' status and data(if any)
                        stQidxx_INSTRUCTIONS[nQidxx_lndex]="";
                        nQidxx_kndex=0;
                        stQidxx_iPARAMs[9]="3";//set instruction status error
                        //optional, update result with error code or specific <data>
                        //NumberToString(nQidxx_error,stQidxx_iPARAMs[10]);
                        //stQidxx_iPARAMs[10]="<data>";               
                        //do not raise error, if instruction can be handled with initialization error
                        //nQidxx_MSGID=nQidxx_error;
                        nQidxx_error=0;
                    endif

                    //transpose instruction's parameters from table to string, updates screen
                    while(nQidxx_kndex<GetLengthOfTable(stQidxx_iPARAMs))
                                      stQidxx_INSTRUCTIONS[nQidxx_lndex]=stQidxx_INSTRUCTIONS[nQidxx_lndex]+stQidxx_iPARAMs[nQidxx_kndex]+",";
                                      nQidxx_kndex=nQidxx_kndex+1;
                    wend
                else//srGetInstrElements errorcode
                    nQidxx_MSGID=nQidxx_error;
                endif
            else//subroutine srGetInstrElements execution error
                nQidxx_MSGID=7716;
            endif
        endif
        nQidxx_jndex=nQidxx_jndex+1;
    wend
    ntQidxx_Handler[n]=2; //set handler status: initialized
endif

// if handler initialized and condition to handle event is true, then handle event
//-------------------------------------------------------------------------------------------------------------------------------------------
if(ntQidxx_Handler[n]==2)then //optionally, condition/reason/<data> to attempt handle instruction, e.g. and not(sQidxx_BARCODE_Data==""))then

    nQidxx_jndex=0;//reset HID table index
            //cycle HID table while not EOT, or not end of active HID(s), or not order event
            while ((nQidxx_jndex < GetLengthOfTable(ntQidxx_HID)) and not(ntQidxx_HID[nQidxx_jndex]==0) and not(nQidxx_event==1))

                if(ntQidxx_HID[nQidxx_jndex]==n)then//if handler is for instruction type n

                    nQidxx_lndex=ntQidxx_ILIDX[nQidxx_jndex];//get corresponding index to instruction table                                
                              //-get instruction' parameters----------------------------------------------------------------------------
                              if(srGetInstrParameters(stQidxx_INSTRUCTIONS[nQidxx_lndex],
                                                                  stQidxx_iPARAMs, //transpose instruction's parameters from string to table
                                                                  nQidxx_error)==0)then
                                    if(nQidxx_error==0)then

                            //---------------------------------------
                            //***************************************
                            //* Implement instruction handling here *
                            //***************************************
                            //--------------------------------------- 
                               
                                if(nQidxx_MSGID==5997)then//if instruction complete(handled) update instruction status and input
                                                      //update instruction' status and data(if any)
                                                      stQidxx_INSTRUCTIONS[nQidxx_lndex]="";
                                                      nQidxx_kndex=0;
                                                      stQidxx_iPARAMs[9]="10";//set instruction status complete
                                                      stQidxx_iPARAMs[10]=sQidxx_BARCODE_Data;//update result with input data
                                    nQidxx_event=1;//raise order event to break while
                                    sQidxx_BARCODE_Data="";//consume input data
                                    ntQidxx_Handler[n]=0;//deactivate handler
                                    //nQidxx_InstrComplete_Idx = nQidxx_lndex;
                                endif

                                //transpose instruction's parameters from table to string, updates screen
                                                  while(nQidxx_kndex<GetLengthOfTable(stQidxx_iPARAMs))
                                                        stQidxx_INSTRUCTIONS[nQidxx_lndex]=stQidxx_INSTRUCTIONS[nQidxx_lndex]+stQidxx_iPARAMs[nQidxx_kndex]+",";
                                                        nQidxx_kndex=nQidxx_kndex+1;
                                                  wend                              

                            else// srGetInstrParameters errorcode
                                nQidxx_MSGID=nQidxx_error;
                            endif
                       
                        else//subroutine srGetInstrParameters execution error
                            nQidxx_MSGID=7716;
                        endif
                endif
              nQidxx_jndex=nQidxx_jndex+1;
            wend
endif

// handle errors (override/bypass/retry)
//---------------------------------------------------------------------------------------------------------------------------------
    if(ntQidxx_Handler[n]==3 or (ntQidxx_Handler[n]==2 and sQidxx_CMD=="RETRY"))then
        //---------------------------------------------
        //*********************************************
        //* Implement instruction error handling here *
        //*********************************************
        //---------------------------------------------
        //optionally issue retry/auto retry if error
        if(not(sQidxx_CMD=="RETRY"))then
            //optional, issue automatic RETRY if error
            sQidxx_BARCODE="RETRY";
        endif

        if(sQidxx_CMD=="RETRY")then
            nQidxx_event=1;//raise order event
            ntQidxx_Handler[n]=0;//deactivate handler
            nQidxx_MSGID=5802;//Instruction Reinitialized
            sQidxx_CMD="";
        endif
    endif
*/