I am trying to read data from a file very quickly (data from an ADC). The conversion is started on opening the file, and finished at close. I need to wait opening the file again, and wait for the currently conversion to complete.
My problem is, that when i am opening the file very quickly nodejs wont caught the expected events. Any clue how to fix this?
node.on('input', function(){
readStream = fs.createReadStream(path.location,{encoding: 'utf8'});
if (readyFlag == 1) {
readStream.on('data',(data) => {
data = {payload: data/1000};
node.send(data);
console.log(`data: ${data}`);
})
}
readStream.on('open', () => {
console.log("file opened");
readyFlag = 0;
})
readStream.on('close', () => {
console.log("file closed");
readyFlag = 1;
})
readStream.on('error', (err) => {
console.log(err);
})
})
I end up with the file being opened all the time.