Files
infineon_plc/Packages/Beckhoff.TwinCAT.HMI.Functions.14.3.340/runtimes/native1.12-tchmi/GetElementByIndex.js
m.heisig 2d11c43579 Added minimal functionality for Robot teaching
- Added minimal HMI
- Added possibility to open and close all chamber doors
2026-01-17 09:20:39 +01:00

1 line
8.1 KiB
JavaScript

"use strict";var TcHmi;!function(TcHmi){!function(Functions){!function(Beckhoff){Beckhoff.GetElementByIndex=function(ctx,arraySymbol,arrayIndex){if(!ctx)throw new TypeError("Parameter 'ctx' must be defined.");if(!ctx.success||!ctx.error)throw new TypeError("Parameter 'ctx' must be defined properly. Either 'success' or 'error' or both are missing.");if("function"!=typeof ctx.success||"function"!=typeof ctx.error)throw new TypeError("Parameter 'ctx' must be defined properly. Either 'success' or 'error' or both are not of type 'function'.");if(null===arraySymbol)return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Requested array symbol is not set.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});if(!(arraySymbol instanceof TcHmi.Symbol))return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Parameter is no symbol.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});const convertedArrayIndex=parseInt(arrayIndex,10);if(Number.isNaN(convertedArrayIndex))return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Requested array index ("+arrayIndex+") is not a number.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});if(convertedArrayIndex<0)return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Requested array index ("+convertedArrayIndex+") is negative.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});let arraySymbolNew=null;if(ctx.delegatedWatch){let arraySymbolNewDestroyWatch=null,arraySymbolDestroyWatch=null,arraySymbolDestroyExpressionWatch=null;arraySymbolDestroyExpressionWatch=arraySymbol.watchExpression(data=>{if(arraySymbolNewDestroyWatch?.(),arraySymbolNewDestroyWatch=null,arraySymbolNew?.destroy(),arraySymbolNew=null,arraySymbolDestroyWatch?.(),arraySymbolDestroyWatch=null,data.error!==TcHmi.Errors.NONE){let res={code:TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,message:TcHmi.Errors[TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION],reason:'Failed to resolve expression: "'+arraySymbol?.getExpression().toString()+'".',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"};return data.details&&(res.errors=[data.details]),void ctx.error(TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,res)}if(!data.expressionResolved)return void ctx.error(TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,{code:TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,message:TcHmi.Errors[TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION],reason:'Failed to resolve expression: "'+arraySymbol?.getExpression().toString()+'".',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});let arraySymbolExpression=data.expressionResolved;if(arraySymbolExpression.getType()===TcHmi.SymbolType.Server){let content=arraySymbolExpression.getContent();if(!content)return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Invalid format.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});{let firstPipePos=content?.indexOf("|");if(-1===firstPipePos)arraySymbolNew=new TcHmi.Symbol("%s%"+content+"["+convertedArrayIndex+"]%/s%");else{let part1=content.substring(0,firstPipePos),part2=content.substring(firstPipePos);arraySymbolNew=new TcHmi.Symbol("%s%"+part1+"["+convertedArrayIndex+"]"+part2+"%/s%")}arraySymbolNewDestroyWatch=arraySymbolNew.watch(function(wdata){wdata.error===TcHmi.Errors.NONE?ctx.success(wdata.value):ctx.error(wdata.error,{code:wdata.error,message:TcHmi.Errors[wdata.error],reason:"Reading symbol value has failed.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex",errors:wdata.details?[wdata.details]:void 0})})}}else arraySymbolDestroyWatch=arraySymbol?.watch(function(wdata){return wdata.error!==TcHmi.Errors.NONE?void ctx.error(wdata.error,{code:wdata.error,message:TcHmi.Errors[wdata.error],reason:"Reading symbol value has failed.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex",errors:wdata.details?[wdata.details]:void 0}):Array.isArray(wdata.value)?wdata.value.length>convertedArrayIndex?void ctx.success(wdata.value[convertedArrayIndex]):void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Array length ("+wdata.value.length+") is smaller than requested array index ("+convertedArrayIndex+").",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"}):void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:'Invalid type. Expected "arraySymbol" to be an array.',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"})})}),ctx.destroy=()=>{arraySymbolDestroyExpressionWatch?.(),arraySymbolDestroyExpressionWatch=null,arraySymbolDestroyWatch?.(),arraySymbolDestroyWatch=null,arraySymbolNew?.destroy(),arraySymbolNew=null,arraySymbolNewDestroyWatch?.(),arraySymbolNewDestroyWatch=null}}else arraySymbol.resolveExpression(data=>{if(data.error!==TcHmi.Errors.NONE){let res={code:TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,message:TcHmi.Errors[TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION],reason:'Failed to resolve expression: "'+arraySymbol?.getExpression().toString()+'".',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"};return data.details&&(res.errors=[data.details]),void ctx.error(TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,res)}if(!data.expressionResolved)return void ctx.error(TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,{code:TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION,message:TcHmi.Errors[TcHmi.Errors.E_SYMBOL_RESOLVE_EXPRESSION],reason:'Failed to resolve expression: "'+arraySymbol?.getExpression().toString()+'".',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});let arraySymbolExpression=data.expressionResolved;if(arraySymbolExpression.getType()===TcHmi.SymbolType.Server){let content=arraySymbolExpression.getContent();if(!content)return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Invalid format.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"});{let firstPipePos=content?.indexOf("|");if(-1===firstPipePos)arraySymbolNew=new TcHmi.Symbol("%s%"+content+"["+convertedArrayIndex+"]%/s%");else{let part1=content.substring(0,firstPipePos),part2=content.substring(firstPipePos);arraySymbolNew=new TcHmi.Symbol("%s%"+part1+"["+convertedArrayIndex+"]"+part2+"%/s%")}arraySymbolNew.readEx(function(rdata){arraySymbolNew?.destroy(),arraySymbolNew=null,rdata.error===TcHmi.Errors.NONE?ctx.success(rdata.value):ctx.error(rdata.error,{code:rdata.error,message:TcHmi.Errors[rdata.error],reason:"Reading symbol value has failed.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex",errors:rdata.details?[rdata.details]:void 0})})}}else arraySymbol.readEx(function(rdata){return rdata.error!==TcHmi.Errors.NONE?void ctx.error(rdata.error,{code:rdata.error,message:TcHmi.Errors[rdata.error],reason:"Reading symbol value has failed.",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex",errors:rdata.details?[rdata.details]:void 0}):Array.isArray(rdata.value)?rdata.value.length>convertedArrayIndex?void ctx.success(rdata.value[convertedArrayIndex]):void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Array length ("+rdata.value.length+") is smaller than requested array index ("+convertedArrayIndex+").",domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"}):void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:'Invalid type. Expected "arraySymbol" to be an array.',domain:"TcHmi.Functions.Beckhoff.GetElementByIndex"})})})}}(Functions.Beckhoff||(Functions.Beckhoff={}))}(TcHmi.Functions||(TcHmi.Functions={}))}(TcHmi||(TcHmi={})),TcHmi.Functions.registerFunctionEx("GetElementByIndex","TcHmi.Functions.Beckhoff",TcHmi.Functions.Beckhoff.GetElementByIndex);