Skip to content

Commit

Permalink
ensure line-break is received when opening a serial connection to a d…
Browse files Browse the repository at this point in the history
…evice
  • Loading branch information
busticated committed Dec 1, 2020
1 parent 7e28774 commit d0436d2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/ymodem.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ module.exports = class YModem {
}

// wait for initial response
const readyMsg = "Waiting for the binary file to be sent ... (press 'a' to abort)";
const linebreakPtn = /\r?\n/;
let line = '';
function cmdResponse(){
let data = self.port.read();
self._logData(data);
line += data.toString();
const lines = line.split(linebreakPtn);
// if not in listening mode, we get CRC16 back
// if in listening mode, we get this string
if (data[0] === ymodem.CRC16 || line.trim() === "Waiting for the binary file to be sent ... (press 'a' to abort)"){
// if in listening mode, we get the ready message
if (data[0] === ymodem.CRC16 || (lines.length > 1 && lines.some(l => l === readyMsg))){
self.port.removeListener('readable', cmdResponse);
return resolve();
}
Expand Down

0 comments on commit d0436d2

Please sign in to comment.