I am creating a bootloader that reads data from a text file, sends each line to the device, and waits for confirmation that the line has been written to the device's firmware before proceeding to the next line.
So I am now using the async modules, which allow me to wait for a command to be executed before moving forward by calling the cb() callback, however I need to only move forward after data is received and validated by the SerialPort.onData() callback.
Problem is, I cannot figure out how to include the data returned by the callback into the async loop, as the callback should only be initiated once for each port, and I therefore cannot simply include it in the async eachSeries loop.
Any suggestions on how I can feed the data received back from the onData callback so that it can be validated against the data sent before proceeding to the next line ??
function cl(dat){return console.log(dat);}
port.open(function(err){
fs.readFile('CS-BT_J.hex', function(err, f){
var hex = f.toString().split('\n');
var async = require("async");
async.eachSeries(hex, function(item,cb){
outStr = String.fromCharCode(1) + item + String.fromCharCode(13);
port.write(outStr, function(err,res) {});
cb();
},function(err){});
});
port.on("data", function (data) {
cl(data);
//if(data == addr) cb();
});
});