From 25f7576454b53108209c89044b528fdadfdc141d Mon Sep 17 00:00:00 2001 From: Brett Berenz Date: Thu, 31 Mar 2022 01:33:49 -0400 Subject: [PATCH] Unescape hex/unicode for sample serial data (#949) Unescape hex/unicode for sample serial data, #877 --- sample.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sample.html b/sample.html index c516e129a..49ea07916 100755 --- a/sample.html +++ b/sample.html @@ -2021,8 +2021,14 @@

Options

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); }