Files
infineon_plc/Packages/Beckhoff.TwinCAT.HMI.Functions.14.3.340/runtimes/native1.12-tchmi/EnumToMemberName.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
5.6 KiB
JavaScript

"use strict";var TcHmi;!function(TcHmi){!function(Functions){!function(Beckhoff){Beckhoff.EnumToMemberName=function(ctx,symbol){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'.");null!=symbol?symbol instanceof TcHmi.Symbol?symbol.resolveSchema(data=>{if(data.error!==TcHmi.Errors.NONE)return void ctx.error(data.error,{code:data.error,message:TcHmi.Errors[data.error],reason:"Resolving symbol '"+symbol.getExpression()+"' schema has failed.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName",errors:data.details?[data.details]:void 0});if(!data.schema)return void ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Resolving symbol '"+symbol.getExpression()+"' schema has failed.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"});let schemaBasedNamePrefix,schemaBasedFullNamePrefix,schema=data.schema,schemaId=schema.id;if(schemaId){let schemaSharpIndex=schemaId.indexOf("#"),schemaSource=schemaId.substr(6,schemaSharpIndex-6),schemaName=schemaId.substr(schemaSharpIndex+14,schemaId?.length-schemaSharpIndex+2);schemaBasedNamePrefix=schemaName,schemaBasedFullNamePrefix=schemaSource.toUpperCase()+"_"+schemaBasedNamePrefix}if(!schema||schema.enum)if(!schema||schema.options)if(ctx.delegatedWatch){let destroyLocalizationWatch=null,destroy=symbol.watch(data=>{if(data.error!==TcHmi.Errors.NONE)return void ctx.error(data.error,{code:data.error,message:TcHmi.Errors[data.error],reason:"Watching symbol '"+symbol.getExpression()+"' has failed.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName",errors:data.details?[data.details]:void 0});let value=data.value,options=schema?.options,memberName=null;if(options)for(let option of options)if(option.value===value){memberName=option.label;break}if(null===memberName)return void ctx.error(TcHmi.Errors.ERROR,{code:TcHmi.Errors.ERROR,message:TcHmi.Errors[TcHmi.Errors.ERROR],reason:"Failed to resolve enum member for symbol '"+symbol.getExpression()+"'.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"});let enumName=symbol.getExpression().getFullName(),localization=new TcHmi.Locale.ApplicationLocalization;destroyLocalizationWatch&&(destroyLocalizationWatch(),destroyLocalizationWatch=null),destroyLocalizationWatch=localization.watch(data=>{if(!memberName)return;let keySymbolName=enumName+"_"+memberName,keySchemaFullName=schemaBasedFullNamePrefix+"_"+memberName,keySchemaName=schemaBasedNamePrefix+"_"+memberName,text=memberName;if(data.error===TcHmi.Errors.NONE&&data.reader){let temp=data.reader.get(keySymbolName);temp!==keySymbolName?text=temp:(temp=data.reader.get(keySchemaFullName),temp!==keySchemaFullName?text=temp:(temp=data.reader.get(keySchemaName),temp!==keySchemaName&&(text=temp)))}ctx.success(text)})});ctx.destroy=()=>{destroyLocalizationWatch&&(destroyLocalizationWatch(),destroyLocalizationWatch=null),destroy&&(destroy(),destroy=null)}}else symbol.readEx(data=>{if(data.error!==TcHmi.Errors.NONE)return void ctx.error(data.error,{code:data.error,message:TcHmi.Errors[data.error],reason:"Reading symbol '"+symbol.getExpression()+"' has failed.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName",errors:data.details?[data.details]:void 0});let value=data.value,options=schema?.options,memberName=null;if(options)for(let option of options)if(option.value===value){memberName=option.label;break}if(null===memberName)return void ctx.error(TcHmi.Errors.ERROR,{code:TcHmi.Errors.ERROR,message:TcHmi.Errors[TcHmi.Errors.ERROR],reason:"Failed to resolve enum member for symbol '"+symbol.getExpression()+"'.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"});let enumName=symbol.getExpression().getFullName(),localizationReader=(new TcHmi.Locale.ApplicationLocalization).get(),keySymbolName=enumName+"_"+memberName,keySchemaFullName=schemaBasedFullNamePrefix+"_"+memberName,keySchemaName=schemaBasedNamePrefix+"_"+memberName,text=memberName,temp=localizationReader.get(keySymbolName);temp!==keySymbolName?text=temp:(temp=localizationReader.get(keySchemaFullName),temp!==keySchemaFullName?text=temp:(temp=localizationReader.get(keySchemaName),temp!==keySchemaName&&(text=temp))),ctx.success(text)});else ctx.error(TcHmi.Errors.E_SCHEMA_INVALID,{code:TcHmi.Errors.E_SCHEMA_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_SCHEMA_INVALID],reason:"Required schema property 'options' is missing in schema for symbol '"+symbol.getExpression()+"'.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"});else ctx.error(TcHmi.Errors.E_SCHEMA_INVALID,{code:TcHmi.Errors.E_SCHEMA_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_SCHEMA_INVALID],reason:"Required schema property 'enum' is missing in schema for symbol '"+symbol.getExpression()+"'.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"})}):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.EnumToMemberName"}):ctx.error(TcHmi.Errors.E_PARAMETER_INVALID,{code:TcHmi.Errors.E_PARAMETER_INVALID,message:TcHmi.Errors[TcHmi.Errors.E_PARAMETER_INVALID],reason:"Requested symbol is not set.",domain:"TcHmi.Functions.Beckhoff.EnumToMemberName"})}}(Functions.Beckhoff||(Functions.Beckhoff={}))}(TcHmi.Functions||(TcHmi.Functions={}))}(TcHmi||(TcHmi={})),TcHmi.Functions.registerFunctionEx("EnumToMemberName","TcHmi.Functions.Beckhoff",TcHmi.Functions.Beckhoff.EnumToMemberName);