From 0507a4a39fffe0731b3031c725fa8df5437b526c Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Sat, 20 Jul 2013 12:41:19 +0200 Subject: [PATCH 1/2] Add a encoding parameter for readline Cleaned up pull request of #129 by @crenovator and @genedna. Optionally allows setting of alternative Buffer encodings besides UTF-8. --- serialport.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/serialport.js b/serialport.js index 14773f7..4988b14 100644 --- a/serialport.js +++ b/serialport.js @@ -22,13 +22,14 @@ var parsers = { raw: function (emitter, buffer) { emitter.emit("data", buffer); }, - readline: function (delimiter) { + readline: function (delimiter, encoding) { if (typeof delimiter === "undefined" || delimiter === null) { delimiter = "\r"; } + if (typeof encoding === "undefined" || encoding === null) { encoding = "utf8"; } // Delimiter buffer saved in closure var data = ""; return function (emitter, buffer) { // Collect data - data += buffer.toString(); + data += buffer.toString(encoding); // Split collected data by delimiter var parts = data.split(delimiter) data = parts.pop(); From 19887d3002a07e1b3c791b5ca5cbf5f319a296ec Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Sat, 20 Jul 2013 12:43:34 +0200 Subject: [PATCH 2/2] Add comment listing available encodings. --- serialport.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serialport.js b/serialport.js index 4988b14..afcc6d7 100644 --- a/serialport.js +++ b/serialport.js @@ -22,6 +22,8 @@ var parsers = { raw: function (emitter, buffer) { emitter.emit("data", buffer); }, + //encoding: ascii utf8 utf16le ucs2 base64 binary hex + //More: http://nodejs.org/api/buffer.html#buffer_buffer readline: function (delimiter, encoding) { if (typeof delimiter === "undefined" || delimiter === null) { delimiter = "\r"; } if (typeof encoding === "undefined" || encoding === null) { encoding = "utf8"; }