JavaLikeCalc.JavaScript
//Same request to the device
function req(data, toWait) {
	data = tr.messIO(data, data.length ? 0 : -1e-3);

	if(toWait != null) {
		//Waiting the acceptance
		while(data.length && data.indexOf(toWait) < 0 && data.length < 1000 && (tresp=tr.messIO("")).length) data += tresp;

		//SYS.messInfo("/VSE002/"+this.cfg("SHIFR"), tr("Resp")+": "+data.indexOf(toWait)+"("+data.length+")");

		if(data.length == 0) return tr("2:No data. ");
		if(data.indexOf(toWait) < 0) return tr("3:No waiting sequence. ");
	}

	return "0";
}

function setVal(aid, vl) {
	if(!(aO=this.nodeAt("a_"+aid))) {
		this.attrAdd(aid, aid, "real|ro");
		aO = this.nodeAt("a_"+aid);
	}
	aO.set(vl, 0, 0, true);

	// Custom signals
	if((tmpO=custSignO[aid]) == null) return;
	if(!(aO=this.nodeAt("a_"+tmpO.id))) {
		this.attrAdd(tmpO.id, tmpO.id, "real|ro");
		aO = this.nodeAt("a_"+tmpO.id);
	}
	aO.set(vl * ((tmpO.mult==null)?1:tmpO.mult), 0, 0, true);
}

function setEVAL( )
{
	mO = this;

	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(f_start || f_stop)	{
	cntRecon = 0;
	initSeq_ = "";
	toInit = true;
	custSign_ = "";
	custSignO = null;

	setEVAL();

	return;
}

if(custSign != custSign_) {
	custSign_ = custSign;

	if(custSign.length) {
		custSignO = new Object();
		for(off = 0; (rec=custSign.parseLine(0,off)).length || off < custSign.length; ) {
			if(!rec.length || rec[0] == "#") continue;
			custSignO[rec.parse(0,":")] = tmpO = new Object();
			tmpO.id = rec.parse(1, ":");
			tmpO.mult = rec.parse(2, ":");
			tmpO.mult = (tmpO.mult.length) ? tmpO.mult.toReal() : null;
		}
	}
	else custSignO = null;
}

tErr = stStr = "";

if(!(tr=SYS.Transport.outAt(transport)) || !tr.start(true))
	tErr = "1:"+tr("Output transport '%1' error.").replace("%1",transport);
else if(toInit || initSeq != initSeq_) {
	cntPkgB8 = cntPkgB12 = cntPkgB20 = 0;
	pkgTm = SYS.time();

	//Restarting
	tr.start(false); tr.start(true);

	if(!initSeq.length)
		initSeq = "2c 00 00 00 00 00 00 ff 03 00 00 00 00 00 00 00 "
			"00 00 00 00 00 00 00 00 00 00 ff ff ff fe 42 01 "
			"00 00 00 00";

	req(SYS.strEncode(initSeq),
		SYS.strEncode("00 00 00 00 2c 00 00 00 00 00 00 00"));

	buf = ""; bOff = 0;
	toInit = false;
	initSeq_ = initSeq;
}
//No data - reconnect
else if((SYS.time()-pkgTm) > tmCon) { toInit = true; pkgTm = SYS.time(); setEVAL(); cntRecon++; }
//Passive filtering
else {
	for(vBuf = new Object(), data = "", stTime = SYS.time(); (tErr=req(data)).toInt() == 0 && (data.length || bOff < buf.length); ) {
		if(data.length) pkgTm = SYS.time();
		buf += data; data = "";
		if((SYS.time()-stTime) > 5)	break;
		if(buf.length > 100000 /*|| (SYS.time()-stTime) > 5*/) {
			SYS.messInfo("/VSE002/"+this.nodePath(), "Data overflow on "+buf.length);
			buf = ""; bOff = 0;
			break;
		}
		if((buf.length-bOff) < 20)	continue;	//Wait more data
		sign = buf.slice(bOff, bOff+2);
		if(sign == "\x6A\x00") {			//B8
			cntPkgB8++;
			io = Special.FLibSYS.IO(buf);
			io.pos = bOff+2;	vBuf["B8_"+io.read("uint16",1)] = io.read("float", 1);
			bOff += 8;
		}
		else if(sign == "\x74\x00") {	//B8_2
			cntPkgB8++;
			io = Special.FLibSYS.IO(buf);
			io.pos = bOff+2;	vBuf["B8_"+io.read("uint16",1)+"_2"] = io.read("float", 1);
			bOff += 8;
		}
		else if(sign == "\x6E\x00") {	//B8_3
			cntPkgB8++;
			io = Special.FLibSYS.IO(buf);
			io.pos = bOff+2;	vBuf["B8_"+io.read("uint16",1)+"_3"] = io.read("float", 1);
			bOff += 8;
		}
		else if(sign == "\x6F\x00" || sign == "\x71\x00") {	//B12
			cntPkgB12++;
			io = Special.FLibSYS.IO(buf);
			io.pos = bOff+2; fId = io.read("uint16", 1);
			vBuf["B12_"+fId+"_1"] = io.read("float", 1);
			vBuf["B12_"+fId+"_2"] = io.read("float", 1);
			bOff += 12;
		}
		else if(sign == "\x66\x00") {	//B20
			cntPkgB20++;
			io = Special.FLibSYS.IO(buf);
			io.pos = bOff+2; fId = io.read("uint16", 1);
			vBuf["B20_"+fId+"_1"] = io.read("float", 1);
			vBuf["B20_"+fId+"_2"] = io.read("float", 1);
			vBuf["B20_"+fId+"_3"] = io.read("float", 1);
			vBuf["B20_"+fId+"_4"] = io.read("float", 1);
			bOff += 20;
		}
		else {
			SYS.messInfo("/VSE002/"+this.nodePath(), "Unknown package: "+SYS.strDecode(buf.slice(bOff,bOff+32),"Bin"," "));
			buf = "", bOff = 0; continue;
		}
	}

	buf = buf.slice(bOff); bOff = 0;

	for(var iV in vBuf) setVal(iV, vBuf[iV]);

	stStr = "Buffer="+buf.length+"; packages 8B="+cntPkgB8+", 12B="+cntPkgB12+", 20B="+cntPkgB20+"; reconnections="+cntRecon+", time="+SYS.strftime(pkgTm)+", left to reset="+(tmCon-(SYS.time()-pkgTm));
}

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