-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtame.js
11 lines (11 loc) · 27.1 KB
/
tame.js
1
2
3
4
5
6
7
8
9
10
11
/*
* TAME [TwinCAT ADS Made Easy] V2.2.2
*
* Copyright (c) 2009-2012 Thomas Schmidt; t.schmidt.p1 at freenet.de
*
* Dual licensed under:
* MIT - http://www.opensource.org/licenses/mit-license
* GPLv3 - http://www.opensource.org/licenses/GPL-3.0
*
*/
var TAME={weekdShortNames:{ge:["So","Mo","Di","Mi","Do","Fr","Sa"],en:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]},weekdLongNames:{ge:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],en:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},monthsShortNames:{ge:["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],en:["Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sept","Oct","Nov","Dez"]},monthsLongNames:{ge:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],en:["January","February","March","April","May","June","July","August","September","October","November","December"]}};TAME.WebServiceClient=function(c){var f=(typeof c.language=="string")?c.language:"ge";this.dateNames={weekdShort:TAME.weekdShortNames[f],weekdLong:TAME.weekdLongNames[f],monthsShort:TAME.monthsShortNames[f],monthsLong:TAME.monthsLongNames[f]};this.maxStringLen=255;this.maxDropReq=10;this.useCheckBounds=true;var K=this,a={M:"16416",MX:"16417",I:"61472",IX:"61473",Q:"61488",QX:"61489"},s={BOOL:1,BYTE:1,USINT:1,SINT:1,WORD:2,UINT:2,INT:2,INT1DP:2,DWORD:4,UDINT:4,DINT:4,TIME:4,TOD:4,DATE:4,DT:4,REAL:4,LREAL:8,STRING:80,EndStruct:0},j=function(){var e={},U="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var T=0;T<U.length;T++){e[T]=U.charAt(T)}return e}(),m=function(){var e={},U="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(var T=0;T<U.length;T++){e[U.charAt(T)]=T}return e}(),g=c.dataAlign4,u=[0],d,b,D;if(typeof c.serviceUrl=="string"){d=c.serviceUrl}else{try{console.log("TAME library error: Service URL is not a string!")}catch(R){}return}if(typeof c.amsNetId=="string"){b=c.amsNetId}else{try{console.log("TAME library error: NetId is not a string!")}catch(R){}return}if(c.amsPort===undefined){D="801"}else{if(typeof c.amsPort=="string"&&parseInt(c.amsPort,10)>=801&&parseInt(c.amsPort,10)<=804){D=c.amsPort}else{try{console.log("TAME library error: AMS Port Number ("+parseInt(c.amsPort,10)+") is no string or out of range!")}catch(R){}return}}function z(e){if((e>=97)&&(e<=102)){return(e-87)}if((e>=65)&&(e<=70)){return(e-55)}if((e>=48)&&(e<=57)){return(e-48)}return 0}function O(W,T){var e=[],V=W.toString(16);while(V.length<T*2){V="0"+V}for(var U=0;U<T;U++){e[(T-1)-U]=((z(V.charCodeAt(U*2))*16)+z(V.charCodeAt((U*2)+1)))}return e}function p(T){var W=0,Z=0,X,e,V,Y;e=Math.abs(T);if(T!==0){for(var U=128;U>-127;U--){V=e/Math.pow(2,U);if(V>=2){break}Y=U;X=V}Y+=127;X=X.toString(2);for(U=2;U<25;U++){W<<=1;if(X.charAt(U)=="1"){W+=1}}if(X.charAt(25)=="1"){W+=1}Z=Y;Z<<=23;Z+=W;if(T<0){Z+=2147483648}}return Z}function t(Y){var U=0,aa=0,V={part1:0,part2:0},ab,X,T,e,Z;ab=Math.abs(Y);if(Y!==0){for(var W=1024;W>=-1023;W--){X=ab/Math.pow(2,W);if(X>=2){break}T=W;Z=X}T+=1023;Z=Z.toString(2);for(W=2;W<22;W++){U<<=1;if(Z.charAt(W)=="1"){U+=1}}if(Z.charAt(W)=="1"){e=true}W++;for(W;W<54;W++){aa<<=1;if(Z.charAt(W)=="1"){aa+=1}}V.part1=T;V.part1<<=20;V.part1+=U;if(Y<0){V.part1+=2147483648}V.part2=aa;if(e===true){V.part2+=2147483648}}return V}function A(U,T){var e;switch(T){case"#d":case"#dd":e=U*86400000;break;case"#h":case"#hh":e=U*3600000;break;case"#m":case"#mm":e=U*60000;break;case"#s":case"#ss":e=U*1000;break;case"#ms":case"#msmsms":e=U;break;default:e=U;break}return e}function k(Y){var X=j,V=0,T="",W,U,e;while(V<Y.length){W=Y[V++];U=Y[V++];e=Y[V++];T=T+X[W>>2]+X[((W&3)<<4)|(U>>4)]+(isNaN(U)?"=":X[(((U&15)<<2)|(e>>6))])+((isNaN(U)||isNaN(e))?"=":X[e&63])}return T}function H(T){var e=q(T.charCodeAt(0));return parseInt(e,16)}function P(e){var T=H(e);if(T>127){T=T-256}return T}function E(T){var e=q(T.charCodeAt(1));e+=q(T.charCodeAt(0));return parseInt(e,16)}function C(e){var T=E(e);if(T>32767){T=T-65536}return T}function w(T){var e=q(T.charCodeAt(3));e+=q(T.charCodeAt(2));e+=q(T.charCodeAt(1));e+=q(T.charCodeAt(0));return parseInt(e,16)}function F(e){var T=w(e);if(T>2147483647){T=T-4294967296}return T}function J(e,U){var T=w(e);if(U===undefined){return T}else{return(y(T,U))}}function l(e,U){var T=new Date(w(e));T=new Date(T.getTime()+T.getTimezoneOffset()*60000);if(U===undefined){return T}else{return(S(T,U))}}function N(T,U){var e=new Date(w(T)*1000);e=new Date(e.getTime()+e.getTimezoneOffset()*60000);if(U===undefined){return e}else{return(S(e,U))}}function o(U){var W=1,Y=0.5,T=w(U),e,X;if(T===0){return 0}e=((T>>>31)==1)?"-":"+";T<<=1;X=(T>>>24)-127;T<<=8;for(var V=1;V<=23;V++){W+=T<0?Y:0;T<<=1;Y/=2}return parseFloat(e+(W*Math.pow(2,X)))}function v(U){var T=w(U.substring(4,8)),X=w(U.substring(0,4)),W=12,V=1,Z=0.5,e,Y;if(T===0&&X===0){return 0}e=((T>>>31)==1)?"-":"+";T<<=1;Y=(T>>>21)-1023;T<<=11;while(W<32){V+=T<0?Z:0;T<<=1;Z/=2;W++}if((X>>>31)==1){V+=Z;X<<=1;Z/=2}while(W<64){V+=X<0?Z:0;X<<=1;Z/=2;W++}return parseFloat(e+(V*Math.pow(2,Y)))}function M(T){var e=T.length;for(var U=0;U<e;U++){if(T.charCodeAt(U)===0){break}}return T.substr(0,U)}function q(T){var e=T.toString(16);if((e.length%2)!==0){e="0"+e}return e}function h(T,e){e=(isNaN(e))?0:e;var U=T.toString(10);while(U.length<e){U="0"+U}return U}function S(Y,X){var e=X.split("#"),W=e.length,T="",V;for(var U=1;U<W;U++){switch(e[U]){case"D":V=Y.getDate();break;case"DD":V=Y.getDate();V=h(V,2);break;case"WD":V=Y.getDay();break;case"WKD":V=K.dateNames.weekdShort[Y.getDay()];break;case"WEEKDAY":V=K.dateNames.weekdLong[Y.getDay()];break;case"M":V=Y.getMonth()+1;break;case"MM":V=Y.getMonth()+1;V=h(V,2);break;case"MON":V=K.dateNames.monthsShort[Y.getMonth()];break;case"MONTH":V=K.dateNames.monthsLong[Y.getMonth()];break;case"YY":V=Y.getYear();while(V>100){V-=100}break;case"YYYY":V=Y.getFullYear();break;case"h":V=Y.getHours();break;case"hh":V=Y.getHours();V=h(V,2);break;case"m":V=Y.getMinutes();break;case"mm":V=Y.getMinutes();V=h(V,2);break;case"s":V=Y.getSeconds();break;case"ss":V=Y.getSeconds();V=h(V,2);break;case"ms":V=Y.getMilliseconds();break;case"msmsms":V=Y.getMilliseconds();V=h(V,3);break;default:V=e[U];break}T=T+V}return T}function y(Y,X){var e=X.split("#"),W=e.length,T="",V;for(var U=1;U<W;U++){switch(e[U]){case"d":if(W<=2){V=Y/86400000}else{V=Math.floor(Y/86400000);Y=Y%86400000}break;case"dd":if(W<=2){V=Y/86400000}else{V=Math.floor(Y/86400000);Y=Y%86400000}V=h(V,2);break;case"h":if(W<=2){V=Y/3600000}else{V=Math.floor(Y/3600000);Y=Y%3600000}break;case"hh":if(W<=2){V=Y/3600000}else{V=Math.floor(Y/3600000);Y=Y%3600000}V=h(V,2);break;case"m":if(W<=2){V=Y/60000}else{V=Math.floor(Y/60000);Y=Y%60000}break;case"mm":if(W<=2){V=Y/60000}else{V=Math.floor(Y/60000);Y=Y%60000}V=h(V,2);break;case"s":if(W<=2){V=Y/1000}else{V=Math.floor(Y/1000);Y=Y%1000}break;case"ss":if(W<=2){V=Y/1000}else{V=Math.floor(Y/1000);Y=Y%1000}V=h(V,2);break;case"ms":V=Y;break;case"msmsms":V=Y;V=h(V,3);break;default:V=e[U];break}T=T+V}return T}function G(V){var W=m,Y=0,e="",X,U,T,ac,ab,aa,Z;V=V.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{ac=W[V.charAt(Y++)];ab=W[V.charAt(Y++)];aa=W[V.charAt(Y++)];Z=W[V.charAt(Y++)];X=(ac<<2)|(ab>>4);U=((ab&15)<<4)|(aa>>2);T=((aa&3)<<6)|Z;e+=String.fromCharCode(X);if(aa!=64){e+=String.fromCharCode(U)}if(Z!=64){e+=String.fromCharCode(T)}}while(Y<V.length);return e}function r(T,W,V,Y,ac){var X=[],ab=0,aa=[],U=0;if(typeof T=="number"){X[0]=T.toString(10)}else{if(typeof T=="string"){X=T.split(".")}else{try{console.log("TAME library error: Can't parse name of object/variable. Name is not a string or number!");console.log(T)}catch(Z){}return}}if(V===undefined){V=window}ab=X.length-1;while(U<ab){if(X[U].charAt(X[U].length-1)=="]"){aa=X[U].substring(0,X[U].length-1).split("[");V=V[aa[0]][aa[1]]}else{V=V[X[U]]}U++}if(X[U].charAt(X[U].length-1)=="]"){aa=X[U].substring(0,X[U].length-1).split("[");V=V[aa[0]];if(W!==undefined){if(typeof Y=="string"){W=Y+W}if(typeof ac=="string"){W=W+ac}V[aa[1]]=W}return V[aa[1]]}else{if(W!==undefined){if(typeof Y=="string"){W=Y+W}if(typeof ac=="string"){W=W+ac}V[X[U]]=W}return V[X[U]]}}function Q(T){if(T===undefined){return false}else{if(!isNaN(T)&&T>0&&T<=K.maxStringLen){return true}else{try{console.log("TAME library error: User defined string length not valid! length: "+T);console.log("Max. string length: "+K.maxStringLen)}catch(U){}return false}}}function n(V){var W="",T=[];if(typeof V.fld!="string"){if(typeof V.addr=="string"&&V.addr.charAt(0)=="%"){if(V.addr.charAt(2)=="X"){V.fld=V.addr.substr(1,2);W=V.addr.substr(3);T=W.split(".");V.addr=T[0]*8+T[1]*1}else{V.fld=V.addr.substr(1,1);V.addr=parseInt(V.addr.substr(3),10)}}else{try{console.log("TAME library error: No field defined (M,MX,I,IX,Q,QX) and address contains no field information (%MB,%MX,%IB,%IX%,%QB,%QX).");console.log("fld:"+V.fld);console.log("addr:"+V.addr)}catch(U){}return}}else{if(V.fld.charAt(0)==="M"||V.fld.charAt(0)==="I"||V.fld.charAt(0)==="Q"){if(typeof V.addr=="string"){V.addr=parseFloat(V.addr)}else{if(typeof V.addr!=="number"){try{console.log("TAME library error: No PLC variable address defined.");console.log("addr:"+V.addr)}catch(U){}return}}if(V.fld.length==2&&V.fld.charAt(1)=="X"){if(V.addr===0){V.addr="0.0"}T=V.addr.toString().split(".");V.addr=T[0]*8+T[1]*1}}else{try{console.log("TAME library error: Field not defined (should be M,MX,I,IX,Q,QX) and address contains no correct field definition.");console.log("fld:"+V.fld);console.log("addr:"+V.addr)}catch(U){}}}if(isNaN(V.addr)){try{console.log("TAME library error: Wrong address definition.");console.log("addr:"+V.addr)}catch(U){}}}function i(e){e.send=function(){var T={};if(typeof e.id=="number"&&u[e.id]>0){try{console.log("TAME library warning: Request dropped (last request with ID "+e.id+" not finished!)")}catch(U){}u[this.id]++;if(u[this.id]<=K.maxDropReq){return}u[this.id]=0}if(XMLHttpRequest!==undefined){this.xmlHttpReq=new XMLHttpRequest()}if(!this.xmlHttpReq){try{this.xmlHttpReq=new ActiveXObject("Msxml2.XMLHTTP")}catch(U){try{this.xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP")}catch(U){this.xmlHttpReq=null;try{console.log("TAME library error: Failed Creating XMLHttpRequest-Object!")}catch(U){}}}}T="<?xml version='1.0' encoding='utf-8'?>";T+="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";T+="<soap:Body><q1:";T+=this.method;T+=" xmlns:q1='http://beckhoff.org/message/'><netId xsi:type='xsd:string'>";T+=b;T+="</netId><nPort xsi:type='xsd:int'>";T+=D;T+="</nPort><indexGroup xsi:type='xsd:unsignedInt'>";T+=this.indexGroup;T+="</indexGroup><indexOffset xsi:type='xsd:unsignedInt'>";T+=this.indexOffset;T+="</indexOffset>";if(this.cbRdLen>0){T+="<cbRdLen xsi:type='xsd:int'>";T+=this.cbRdLen;T+="</cbRdLen>"}if(this.pData&&this.pData.length>0){T+="<pData>";T+=this.pData;T+="</pData>"}T+="</q1:";T+=this.method;T+="></soap:Body></soap:Envelope>";if(typeof this.xmlHttpReq=="object"){this.xmlHttpReq.open("POST",d,true);this.xmlHttpReq.setRequestHeader("SOAPAction","http://beckhoff.org/action/TcAdsSync."+this.method);this.xmlHttpReq.setRequestHeader("Content-Type","text/xml; charset=utf-8");this.xmlHttpReq.onreadystatechange=function(){if((e.xmlHttpReq.readyState==4)&&(e.xmlHttpReq.status==200)){K.parseData(e)}};this.xmlHttpReq.send(T);if(typeof this.id=="number"){u[this.id]=1}}};return e}function I(W,V,U,T){var Y;if(typeof W.val=="string"){if(V==="REAL"||V==="LREAL"){Y=parseFloat(W.val)}else{Y=parseInt(W.val,10)}}else{if(typeof W.val=="number"){Y=W.val}else{try{console.log("TAME library error: Wrong variable type for a numeric variable in write request!");console.log("TAME library error: Variable type should be number or string, but is "+typeof W.val);console.log(W)}catch(X){}Y=0}}if(isNaN(Y)){Y=0;try{console.log("TAME library error: Value of a numeric variable in write request is not a number.");console.log(W)}catch(X){}}if(K.useCheckBounds===true){if(V==="LREAL"){if(!isFinite(Y)){try{console.log("TAME library warning: Limit for LREAL value exceeded!");console.log("Upper limit: "+Number.MAX_VALUE);console.log("Lower limit: "+Number.MIN_VALUE);console.log("value: "+Y);console.log(W)}catch(X){}}}else{if(V==="REAL"){if(Y>0){if(Y<1.175495e-38){try{console.log("TAME library warning: Lower limit for positive REAL value exceeded!");console.log("limit: 1.175495e-38");console.log("value: "+Y);console.log(W)}catch(X){}Y=1.175495e-38}else{if(Y>3.402823e+38){try{console.log("TAME library warning: Upper limit for positive REAL value exceeded!");console.log("limit: 3.402823e+38");console.log("value: "+Y);console.log(W)}catch(X){}Y=3.402823e+38}}}else{if(Y<0){if(Y>-1.175495e-38){try{console.log("TAME library warning: Upper limit for negative REAL value exceeded!");console.log("limit: -1.175495e-38");console.log("value: "+Y);console.log(W)}catch(X){}Y=-1.175495e-38}else{if(Y<-3.402823e+38){try{console.log("TAME library warning: Lower limit for negative REAL value exceeded!");console.log("limit: -3.402823e+38");console.log("value: "+Y);console.log(W)}catch(X){}Y=-3.402823e+38}}}}}else{if(Y<U){try{console.log("TAME library warning: Lower limit for numeric value exceeded!");console.log("type: "+V);console.log("limit: "+U);console.log("value: "+Y);console.log(W)}catch(X){}Y=U}else{if(Y>T){try{console.log("TAME library warning: Upper limit for numeric value exceeded!");console.log("type: "+V);console.log("limit: "+T);console.log("value: "+Y);console.log(W)}catch(X){}Y=T}}}}}return Y}function B(W,V,U){var T={},e;e=s[V];switch(V){case"STRING":if(Q(U.strlen)){V+="."+U.strlen;e=U.strlen}e++;break;case"TIME":case"TOD":case"DT":case"DATE":if(typeof U.format=="string"){V+="."+U.format}break;case"REAL":case"LREAL":if(typeof U.decPlaces=="number"){V+="."+U.decPlaces}else{if(typeof U.dp=="number"){V+="."+U.dp}}break}T={fld:U.fld,addr:U.addr,id:U.id,oc:U.oc,ocd:U.ocd,readLength:e,debug:U.debug,seq:true,items:[{val:U.val,jvar:U.jvar,type:V,prefix:U.prefix,suffix:U.suffix}]};if(W==="Write"){K.writeReq(T)}else{K.readReq(T)}}function x(V,W,U){var X={},af={},ac,ah=0,ai=0,ag=0,aj,T=[],an,Y,ab=0,ad,Z,am=0,ae=0,ap,al,aa,ao;if(V==="Write"&&typeof U.val=="object"){af=U.val;ac=U.val.length}else{if(typeof U.jvar=="string"){af=r(U.jvar);ac=r(U.jvar).length}else{try{console.log("TAME library error: No data object for this "+V+"-Request defined!")}catch(ak){}}}if(typeof U.arrlen=="number"){ac=U.arrlen}n(U);if(typeof U.item=="number"&&!isNaN(U.item)&&V==="Write"){ao=true;if(U.item<0||U.item>ac-1){try{console.log('TAME library error: Wrong value for "item"!');console.log("item: "+U.item);console.log("Last array index: "+(ac-1))}catch(ak){}}}if(W==="STRUCT"){if(typeof U.def=="string"){U.def=r(U.def)}else{if(typeof U.def!="object"){try{console.log("TAME library error: No structure definition found!")}catch(ak){}}}for(al in U.def){T=U.def[al].split(".");if(T[0]=="ARRAY"){an=parseInt(T[1],10);T.shift();T.shift()}else{an=1}for(ai=0;ai<an;ai++){if(T[0]=="STRING"){if(typeof T[1]=="string"){ad=parseInt(T[1],10)}Z=(Q(ad)?ad:s[T[0]])+1}else{Z=s[T[0]]}if(g===true&&Z>1&&T[0]!="STRING"&&ab>0){ap=ab%Z;if(ap>0){ab+=Z-ap}}ab+=Z}if(g===true&&Z>am&&T[0]!="STRING"){am=Z}}if(g===true&&am>1&&T[0]!="STRING"){if(am>4){am=4}ap=ab%am;if(ap>0){ae=am-ap;ab+=ae}}if(ao){U.addr=U.addr+ab*U.item;ac=1}X={fld:U.fld,addr:U.addr,id:U.id,oc:U.oc,ocd:U.ocd,debug:U.debug,readLength:ab*ac,seq:true,dataAlign4:g,dataObj:af,items:[]};for(ai=0;ai<ac;ai++){for(al in U.def){T=U.def[al].split(".");if(T[0]=="ARRAY"){an=parseInt(T[1],10);Y=T.length-1;for(ag=0;ag<an;ag++){if(T[Y]=="SP"){X.items[ah]={jvar:ai+"."+al+ag};if(Y===4){X.items[ah].type=T[2]+"."+T[3]}else{X.items[ah].type=T[2]}}else{X.items[ah]={jvar:ai+"."+al+"."+ag};if(Y===3){X.items[ah].type=T[2]+"."+T[3]}else{X.items[ah].type=T[2]}}if(V==="Write"){if(ao){if(T[Y]=="SP"){X.items[ah].val=af[U.item][al+ag]}else{X.items[ah].val=af[U.item][al][ag]}}else{if(T[Y]=="SP"){X.items[ah].val=af[ai][al+ag]}else{X.items[ah].val=af[ai][al][ag]}}}ah++}}else{X.items[ah]={jvar:ai+"."+al,type:U.def[al]};if(V==="Write"){if(ao){X.items[ah].val=af[U.item][al]}else{X.items[ah].val=af[ai][al]}}ah++}}if(g===true){X.items[ah]={type:"EndStruct",val:ae};ah++}}}else{aj=s[W];switch(W){case"STRING":if(Q(U.strlen)){W+="."+U.strlen;aj=U.strlen}aj++;break;case"TIME":case"TOD":case"DT":case"DATE":if(typeof U.format=="string"){W+="."+U.format}break;case"REAL":case"LREAL":if(typeof U.decPlaces=="number"){W+="."+U.decPlaces}else{if(typeof U.dp=="number"){W+="."+U.dp}}break}if(ao){U.addr+=U.item*aj;ac=1}X={fld:U.fld,addr:U.addr,id:U.id,oc:U.oc,ocd:U.ocd,readLength:aj*ac,debug:U.debug,seq:true,dataObj:af,items:[]};for(ai=0;ai<ac;ai++){X.items[ai]={jvar:ai,type:W};if(V==="Write"){if(ao){X.items[ai].val=af[U.item]}else{X.items[ai].val=af[ai]}}}}if(V==="Write"){K.writeReq(X)}else{K.readReq(X)}}function L(T,ac){var Y={},U={},ad=[],W=0,aa,V,X,Z;if(T==="Write"&&typeof ac.val=="object"){U=ac.val}else{if(typeof ac.jvar=="string"){U=r(ac.jvar)}else{try{console.log("TAME library error: No data object for this "+T+"-Request defined!")}catch(ab){}}}if(typeof ac.def=="string"){ac.def=r(ac.def)}else{if(typeof ac.def!="object"){try{console.log("TAME library error: No structure defininition found!")}catch(ab){}}}Y={fld:ac.fld,addr:ac.addr,id:ac.id,oc:ac.oc,ocd:ac.ocd,debug:ac.debug,seq:true,dataAlign4:g,dataObj:U,items:[]};for(X in ac.def){ad=ac.def[X].split(".");if(ad[0]=="ARRAY"){V=parseInt(ad[1],10);aa=ad.length-1;for(Z=0;Z<V;Z++){if(ad[aa]=="SP"){Y.items[W]={jvar:X+Z};if(aa===4){Y.items[W].type=ad[2]+"."+ad[3]}else{Y.items[W].type=ad[2]}}else{Y.items[W]={jvar:X+"."+Z};if(aa===3){Y.items[W].type=ad[2]+"."+ad[3]}else{Y.items[W].type=ad[2]}}if(T==="Write"){if(ad[aa]=="SP"){Y.items[W].val=U[X+Z]}else{Y.items[W].val=U[X][Z]}}W++}}else{Y.items[W]={jvar:X,type:ac.def[X]};if(T==="Write"){Y.items[W].val=U[X]}W++}}if(T==="Write"){K.writeReq(Y)}else{K.readReq(Y)}}this.writeReq=function(W){var Z=W.items,af={},T=[],ac=[],aj=[],V,aa,ai,U,ag,ad,ah,X,Y,ae;n(W);if(W.debug){try{console.log(W)}catch(ab){}}for(ae=0,V=Z.length;ae<V;ae++){aj=[];ah=Z[ae];if(ah.type!==undefined){ac=ah.type.split(".")}aa=(s[ac[0]]<4)?s[ac[0]]:4;if(W.dataAlign4===true&&aa>1&&ac[0]!="STRING"&&T.length>0){ad=T.length%aa;if(ad>0){ag=aa-ad;for(Y=1;Y<=ag;Y++){T.push(0)}}}if(ah.val===undefined){switch(ac[0]){case"STRING":ah.val="";break;case"DATE":case"DT":case"TOD":ah.val=new Date();break;default:ah.val=0;break}try{console.log("TAME library warning: Value of a variable in write request is not defined!");console.log(ah)}catch(ab){}}switch(ac[0]){case"BOOL":if(ah.val){aj[0]=1}else{aj[0]=0}break;case"BYTE":case"USINT":U=I(ah,ac[0],0,255);aj=O(U,aa);break;case"SINT":U=I(ah,ac[0],-128,127);if(U<0){U=U+256}aj=O(U,aa);break;case"WORD":case"UINT":U=I(ah,ac[0],0,65535);aj=O(U,aa);break;case"INT":U=I(ah,ac[0],-32768,32767);if(U<0){U=U+65536}aj=O(U,aa);break;case"INT1DP":ah.val=Math.round(ah.val*10);U=I(ah,ac[0],-32768,32767);if(U<0){U=U+65536}aj=O(U,aa);break;case"DWORD":case"UDINT":U=I(ah,ac[0],0,4294967295);aj=O(U,aa);break;case"DINT":U=I(ah,ac[0],-2147483648,2147483647);if(U<0){U=U+4294967296}aj=O(U,aa);break;case"REAL":U=I(ah,ac[0]);U=p(U);aj=O(U,aa);break;case"LREAL":U=I(ah,ac[0]);U=t(U);aj=O(U.part2,aa);aj=aj.concat(O(U.part1,aa));break;case"DATE":if(typeof ah.val=="object"){ah.val.setHours(0);ah.val.setMinutes(0);ah.val.setSeconds(0);U=ah.val.getTime()/1000-ah.val.getTimezoneOffset()*60}else{try{console.log("TAME library error: Date is not an object!)");console.log(ah)}catch(ab){}}aj=O(U,aa);break;case"DT":if(typeof ah.val=="object"){U=ah.val.getTime()/1000-ah.val.getTimezoneOffset()*60}else{try{console.log("TAME library error: Date is not an object!)");console.log(ah)}catch(ab){}}aj=O(U,aa);break;case"TOD":if(typeof ah.val=="object"){ah.val.setYear(1970);ah.val.setMonth(0);ah.val.setDate(1);U=ah.val.getTime()-ah.val.getTimezoneOffset()*60000}else{try{console.log("TAME library error: Date is not an object!)");console.log(ah)}catch(ab){}}aj=O(U,aa);break;case"STRING":ai=(ac[1]===undefined)?s.STRING:parseInt(ac[1],10);if(Q(ai)){X=ai<ah.val.length?ai:ah.val.length;for(Y=0;Y<X;Y++){aj[Y]=ah.val.charCodeAt(Y)}for(Y;Y<ai;Y++){aj[Y]=0}aj[Y]=0}break;case"TIME":U=ah.val*1;U=A(U,ac[1]);if(U<0){U=0;try{console.log("TAME library warning: Lower limit for TIME variable exceeded!)");console.log("value: "+ah.val+ac[1]);console.log(ah)}catch(ab){}}else{if(U>4294967295){U=4294967295;try{console.log("TAME library warning: Upper limit for TIME variable exceeded!)");console.log("value: "+ah.val+ac[1]);console.log(ah)}catch(ab){}}}aj=O(U,aa);break;case"EndStruct":for(Y=1;Y<=ah.val;Y++){T.push(0)}break;default:try{console.log("TAME library error: Unknown data type in write request : "+ac[0]);console.log(ah)}catch(ab){}break}T=T.concat(aj)}if(T&&T.length>0){T=k(T)}af={method:"Write",indexGroup:a[W.fld],indexOffset:W.addr,id:W.id,cbRdLen:0,pData:T,reqDescr:W};i(af).send()};this.readReq=function(U){var ab={},V=U.items,X=[],T,Y,Z,ac,aa;n(U);if(U.debug){try{console.log(U)}catch(W){}}if(typeof U.readLength!="number"){U.readLength=0;for(aa=0,T=V.length;aa<T;aa++){X=V[aa].type.split(".");if(X[0]=="STRING"){if(typeof X[1]=="string"){ac=parseInt(X[1],10)}Z=(Q(ac)?ac:s[X[0]])+1}else{Z=s[X[0]]}if(U.seq===true){if(U.dataAlign4===true&&Z>1&&X[0]!="STRING"&&U.readLength>0){Y=U.readLength%Z;if(Y>0){U.readLength+=Z-Y}}U.readLength+=Z}else{U.readLength=Z+V[aa].addr-U.addr}}}ab={method:"Read",indexGroup:a[U.fld],indexOffset:U.addr,cbRdLen:U.readLength,id:U.id,reqDescr:U};i(ab).send()};this.writeBool=function(e){B("Write","BOOL",e)};this.writeByte=function(e){B("Write","BYTE",e)};this.writeUsint=function(e){B("Write","USINT",e)};this.writeSint=function(e){B("Write","SINT",e)};this.writeWord=function(e){B("Write","WORD",e)};this.writeUint=function(e){B("Write","UINT",e)};this.writeInt=function(e){B("Write","INT",e)};this.writeInt1Dp=function(e){B("Write","INT1DP",e)};this.writeDword=function(e){B("Write","DWORD",e)};this.writeUdint=function(e){B("Write","UDINT",e)};this.writeDint=function(e){B("Write","DINT",e)};this.writeReal=function(e){B("Write","REAL",e)};this.writeLreal=function(e){B("Write","LREAL",e)};this.writeString=function(e){B("Write","STRING",e)};this.writeTime=function(e){B("Write","TIME",e)};this.writeTod=function(e){B("Write","TOD",e)};this.writeDate=function(e){B("Write","DATE",e)};this.writeDt=function(e){B("Write","DT",e)};this.readBool=function(e){B("Read","BOOL",e)};this.readByte=function(e){B("Read","BYTE",e)};this.readUsint=function(e){B("Read","USINT",e)};this.readSint=function(e){B("Read","SINT",e)};this.readWord=function(e){B("Read","WORD",e)};this.readUint=function(e){B("Read","UINT",e)};this.readInt=function(e){B("Read","INT",e)};this.readInt1Dp=function(e){B("Read","INT1DP",e)};this.readDword=function(e){B("Read","DWORD",e)};this.readUdint=function(e){B("Read","UDINT",e)};this.readDint=function(e){B("Read","DINT",e)};this.readReal=function(e){B("Read","REAL",e)};this.readLreal=function(e){B("Read","LREAL",e)};this.readString=function(e){B("Read","STRING",e)};this.readTime=function(e){B("Read","TIME",e)};this.readTod=function(e){B("Read","TOD",e)};this.readDate=function(e){B("Read","DATE",e)};this.readDt=function(e){B("Read","DT",e)};this.writeStruct=function(e){L("Write",e)};this.readStruct=function(e){L("Read",e)};this.writeArrayOfBool=function(e){x("Write","BOOL",e)};this.writeArrayOfByte=function(e){x("Write","BYTE",e)};this.writeArrayOfUsint=function(e){x("Write","USINT",e)};this.writeArrayOfSint=function(e){x("Write","SINT",e)};this.writeArrayOfWord=function(e){x("Write","WORD",e)};this.writeArrayOfUint=function(e){x("Write","UINT",e)};this.writeArrayOfInt=function(e){x("Write","INT",e)};this.writeArrayOfInt1Dp=function(e){x("Write","INT1DP",e)};this.writeArrayOfDword=function(e){x("Write","DWORD",e)};this.writeArrayOfUdint=function(e){x("Write","UDINT",e)};this.writeArrayOfDint=function(e){x("Write","DINT",e)};this.writeArrayOfReal=function(e){x("Write","REAL",e)};this.writeArrayOfLreal=function(e){x("Write","LREAL",e)};this.writeArrayOfString=function(e){x("Write","STRING",e)};this.writeArrayOfTime=function(e){x("Write","TIME",e)};this.writeArrayOfTod=function(e){x("Write","TOD",e)};this.writeArrayOfDate=function(e){x("Write","DATE",e)};this.writeArrayOfDt=function(e){x("Write","DT",e)};this.writeArrayOfStruct=function(e){x("Write","STRUCT",e)};this.readArrayOfBool=function(e){x("Read","BOOL",e)};this.readArrayOfByte=function(e){x("Read","BYTE",e)};this.readArrayOfUsint=function(e){x("Read","USINT",e)};this.readArrayOfSint=function(e){x("Read","SINT",e)};this.readArrayOfWord=function(e){x("Read","WORD",e)};this.readArrayOfUint=function(e){x("Read","UINT",e)};this.readArrayOfInt=function(e){x("Read","INT",e)};this.readArrayOfInt1Dp=function(e){x("Read","INT1DP",e)};this.readArrayOfDword=function(e){x("Read","DWORD",e)};this.readArrayOfUdint=function(e){x("Read","UDINT",e)};this.readArrayOfDint=function(e){x("Read","DINT",e)};this.readArrayOfReal=function(e){x("Read","REAL",e)};this.readArrayOfLreal=function(e){x("Read","LREAL",e)};this.readArrayOfString=function(e){x("Read","STRING",e)};this.readArrayOfTime=function(e){x("Read","TIME",e)};this.readArrayOfTod=function(e){x("Read","TOD",e)};this.readArrayOfDate=function(e){x("Read","DATE",e)};this.readArrayOfDt=function(e){x("Read","DT",e)};this.readArrayOfStruct=function(e){x("Read","STRUCT",e)};this.parseData=function(ai){var W=ai.xmlHttpReq.responseXML.documentElement,ad=[],U=0,af,aa,X,ac,Z,V,aj,ae,ah,ag,T;if(typeof ai.id=="number"){u[ai.id]=0}try{aa=W.getElementsByTagName("faultstring")[0].firstChild.data;try{af=W.getElementsByTagName("errorcode")[0].firstChild.data}catch(ab){af="-"}try{console.log("TAME library error: Message from server: "+aa+" ("+af+")")}catch(ab){}return}catch(ab){af=0}if(ai.method==="Read"){var Y=ai.reqDescr.items;try{if(typeof W.normalize=="function"){W.normalize()}X=G(W.getElementsByTagName("ppData")[0].firstChild.data);for(ag=0,T=Y.length;ag<T;ag++){ad.length=1;ad=Y[ag].type.split(".");if(ad.length>2){ah=ad.slice(1).join(".")}else{ah=ad[1]}Z=s[ad[0]];V=Z<4?Z:4;if(ai.reqDescr.seq!==true){U=Y[ag].addr-ai.reqDescr.addr}else{if(ai.reqDescr.dataAlign4===true&&V>1&&ad[0]!="STRING"&&U>0){ae=U%V;if(ae>0){U+=V-ae}}}switch(ad[0]){case"BOOL":ac=(X.charCodeAt(U)!="0");break;case"BYTE":case"USINT":ac=H(X.substr(U,Z));break;case"SINT":ac=P(X.substr(U,Z));break;case"WORD":case"UINT":ac=E(X.substr(U,Z));break;case"INT":ac=C(X.substr(U,Z));break;case"INT1DP":ac=((C(X.substr(U,Z)))/10).toFixed(1);break;case"DWORD":case"UDINT":ac=w(X.substr(U,Z));break;case"DINT":ac=F(X.substr(U,Z));break;case"REAL":ac=o(X.substr(U,Z));if(typeof ah=="string"){ac=ac.toFixed(parseInt(ah,10))}break;case"LREAL":ac=v(X.substr(U,Z));if(typeof ah=="string"){ac=ac.toFixed(parseInt(ah,10))}break;case"STRING":if(typeof ah=="string"){aj=parseInt(ah,10)}Z=(Q(aj)?aj:Z)+1;ac=M(X.substr(U,Z));break;case"TOD":ac=l(X.substr(U,Z),ah);break;case"TIME":ac=J(X.substr(U,Z),ah);break;case"DT":case"DATE":ac=N(X.substr(U,Z),ah);break;case"EndStruct":Z=Y[ag].val;break;default:try{console.log("TAME library error: Unknown data type at parsing read request: "+Y[ag].type)}catch(ab){}break}if(ad[0]!=="EndStruct"){r(Y[ag].jvar,ac,ai.reqDescr.dataObj,Y[ag].prefix,Y[ag].suffix)}if(ai.reqDescr.seq===true){U+=Z}}}catch(ab){try{console.log("TAME library error: Parsing Failed:"+ab);console.log(Y[ag])}catch(ab){}return}}if(typeof ai.reqDescr.oc=="function"){if(typeof ai.reqDescr.ocd=="number"){window.setTimeout(ai.reqDescr.oc,ai.reqDescr.ocd)}else{ai.reqDescr.oc()}}}};TAME.WebServiceClient.createClient=function(a){return new TAME.WebServiceClient(a)};