Function Tool_Parms_Services(@Service, @Params) /*********************************************************************************************************************** This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written permission from SRP Computer Solutions, Inc. Name : Tool_Parms_Services Description : Handler program for all module related services. Notes : The generic parameters should contain all the necessary information to process the services. Often this will be information like the data Record and Key ID. Parameters : Service [in] -- Name of the service being requested Param1-10 [in/out] -- Additional request parameter holders Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure History : (Date, Initials, Notes) 09/11/18 djs Original programmer. ***********************************************************************************************************************/ #pragma precomp SRP_PreCompiler $Insert LOGICAL $Insert RLIST_EQUATES $Insert RDS_LAYER_EQUATES $Insert TOOL_PARMS_EQUATES $Insert RDS_EQUATES $Insert WO_DAILY_SCHED_EQU Declare subroutine RList, Set_Status, Error_Services, Database_Services, Tool_Parms_Services, Btree.Extract Declare function Database_Services, Error_Services, Tool_Parms_Services GoToService Return Response or "" //----------------------------------------------------------------------------- // SERVICES //----------------------------------------------------------------------------- Service GetCurrentToolParmKey(PSN, Reactor) If PSN NE '' and Reactor NE '' then ToolParmKey = '' // Query for the most recent TOOL_PARMS record Query = 'SELECT TOOL_PARMS WITH PSN EQ ':PSN:' AND WITH REACTOR EQ ':Reactor:' BY-DSND DATETIME' GoSub ClearCursors Set_Status(0) RList(Query, TARGET_ACTIVELIST$, '', '' '') ErrorCode = '' If Get_Status(ErrorCode) then ErrorMsg = 'Error calling RList(): error code ':ErrorCode Error_Services('Add', ErrorMsg) return end Done = False$ Loop Until Done Readnext ToolParmKey Else Done = True$ // We have the most recent ToolParmKey -> Done Done = True$ Repeat GoSub ClearCursors If ToolParmKey EQ '' then // Widen query to exclude reactor Query = 'SELECT TOOL_PARMS WITH PSN EQ ':PSN:' BY-DSND DATETIME' GoSub ClearCursors Set_Status(0) RList(Query, TARGET_ACTIVELIST$, '', '' '') If Get_Status(ErrorCode) then ErrorMsg = 'Error calling RList(): error code ':ErrorCode Error_Services('Add', ErrorMsg) return end Done = False$ Loop Readnext ToolParmKey Else Done = True$ Until Done // We have the most recent ToolParmKey -> Done Done = True$ Repeat GoSub ClearCursors end If ToolParmKey EQ '' then // Matching TOOL_PARMS record does not yet exist -> Build one ToolParmKey = Tool_Parms_Services('CreateToolParmsRec', PSN, Reactor) end Response = ToolParmKey end else Response = '' end End Service //---------------------------------------------------------------------------------------------------------------------- // CreateToolParmsRec // // Input: // PSN - [Required] // ReactorNo - [Required] // RDSNo - [Optional] // // Output: // NewToolParmKey // // Creates a new TOOL_PARMS record. If RDSNo is not supplied, then the most recent RDS which matches the supplied // PSN and ReactorNo will be referenced for RDS_LAYER parameters. If RDSNo is supplied, then a new TOOL_PARMS // record will be created using the associated RDS_LAYERS for that RDSNo. The key ID of the new TOOL_PARMS record // is returned in the response. //---------------------------------------------------------------------------------------------------------------------- Service CreateToolParmsRec(PSN, ReactorNo, RDSNo) CurrentTime = OConv(Time(), 'MT') CurrentDate = OConv(Date(), 'D') CurrentDTM = CurrentDate:' ':CurrentTime CurrentDTM = IConv(CurrentDTM, 'DT') NewToolParmKey = PSN:'*':ReactorNo:'*':CurrentDTM NewToolParmRec = '' RDSRec = '' If RDSNo EQ '' then Query = 'SELECT RDS WITH PROD_SPEC_ID EQ ':PSN:' AND WITH REACTOR EQ ':ReactorNo:' BY-DSND DATE_IN' GoSub ClearCursors Set_Status(0) RList(Query, TARGET_ACTIVELIST$, '', '', '') If Get_Status(ErrorCode) then ErrorMsg = 'Error calling RList(): error code ':ErrorCode Error_Services('Add', ErrorMsg) return end NumResultRows = @RecCount If NumResultRows LT 1 then // No RDS records found that match this criteria. Widen the query to search the most recent // RDS that matches the Recipe ID and PSN, but to any reactor. Query = 'SELECT RDS WITH PROD_SPEC_ID EQ ':PSN:' BY-DSND DATE_IN' GoSub ClearCursors Set_Status(0) RList(Query, TARGET_ACTIVELIST$, '', '', '') If Get_Status(ErrorCode) then ErrorMsg = 'Error calling RList(): error code ':ErrorCode Error_Services('Add', ErrorMsg) return end end Readnext RDSKey then RDSRec = Database_Services('ReadDataRow', 'RDS', RDSKey) end GoSub ClearCursors end else // RDSNo supplied -> use RDSNo RDSRec = Database_Services('ReadDataRow', 'RDS', RDSNo) end If RDSRec NE '' then RDSLayerKeys = RDSRec For each RDSLayerKey in RDSLayerKeys using @VM setting vPos RDSLayerRec = Database_Services('ReadDataRow', 'RDS_LAYER', RDSLayerKey) LayerID = RDSLayerKey[-1, 'B*'] NewToolParmRec = LayerID NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewTOolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec NewToolParmRec = @USER4 NewToolParmRec = RDSLayerRec NewToolParmRec = RDSLayerRec Next RDSLayerKey end Database_Services('WriteDataRow', 'TOOL_PARMS', NewToolParmKey, NewToolParmRec) If Error_Services('NoError') else Error_Services('Add', 'Error writing TOOL_PARMS record: ':NewToolParmKey) end Response = NewToolParmKey end service Service ApplyCurrentRunParms(PSN, Reactor) // Updates all RDS records in the current run without an unload signature. DailySchedKey = 'WO_DAILY_SCHED':Reactor DailySchedRec = Database_Services('ReadDataRow', 'CONFIG', DailySchedKey) WorkOrderCust = DailySchedRec WorkOrderNo = FIELD(WorkOrderCust, ' ', 1) If WorkOrderNo NE '' then CurrToolParmKey = Tool_Parms_Services('GetCurrentToolParmKey', PSN, Reactor) Record = Database_Services('ReadDataRow', 'TOOL_PARMS', CurrToolParmKey) Open 'DICT.RDS' to @DICT then FailFlag = '' RDSKeys = '' SearchString = 'WO':@VM:WorkOrderNo:@FM Btree.Extract(SearchString, 'RDS', @DICT, RDSKeys, '', FailFlag) If FailFlag NE '-1' then Done = False$ For each RDSKey in RDSKeys using @VM // Ensure the current TOOL_PARMS record being saved matches the current run on the reactor. // If they do not match, then do not update the RDS_LAYER records in the current run. RdsPSN = Xlate('RDS', RDSKey, 'PROD_SPEC_ID', 'X') RDSReactor = Xlate('RDS', RDSKey, 'REACTOR', 'X') ReactorChange = False$ If RDSReactor NE '' then If (RDSReactor NE Reactor) then ReactorChange = True$ end If (RdsPSN NE PSN) or (ReactorChange) then Done = True$ Until Done // Need to check if unload stage has been signed UnloadSig = Xlate('RDS', RDSKey, 'OPERATOR_OUT', 'X') If UnloadSig EQ '' then // Get RDSLayer keys -> copy tool parameters to each layer RDSLayerIDs = Xlate('RDS', RDSKey, 'RDS_LAYER_KEYS', 'X') If RDSLayerIDs NE '' then ToolParmLayers = Record For each RDSLayerKey in RDSLayerIDs // Copy tool paramters LayerID = Field(RDSLayerKey, '*', 2) RDSLayerRec = Database_Services('ReadDataRow', 'RDS_LAYER', RDSLayerKey) RDSLayerTPKey = RDSLayerRec If RDSLayerTPKey NE CurrToolParmKey then // Only update RDS_LAYER record if TOOL_PARMS record has been updated. Locate LayerID in ToolParmLayers using @VM setting LayerPos then RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Record RDSLayerRec = Field(CurrToolParmKey, '*', 3) RDSLayerRec = CurrToolParmKey Database_Services('WriteDataRow', 'RDS_LAYER', RDSLayerKey, RDSLayerRec, True$, True$, True$) end end Next RDSLayerKey end end Next RDSKey end end end end service Service ApplyCurrentParms(RDSNo, PSN, Reactor) If (RDSNo NE '') and (PSN NE '') and (Reactor NE '') then CurrToolParmKey = Tool_Parms_Services('GetCurrentToolParmKey', PSN, Reactor) If CurrToolParmKey NE '' then // Get current tool parameter record TPRec = Database_Services('ReadDataRow', 'TOOL_PARMS', CurrToolParmKey) // Get RDSLayer keys -> copy tool parameters to each layer RDSLayerIDs = Xlate('RDS', RDSNo, 'RDS_LAYER_KEYS', 'X') If RDSLayerIDs NE '' then ToolParmLayers = TPRec For each RDSLayerKey in RDSLayerIDs // Copy tool paramters LayerID = Field(RDSLayerKey, '*', 2) RDSLayerRec = Database_Services('ReadDataRow', 'RDS_LAYER', RDSLayerKey) Locate LayerID in ToolParmLayers using @VM setting LayerPos then RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = TPRec RDSLayerRec = Field(CurrToolParmKey, '*', 3) RDSLayerRec = CurrToolParmKey Database_Services('WriteDataRow', 'RDS_LAYER', RDSLayerKey, RDSLayerRec, True$, True$, True$) end Next RDSLayerKey end end end end service //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Internal GoSubs //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ClearCursors: For counter = 0 to 8 ClearSelect counter Next counter return