javascript - How to set a variable in a child process in Node.JS? -


i´m having troubles setting variable in child process node.js.

my code passing looks this:

parent.js:

var spawn = require("child_process").spawn;  // run node app.js file argument var child = spawn("node", ["app.js"]);  // send data child process via stdin stream child.stdin.setencoding = "utf-8"; child.stdin.write(parsefloat("45.00").tofixed(2));  // listen response child: child.stdout.on("data", function (data) {     console.log("got data child: " + data); }); 

app.js:

var temp;  process.stdin.setencoding("utf8"); process.stdin.on("readable", function(){     temp = process.stdin.read();     return temp; }); 

then function in child-process should set variable temp setpoint pid - controll:

ctrl.setpoint(readsetpoint()); ctrl.setinput(readinput()); ctrl.compute();  output = parsefloat(ctrl.myoutput).tofixed(2);  function readsetpoint(){         return temp;     }  function readinput() {         v = sensor.value;         return input = (parsefloat(fmap(v, 484, 550, 27.8, 66))).tofixed(2);     }   console.log("input:" + input);  console.log("output:" + output); 

when set variable temp = parsefloat("45.00") in app.js, pid controll heats 45° c want set target temperature via parent.js.

atm i´ll

got data child: input:24.33

got data child: output:nan

and heater not heat guess setpoint not set.

i´m beginner in programming atm i´m kind of lost. appreciated, thanks

kind regards


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -