JavaLikeCalc.JavaScript
//Same request to the device
function req(data, buf) {
	if(data == EVAL)	data = "";

	if(addr >= 0) {
		data = SYS.strFromCharCode(addr) + data;
		for(SUB = 0xFF, iCh = 0; iCh < data.length; iCh++)
			SUB -= data.charCodeAt(iCh);

		req = SYS.strFromCharCode(0x10, 0x02) + data + SYS.strFromCharCode(SUB&0xFF, 0x10, 0x03);

		//SYS.messInfo("/INCB/"+this.cfg("SHIFR"), tr("Request")+": "+SYS.strDecode(req,"Bin"," "));

		resp = tr.messIO(req);
	} resp = tr.messIO("", -10e-3);

	//Waiting the acceptance
	while(resp.length && (resp.length < 100 || resp.slice(-2) != "\x10\x03") && (tresp=tr.messIO("")).length) resp += tresp;
	if(buf != EVAL)	resp = buf + resp;
	if(resp.length == 0) return tr("2:No data. ");
	if(resp.length < 100 || resp.slice(0,2) != "\x10\x02" || resp.slice(-2) != "\x10\x03") {
		if(buf != EVAL)	buf = "";	//Cleaning the buffer at such errors of wrong data
		return tr("3:Input package is inconsistent. ");
	}
	if(addr >= 0 && resp.charCodeAt(2) != addr)
		return tr("4:Not correspond response address. ");

	for(pEnd = 0; !pEnd || (pEnd >= 0 && pEnd < resp.length && resp.indexOf("\x10\x02",pEnd) != pEnd); ) {
		pEnd = resp.indexOf("\x10\x03", pEnd);
		if(pEnd >= 0) pEnd += 2;
	}
	if(pEnd < 0) return tr("5:Wrong package structure. ");
		
	data = resp.slice(2, pEnd-3);
	if(buf != EVAL)	buf = resp.slice(pEnd);
	// Processing of doubling 0x10 for address 16
	if(data.charCodeAt(0) == 0x10 && data.charCodeAt(1) == 0x10)	data = data.slice(1);

	//SYS.messInfo("/INCB/"+this.cfg("SHIFR"), tr("Response")+": "+SYS.strDecode(data,"Bin"," "));

	for(SUB = 0xFF, iCh = 0; iCh < data.length; iCh++)
		SUB -= data.charCodeAt(iCh);
	if(resp.charCodeAt(resp.length-3) != (SUB&0xFF))
		return tr("3:Control sub error "+(SUB&0xFF)+" != "+resp.charCodeAt(resp.length-3));

	return "0";
}

function getSt(code) {
	stVl = tr("Unknown");
	if(code == 1)	stVl = tr("Heating");
	else if(code == 2)	stVl = tr("Cooling");

	return stVl+" ("+code+")";
}

function prmUpd(data) {
	if(data.charCodeAt(1) != 0x1B || data.charCodeAt(2) != 0x03 || data.length != 102)	return false;

	//Connecting or creating the representing parameter
	mO = false;
	if(addr >= 0)	prm = this;
	else {
		pId = "m" + data.charCodeAt(0);
		if(!(prm=this.nodeAt("prm_"+pId))) {
			SYS.cntrReq(SYS.XMLNode("add").setAttr("path",this.nodePath()+"/%2fbr%2fprm_").setAttr("id",pId));//.setText(devNm+": "+decId));
			SYS.cntrReq(SYS.XMLNode("set").setAttr("path",this.nodePath()+"/prm_"+pId+"/%2fprm%2fst%2fen").setText("1"));
			prm = this.nodeAt("prm_"+pId);

			machs[data.charCodeAt(0)] = mO = new Object();
			mO.cnt = 1;
			mO.disconCnt = 0;
			mO.tm = SYS.time();
		} else { mO = machs[data.charCodeAt(0)]; mO.cnt++; }
	}

	//Creating for attributes
	if(!prm.nodeAt("a_T1")) {
		if(mO)	prm.attrAdd("dataSt", tr("Data status"), "string|ro");

		prm.attrAdd("T1", tr("T1"), "real|ro");
		prm.attrAdd("T2", tr("T2"), "real|ro");
		prm.attrAdd("T3", tr("T3"), "real|ro");
		prm.attrAdd("T4", tr("T4"), "real|ro");
		prm.attrAdd("T5", tr("T5"), "real|ro");
		prm.attrAdd("T6", tr("T6"), "real|ro");
		prm.attrAdd("CO2", tr("CO2"), "real|ro");
		prm.attrAdd("H2O", tr("H2O"), "real|ro");
		prm.attrAdd("FAN", tr("FAN"), "real|ro");
		prm.attrAdd("V_H1", tr("Voltage Heater 1"), "real|ro");
		prm.attrAdd("V_H2", tr("Voltage Heater 2"), "real|ro");
		prm.attrAdd("V_H3", tr("Voltage Heater 3"), "real|ro");
		prm.attrAdd("V_H4", tr("Voltage Heater 4"), "real|ro");
		prm.attrAdd("V_H5", tr("Voltage Heater 5"), "real|ro");
		prm.attrAdd("V_H6", tr("Voltage Heater 6"), "real|ro");

		prm.attrAdd("Hum", tr("Humidify"), "real|ro");
		prm.attrAdd("V_C1", tr("Voltage Cooler 1"), "real|ro");
		prm.attrAdd("V_C2", tr("Voltage Cooler 2"), "real|ro");
		prm.attrAdd("V_C3", tr("Voltage Cooler 3"), "real|ro");
		prm.attrAdd("V_C4", tr("Voltage Cooler 4"), "real|ro");
		prm.attrAdd("V_C5", tr("Voltage Cooler 5"), "real|ro");
		prm.attrAdd("V_C6", tr("Voltage Cooler 6"), "real|ro");

		prm.attrAdd("DD", tr("Day"), "integer|ro");
		prm.attrAdd("HH", tr("Hour"), "integer|ro");
		prm.attrAdd("MM", tr("Minute"), "integer|ro");

		prm.attrAdd("st1", tr("Status radiator 1"), "string|ro");
		prm.attrAdd("st2", tr("Status radiator 2"), "string|ro");
		prm.attrAdd("st3", tr("Status radiator 3"), "string|ro");
		prm.attrAdd("st4", tr("Status radiator 4"), "string|ro");
		prm.attrAdd("st5", tr("Status radiator 5"), "string|ro");
		prm.attrAdd("st6", tr("Status radiator 6"), "string|ro");

		prm.attrAdd("setT1", tr("Set T1"), "real|ro");
		prm.attrAdd("setT2", tr("Set T2"), "real|ro");
		prm.attrAdd("setT3", tr("Set T3"), "real|ro");
		prm.attrAdd("setT4", tr("Set T4"), "real|ro");
		prm.attrAdd("setT5", tr("Set T5"), "real|ro");
		prm.attrAdd("setT6", tr("Set T6"), "real|ro");

		prm.attrAdd("setCO2min", tr("Set CO2 minimum"), "real|ro");
		prm.attrAdd("setCO2max", tr("Set CO2 maximum"), "real|ro");
		prm.attrAdd("setH2Omin", tr("Set H2O minimum"), "real|ro");
		prm.attrAdd("setH2Omax", tr("Set H2O maximum"), "real|ro");
	}

	//Updating for values the attributes
	if(mO) {
		if(mO.per.isEVal())		mO.per = 0;
		if(SYS.time() > mO.tm)	mO.per = SYS.time() - mO.tm;
		if(mO.perM.isEVal())	mO.perM = 0;
		mO.perM = max(mO.perM, mO.per);
		mO.tm = SYS.time();
		mO.con = true;
		prm.nodeAt("dataSt").set("Filtering in passive. Packages="+mO.cnt+", time="+SYS.strftime(mO.tm)+"; period="+mO.per+"["+mO.perM+"]; disconnections="+mO.disconCnt, 0, 0, true);
	}

	prm.nodeAt("T1").set(data.charCodeAt(3,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("T2").set(data.charCodeAt(5,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("T3").set(data.charCodeAt(7,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("T4").set(data.charCodeAt(9,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("T5").set(data.charCodeAt(11,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("T6").set(data.charCodeAt(13,"UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("CO2").set(data.charCodeAt(15,"UTF-16BE"), 0, 0, true);
	prm.nodeAt("H2O").set(data.charCodeAt(17,"UTF-16BE"), 0, 0, true);
	prm.nodeAt("FAN").set(data.charCodeAt(19,"UTF-16BE"), 0, 0, true);
	prm.nodeAt("V_H1").set(data.charCodeAt(21,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_H2").set(data.charCodeAt(23,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_H3").set(data.charCodeAt(25,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_H4").set(data.charCodeAt(27,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_H5").set(data.charCodeAt(29,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_H6").set(data.charCodeAt(31,"UTF-16BE")/100, 0, 0, true);

	prm.nodeAt("Hum").set(data.charCodeAt(35,"UTF-16BE"), 0, 0, true);
	prm.nodeAt("V_C1").set(data.charCodeAt(37,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_C2").set(data.charCodeAt(39,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_C3").set(data.charCodeAt(41,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_C4").set(data.charCodeAt(43,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_C5").set(data.charCodeAt(45,"UTF-16BE")/100, 0, 0, true);
	prm.nodeAt("V_C6").set(data.charCodeAt(47,"UTF-16BE")/100, 0, 0, true);

	prm.nodeAt("DD").set(data.charCodeAt(53), 0, 0, true);
	prm.nodeAt("HH").set(data.charCodeAt(54), 0, 0, true);
	prm.nodeAt("MM").set(data.charCodeAt(55), 0, 0, true);

	prm.nodeAt("st1").set(getSt(data.charCodeAt(59)), 0, 0, true);
	prm.nodeAt("st2").set(getSt(data.charCodeAt(60)), 0, 0, true);
	prm.nodeAt("st3").set(getSt(data.charCodeAt(61)), 0, 0, true);
	prm.nodeAt("st4").set(getSt(data.charCodeAt(62)), 0, 0, true);
	prm.nodeAt("st5").set(getSt(data.charCodeAt(63)), 0, 0, true);
	prm.nodeAt("st6").set(getSt(data.charCodeAt(64)), 0, 0, true);

	prm.nodeAt("setT1").set(data.charCodeAt(81, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setT2").set(data.charCodeAt(83, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setT3").set(data.charCodeAt(85, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setT4").set(data.charCodeAt(87, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setT5").set(data.charCodeAt(89, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setT6").set(data.charCodeAt(91, "UTF-16BE")/10, 0, 0, true);
	prm.nodeAt("setCO2min").set(data.charCodeAt(93), 0, 0, true);
	prm.nodeAt("setCO2max").set(data.charCodeAt(94), 0, 0, true);
	prm.nodeAt("setH2Omin").set(data.charCodeAt(95), 0, 0, true);
	prm.nodeAt("setH2Omax").set(data.charCodeAt(96), 0, 0, true);

	return true;
}

function setEVAL( mach, updSt )
{
	if(!(mO=mach.isEVal()?this:this.nodeAt("prm_m"+mach)))	return false;

	if(updSt == true)	tVl = mO.nodeAt("dataSt").get();

	for(attrs = mO.nodeList("a_"), iA = 0; iA < attrs.length; iA++) {
		if((aId=attrs[iA].slice(2)) == "DESCR" || aId == "NAME" || aId == "SHIFR" || aId == "err")	continue;
		mO.nodeAt(aId).set(EVAL, 0, 0, true);
	}

	if(updSt == true)	mO.nodeAt("dataSt").set("Disconnected. "+tVl, 0, 0, true);

	return true;
}

if(f_start || f_stop) {
	if(f_start) {
		passFBuf = "";
		cntPkg = cntPrc = 0;
		// Reading the child parameters, enabling and registration for control
		if(addr < 0) {
			machs = new Object();
			machs.pkgTm = SYS.time();
			for(prms = this.nodeList("prm_"), iPrm = 0; iPrm < prms.length; iPrm++)
				if(prms[iPrm][4] == "m") {
					machs[mId=prms[iPrm].slice(5).toInt()] = mO = new Object();
					mO.cnt = mO.disconCnt = 0;
					mO.tm = SYS.time();
					SYS.cntrReq(SYS.XMLNode("set").setAttr("path",this.nodePath()+"/"+prms[iPrm]+"/%2fprm%2fst%2fen").setText("1"));
					setEVAL(mId);
				}
		}
	}
	return;
}

tErr = stStr = "";

if(!(tr=SYS.Transport.outAt(transport)) || !tr.start(true))
	tErr = "1:"+tr("Output transport '%1' error.").replace("%1",transport);
else if(addr < -1 || addr > 255)
	tErr = "2:"+tr("Address '%1' out of range [0...255].").replace("%1",addr.toString());
else if(addr < 0) {	//Passive filtering
	data = "";
	for( ; (tErr=req(data,passFBuf)).toInt() == 0 || tErr > 2; cntPkg++) {
		if(prmUpd(data))	cntPrc++;
		machs.pkgTm = SYS.time();
	}
	if(tErr >= 2)	tErr = "0";
	stStr = "Filtering in passive. Packages read="+cntPkg+", processed="+cntPrc+", time="+SYS.strftime(machs.pkgTm)+"; left to reset="+(tmCon-(SYS.time()-machs.pkgTm));

	if((SYS.time()-machs.pkgTm) > tmCon) { tr.start(false); machs.pkgTm = SYS.time(); }

	for(var iM in machs)
		if((SYS.time()-machs[iM].tm) > tmToEVAL && machs[iM].con == true) {
			machs[iM].con = false;
			machs[iM].disconCnt++;
			setEVAL(iM, true);
		}
}
else {
	//Reading
	if(!tErr.toInt()) {
		data = SYS.strFromCharCode(0x1B, 0x03);
		if(!(tErr=req(data)).toInt())
			prmUpd(data);
	}
}

//Error set
if(!tErr.length)	tErr = "0";
if(tErr.toInt()) {
	if(!tr.isEVal() && tr.start()) tr.start(false);
	if(f_err != tErr)
		SYS.messDebug("/INCB/"+this.cfg("SHIFR"), tr("Error")+": "+tErr);
	if(stStr.length)	tErr += " " + stStr;
} else if(stStr.length)	tErr += ":" + stStr;
f_err = tErr;