Skip to content

Commit

Permalink
Changed from @rblakesley to handle errors during write when unexpecte…
Browse files Browse the repository at this point in the history
…dly disconnected
  • Loading branch information
gfwilliams committed Oct 22, 2024
1 parent 41331a6 commit c3ca6c7
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions uart.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,22 +793,23 @@ To do:
};
connection.write = function(data, callback) {
// TODO: progress?
writer = serialPort.writable.getWriter();
log(2, "Sending "+ JSON.stringify(data));
return new Promise((resolve, reject) => {
if (!serialPort) reject ("Not connected");
writer = serialPort.writable.getWriter();
log(2, "Sending "+ JSON.stringify(data));
writer.write(str2ab(data)).then(function() {
writer.releaseLock();
writer = undefined;
log(3, "Sent");
if (callback) callback();
writer.releaseLock();
writer = undefined;
log(3, "Sent");
if (callback) callback();
resolve();
}).catch(function(error) {
if (writer) {
writer.releaseLock();
writer.close();
}
writer = undefined;
log(0,'SEND ERROR: ' + error);
}).catch(function(error) {
if (writer) {
writer.releaseLock();
writer.close();
}
writer = undefined;
log(0,'SEND ERROR: ' + error);
reject(error);
});
});
Expand Down

0 comments on commit c3ca6c7

Please sign in to comment.