thats why in my version i only ever call the repeat function in the return of the exec. So it doesnt do anything like that. Did you look at the code i send you in the pm
So i started working on the listen node , and i have a problem with spawning the minimodem --rx + options + baudmode
I am using child_process
-s spawn
and i cant configure it to run as it should
After reading the documentation and copying the sample code to mine project i always get an error from minimodem stderr: usage: minimodem [--tx|--rx] [options] {baudmode}
Here is my code:
function getlisten(options){
const ls = spawn("minimodem" ,[ options + " 300" ]);
node.status({fill:"blue", shape:"dot", text:"Listening!"})
ls.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
ls.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
ls.on('error', (error) => {
console.log(`error: ${error.message}`);
});
ls.on("close", code => {
console.log(`child process exited with code ${code}`);
});
}
options is a string (eg: --auto-carrier --confidence 2.5 )
300 should be replaced with baudmode variable.
I tried several different orders but none is working as it should!
So aperantly there was a really simple sollution for this
Just by adding the ' before and after options string it got working!
const ls = spawn("minimodem" ,[ + "'" + options +"'" + " 300" ]);
Normally this shouldnāt be necessary and its not really the recommended way. What is true is that the child_process.spawn() exepects an array of arguments with one argument per array element and not one string of options. So it should be something like really to use it correctly : spawn("minimode",["--auto-carrier","--confidence","2.5","300"]);
Okay i will convert the options string to an array and will try again , so far the minimodem executes successfully , but i do not get any data from it
Can anyone help? Decided to ask a question after being stuck for a whole day...
Stackoverflow Question.
Maybe try a function something like this:
let timeout = false;
let outputBufferArr = [];
function timeoutConcat(data){
if(timeout) {
clearTimeout(timeout);
timeout = false;
}
outputBufferArr.push(data);
timeout = setTimeout(()=>{
let message = Buffer.concat(outputBufferArr);
console.log(message.toString());
outputBufferArr = [];
}, 500);
}
which you call from the stdout on data part:
minimodem.stdout.on('data', (data)=>{
timeoutConcat(data);
});
Not tested at all just wrote down what i think might work logically.
It should in theory log the output of all data received so far as soon as no new data arrives for 500 ms.
Thank you for your quick answer once again sir Will test it right now
i edited the code above, of course the variables need to be declared as let or var and not const and it was logging the wrong var too. That happens when you write code free form late at night
Yes i just saw that error
Well its working great i think i would experiment with the 500ms delay (probably add a setting for it) so user can edit it.
I took a brake from 7pm to 10pm so i am ready to roll the entire night
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.