Skip to content

Commit

Permalink
Unescape hex/unicode for sample serial data (qzind#949)
Browse files Browse the repository at this point in the history
Unescape hex/unicode for sample serial data, qzind#877
  • Loading branch information
Brett Berenz authored Mar 31, 2022
1 parent fbcd9ef commit 25f7576
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,14 @@ <h4 class="panel-title">Options</h4>
type: $("input[name='serialType']:checked").val(),
data: $("#serialCmd").val()
};
//allow some escape characters
serialData.data = serialData.data.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t");

var fromHex = function(m, s1) {
return String.fromCharCode(parseInt(s1, 16));
};

//allow some escape characters (newlines, tabs, hex/unicode)
serialData.data = serialData.data.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t")
.replace(/\\x([0-9A-Za-z]{2})/g, fromHex).replace(/\\u([0-9A-Za-z]{4})/g, fromHex);

qz.serial.sendData($("#serialPort").val(), serialData, options).catch(displayError);
}
Expand Down

0 comments on commit 25f7576

Please sign in to comment.