You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A user contacted me by email and wanted to see a way to get a complete list of all tag names that would valid on the controller including drilling down through arrays and structures. I came up with this solution. Would this be useful as a utility function?
consteip=require('st-ethernet-ip')letcont=neweip.Controller()cont.connect('192.168.121.10').then(async()=>{letdirectory={}// Separate tags by program / controller scopecont.tagList.forEach(t=>{directory[t.program]=[];})// Iterate through each scopefor(programindirectory){letnameList=[]letprogValue=(program==='null') ? null : program;lettaglist=cont.tagList.filter(t2=>t2.program===progValue);// Iterate through each tag of each scopefor(leti=0;i<taglist.length;i++){awaitdrillDown(cont,nameList,taglist[i])}directory[program]=nameList}// Change 'null' name to 'Controller'directory['Controller']=directory['null']deletedirectory.nullconsole.log(directory)})// Recursive tag name listing functionasyncfunctiondrillDown(cont,nameList,tagInfo,previousName){lettagLength=1;if(tagInfo.type.arrayDims>0){if(tagInfo.info===undefined){letcontTag=cont.newTag(tagInfo.name,tagInfo.program,false,1);tagLength=awaitcont.getTagArraySize(contTag);}else{tagLength=tagInfo.info;}for(leti=0;i<tagLength;i++){letnewNameif(previousName){newName=previousName+'.'+tagInfo.name+'['+i+']';}else{newName=tagInfo.name+'['+i+']';}nameList.push(newName);if(tagInfo.type.structure){letmembers=cont.templateList[tagInfo.type.code]._members;for(leta=0;a<members.length;a++){awaitdrillDown(cont,nameList,members[a],newName);}}}}else{letnewNameif(previousName){newName=previousName+'.'+tagInfo.name}else{newName=tagInfo.name}nameList.push(newName);if(tagInfo.type.structure){letmembers=cont.templateList[tagInfo.type.code]._members;for(leta=0;a<members.length;a++){awaitdrillDown(cont,nameList,members[a],newName);}}}}
The text was updated successfully, but these errors were encountered:
A user contacted me by email and wanted to see a way to get a complete list of all tag names that would valid on the controller including drilling down through arrays and structures. I came up with this solution. Would this be useful as a utility function?
The text was updated successfully, but these errors were encountered: