JavaLikeCalc.JavaScript
//Same request to the device
function req(data) {
	reqCntr++;

	if(data == EVAL)	data = "";
	req = SYS.strFromCharCode(0xAA, addr, data.length+5) + data;
	//Calc and append the CRC
	CRC = Special.FLibSYS.CRC(req, 16, 0x8005, -1, true, true, 0);
	req += SYS.strFromCharCode(CRC&0xFF, CRC>>8);
	SYS.messDebug("/PilotOld/"+this.cfg("SHIFR"), tr("Request")+": "+SYS.strDecode(req,"Bin"," "));

	resp = tr.messIO(req);
	//Wait for an acceptance
	while(resp.length && (resp.length < 6 || resp.length < resp.charCodeAt(2)) && (tresp=tr.messIO("")).length) resp += tresp;
	if(resp.length < 6 || (resp.charCodeAt(0)>>4) != 0x5 || resp.length != resp.charCodeAt(2))
		return tr("3:No response or the response is inconsistent. ");
	if(Special.FLibSYS.CRC(resp.slice(0,-2),16,0x8005,-1,true,true,0) != resp.charCodeAt(resp.length-2,"UTF-16LE"))
		return tr("3:Error the response CRC. ");

	SYS.messDebug("/PilotOld/"+this.cfg("SHIFR"), tr("Response")+": "+SYS.strDecode(resp,"Bin"," "));

	data = resp.slice(3,-2);
	if((tVl=resp.charCodeAt(3)) == 0xFF || !(tVl&0x80) || (tVl&0x7F) != (req.charCodeAt(3)&0x7F)) {
		return tr("4:The function is error or inconsistent to the request one. ");
	}
	return "0";
}

function valGetF(data, dOff) {
	return Special.FLibSYS.floatMergeWord(data.charCodeAt(dOff,"UTF-16LE"),data.charCodeAt(dOff+2,"UTF-16LE"));
}

//Seting value to the archive
function archSet(attr, vTm, vl, arh) {
	SYS.messInfo("/PilotOld/"+this.cfg("SHIFR"), "attr="+attr+"; vTm="+SYS.strftime(vTm)+"; arh="+arh+"; vl="+vl);
	atrO = this[attr];
	if(!atrO || atrO.isEVal()) return;
	arguments[attr] = vl;	//Set the current-last value
	//if(vTm > atrO.time())	atrO.set(vl,vTm,0,true);
	if(atrO.arch())	atrO.arch().setVal(vTm*1e6, vl, arh);
}

//Main process
if(f_start) {
	transport_ = transport;
	reqCntr = 0;
	tr = EVAL;
	reset = false;
	lstATmH = lstATmD = lstATmALRM = lstATmAUDIT = 0;
}

if(reset) {
	reset = false, arhLastH = arhLastD = 0;
}
if(f_start || f_stop) return;

tErr = "";
prcSt = "";

//Check for the transport change and connect
if(tr.isEVal() || transport != transport_)	{
	tr = SYS.Transport[transport.parse(0)]["out_"+transport.parse(1)];
	transport_ = transport;
}
if(tr.isEVal())
	tErr = "1:"+tr("Output transport '%1' error.").replace("%1",transport);
else if(addr < 0 || addr > 255)
	tErr = "2:"+tr("Address '%1' out of range [0...255].").replace("%1",addr.toString());
else {
	tmCur = SYS.time();
	tmCurY = tmCurM = tmCurD = tmCurH = 0;
	SYS.localtime(tmCur, 0, 0, tmCurH, tmCurD, tmCurM, tmCurY);

	if(reqCntr < 0) {
		if(tmCur > abs(reqCntr))	reqCntr = 0;
		else tErr = "10:"+tr("No connection, next try after %1 seconds").replace("%1",(abs(reqCntr)-tmCur).toString());
	}

	//Read Instantaneous and Calculated Data
	data = SYS.strFromCharCode(4, 1);
	if(!(tErr=req(data)).toInt()) {
		arguments["dp"] = valGetF(data, 2);
		arguments["p"] = valGetF(data, 6);
		arguments["t"] = valGetF(data, 10);
		arguments["sqrRootExt"] = valGetF(data, 14);
		arguments["f"] = valGetF(data, 18);
		arguments["fTotal"] = valGetF(data, 22);
		arguments["eTotal"] = valGetF(data, 26);
		arguments["fAcc"] = valGetF(data, 30);
		arguments["b"] = valGetF(data, 34);
		arguments["supComprF"] = valGetF(data, 38);
		arguments["Fr"] = valGetF(data, 42);
		arguments["E_D"] = valGetF(data, 46);
		arguments["K"] = valGetF(data, 50);
		arguments["Fb"] = valGetF(data, 54);
		arguments["Fg"] = valGetF(data, 58);
		arguments["Fa"] = valGetF(data, 62);
		arguments["Ftf"] = valGetF(data, 66);
		arguments["Fpb"] = valGetF(data, 70);
		arguments["Ftb"] = valGetF(data, 74);
		arguments["extFY"] = valGetF(data, 78);
		arguments["subFY"] = valGetF(data, 82);
		arguments["yestDayTotal"] = valGetF(data, 86);
		dtTm = data.charCodeAt(95).toString(10,2)+"-"+data.charCodeAt(94).toString(10,2)+"-"+data.charCodeAt(96).toString(10,2)+"T"+data.charCodeAt(97).toString(10,2)+":"+data.charCodeAt(98).toString(10,2)+":"+data.charCodeAt(99).toString(10,2);
	}

	if(!tErr.toInt()) {
		data = SYS.strFromCharCode(0x11, 1);
		if(!(tErr=req(data)).toInt()) {
			factFlowSt = data.charCodeAt(2, "UTF-16LE");
			arguments["factFwv"] = valGetF(data, 4);
			arguments["factWatCnt"] = valGetF(data, 8);
			arguments["factWellStr"] = valGetF(data, 12);
			arguments["factGasVeloc"] = valGetF(data, 16);
			arguments["factLocGrav"] = valGetF(data, 20);
			arguments["factCalbGrav"] = valGetF(data, 24);
		}
	}

	//Requesting the hourly archive
	if(!tErr.toInt() && arhH.length && (tmCur-arhLastH) > 60*60) {
		tmLastY = tmLastM = tmLastD = tmLastH = 0;
		SYS.localtime(arhLastH, 0, 0, tmLastH, tmLastD, tmLastM, tmLastY);

		for(sec = 0; !tErr.toInt() && (SYS.time()-tmCur) < arhTmLim /*&& sec < 3*/; sec++) {
			data = SYS.strFromCharCode(0x15, 1, sec, tmLastM+1, tmLastD, max(0,tmLastY-2000), tmLastH, tmCurM+1, tmCurD, max(0,tmCurY-2000), tmCurH);
			if(!(tErr=req(data)).toInt()) {
				nReqs = data.charCodeAt(2);
				szReq = (data.length-4)/nReqs;
				SYS.messInfo("/PilotOld/"+this.cfg("SHIFR"), "nReqs="+nReqs+"; szReq="+szReq);
				for(rOff = 4, iReq = 0; iReq < nReqs; iReq++, rOff += szReq) {
					arhLastH = SYS.mktime(0, data.charCodeAt(rOff+4), data.charCodeAt(rOff+3), data.charCodeAt(rOff+1), data.charCodeAt(rOff+0)-1, , data.charCodeAt(rOff+2)+2000);
					SYS.messInfo("/PilotOld/"+this.cfg("SHIFR"), "req="+iReq+"; date="+SYS.strftime(arhLastH));
					archSet("fTotal", arhLastH, valGetF(data,rOff+5), arhH);
					archSet("eTotal", arhLastH, valGetF(data,rOff+9), arhH);
					archSet("dp", arhLastH, valGetF(data,rOff+13), arhH);
					archSet("p", arhLastH, valGetF(data,rOff+17), arhH);
					archSet("t", arhLastH, valGetF(data,rOff+21), arhH);
					archSet("sqrRootExt", arhLastH, valGetF(data,rOff+25), arhH);
				}
				SYS.cntrReq(SYS.XMLNode("save").setAttr("path",this.nodePath()+"/%2fobj").setAttr("force",1));
				if(data.charCodeAt(3) == 0)	break;
			}
		}
	}
	if(arhH.length) {
		if((tmCur-arhLastH) < 2*60*60) prcSt += tr("Hours: ") + tr("Trace for current time=%1").replace("%1",SYS.strftime(arhLastH,"%Y/%m/%d %H-%M")) + "; ";
		else prcSt += tr("Hours: ") + tr("Initial reading in time=%1").replace("%1",SYS.strftime(arhLastH,"%Y/%m/%d %H-%M")) + "; ";
	}

	//Requesting the daily archive
	if(!tErr.toInt() && arhD.length && (tmCur-arhLastD) > 24*60*60) {
		tmLastY = tmLastM = tmLastD = 0;
		SYS.localtime(arhLastD, 0, 0, 0, tmLastD, tmLastM, tmLastY);

		for(sec = 0; !tErr.toInt() && (SYS.time()-tmCur) < arhTmLim /*&& sec < 3*/; sec++) {
			data = SYS.strFromCharCode(0x14, 1, sec, tmLastM+1, tmLastD, max(0,tmLastY-2000), tmCurM+1, tmCurD, max(0,tmCurY-2000));
			if(!(tErr=req(data)).toInt()) {
				nReqs = data.charCodeAt(2);
				szReq = (data.length-4)/nReqs;
				SYS.messInfo("/PilotOld/"+this.cfg("SHIFR"), "nReqs="+nReqs+"; szReq="+szReq);
				for(rOff = 4, iReq = 0; iReq < nReqs; iReq++, rOff += szReq) {
					arhLastD = SYS.mktime(0, 0, 0, data.charCodeAt(rOff+1), data.charCodeAt(rOff+0)-1, , data.charCodeAt(rOff+2)+2000);
					SYS.messInfo("/PilotOld/"+this.cfg("SHIFR"), "req="+iReq+"; date="+SYS.strftime(arhLastD));
					archSet("fTotal", arhLastD, valGetF(data,rOff+3), arhD);
					archSet("eTotal", arhLastD, valGetF(data,rOff+7), arhD);
					archSet("dp", arhLastD, valGetF(data,rOff+11), arhD);
					archSet("p", arhLastD, valGetF(data,rOff+15), arhD);
					archSet("t", arhLastD, valGetF(data,rOff+19), arhD);
					archSet("sqrRootExt", arhLastD, valGetF(data,rOff+23), arhD);
				}
				SYS.cntrReq(SYS.XMLNode("save").setAttr("path",this.nodePath()+"/%2fobj").setAttr("force",1));
				if(data.charCodeAt(3) == 0)	break;
			}
		}
	}
	if(arhD.length) {
		if((tmCur-arhLastD) < 2*24*60*60) prcSt += tr("Days: ") + tr("Trace for current time=%1").replace("%1",SYS.strftime(arhLastD,"%Y/%m/%d")) + "; ";
		else prcSt += tr("Days: ") + tr("Initial reading in time=%1").replace("%1",SYS.strftime(arhLastD,"%Y/%m/%d")) + "; ";
	}
}

//Error set
if(!tErr.length)	tErr = "0:Requests="+reqCntr;
if(tErr.toInt()) {
	if(!tr.isEVal() && tr.start()) tr.start(false);
	if(f_err != tErr) {
		SYS.messDebug("/PilotOld/"+this.cfg("SHIFR"), tr("Error")+": "+tErr);
		reqCntr = -(SYS.time()+tmConTry);

		/*aLs = this.nodeList("a_");
		for(iA = 0; iA < aLs.length; iA++)
			if((aPref=aLs[iA].slice(2,5)) == "tbl")
				this[aLs[iA].slice(2)].set(EVAL_INT, 0, 0, true);

		vAcc = dp = p = t = flowTm = grav = C = N = EVAL_REAL;*/
	}
}
else if(prcSt.length)	tErr += "; "+prcSt;
f_err = tErr;