diff --git a/io/rawserial/26-rawserial.html b/io/rawserial/26-rawserial.html
index c7b7c362..5bf3a7e3 100644
--- a/io/rawserial/26-rawserial.html
+++ b/io/rawserial/26-rawserial.html
@@ -16,17 +16,43 @@
diff --git a/io/rawserial/26-rawserial.js b/io/rawserial/26-rawserial.js
index da53dfe8..11762005 100644
--- a/io/rawserial/26-rawserial.js
+++ b/io/rawserial/26-rawserial.js
@@ -29,25 +29,57 @@ if (!plat.match(/^win/)) {
function RawSerialInNode(n) {
RED.nodes.createNode(this,n);
this.port = n.port;
- this.split = n.split||null;
- if (this.split == '\\n') this.split = "\n";
- if (this.split == '\\r') this.split = "\r";
+ this.splitc = n.splitc||null;
+ this.out = n.out||"char";
+ this.bin = n.bin||false;
+ if (this.splitc == '\\n') this.splitc = "\n";
+ if (this.splitc == '\\r') this.splitc = "\r";
+ if (!isNaN(parseInt(this.splitc))) { this.splitc = parseInt(this.splitc); }
+ console.log("Split is",this.out,this.splitc);
var node = this;
var setupSerial = function() {
node.inp = fs.createReadStream(pre+node.port);
node.log("opened "+pre+node.port);
- node.inp.setEncoding('utf8');
+ node.tout = null;
var line = "";
+ var buf = new Buffer(32768);
+ var i = 0;
node.inp.on('data', function (data) {
- if (node.split != null) {
- if (data == node.split) {
- node.send({payload:line});
- line = "";
+ for (var z = 0; z < data.length; z++) {
+ if ((node.out === "time") && (node.splitc != 0)) {
+ if (node.tout) {
+ i += 1;
+ buf[i] = data[z];
+ }
+ else {
+ node.tout = setTimeout(function () {
+ node.tout = null;
+ var m = new Buffer(i+1);
+ buf.copy(m,0,0,i+1);
+ if (node.bin !== "true") { m = m.toString(); }
+ node.send({"payload": m});
+ }, node.splitc);
+ i = 0;
+ buf[0] = data[z];
+ }
+ }
+ else if ((node.out == "char") && (node.splitc != null)) {
+ buf[i] = data[z];
+ i += 1;
+ if ((data[z] === node.splitc.charCodeAt(0)) || (i === 32768)) {
+ var m = new Buffer(i);
+ buf.copy(m,0,0,i);
+ if (node.bin !== "true") { m = m.toString(); }
+ node.send({"payload":m});
+ i = 0;
+ }
+ }
+ else {
+ if (node.bin !== "true") { node.send({"payload": String.fromCharCode(data[z])}); }
+ else { node.send({"payload": new Buffer([data[z]])});}
}
- else { line += data; }
}
- else { node.send({payload:data}); }
});
//node.inp.on('end', function (error) {console.log("End", error);});
node.inp.on('close', function (error) {