mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Tweak serial to outpur correct number of chars from buffer.
Having counted the correct number into the buffer it seems a shame not to send them all out to the next node... (Also allow separator char to be specified as hex (eg 0x0a))
This commit is contained in:
parent
cf70fee8c7
commit
7c7f030aa8
@ -27,10 +27,9 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="serial in">
|
||||
<p>Reads data from a local serial port.</p>
|
||||
<p>Can either <ul><li>wait for a "split" character (default \n)</li>
|
||||
<p>Can either <ul><li>wait for a "split" character (default \n). Also accepts hex notation (0x0a).</li>
|
||||
<li>Wait for a timeout in milliseconds for the first character received</li>
|
||||
<li>Wait to fill a fixed sized buffer</li>
|
||||
</ul>
|
||||
<li>Wait to fill a fixed sized buffer</li></ul></p>
|
||||
<p>It then outputs <b>msg.payload</b> as either a UTF8 ascii string or a binary Buffer object.</p>
|
||||
<p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters is sent - again either as ascii chars or size 1 binary buffers.</p>
|
||||
</script>
|
||||
|
@ -114,7 +114,13 @@ module.exports = function(RED) {
|
||||
this.serialConfig.stopbits,
|
||||
this.serialConfig.newline
|
||||
);
|
||||
var splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"));
|
||||
|
||||
if (node.serialConfig.newline.substr(0,2) == "0x") {
|
||||
var splitc = new Buffer([parseInt(node.serialConfig.newline)]);
|
||||
} else {
|
||||
var splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"));
|
||||
}
|
||||
|
||||
this.port.on('data', function(msg) {
|
||||
// single char buffer
|
||||
if ((node.serialConfig.newline == 0)||(node.serialConfig.newline == "")) {
|
||||
@ -145,9 +151,9 @@ module.exports = function(RED) {
|
||||
else if (node.serialConfig.out === "count") {
|
||||
buf[i] = msg;
|
||||
i += 1;
|
||||
if ( i >= Number(node.serialConfig.newline)) {
|
||||
if ( i >= parseInt(node.serialConfig.newline)) {
|
||||
var m = new Buffer(i);
|
||||
buf.copy(m,0,0,i-1);
|
||||
buf.copy(m,0,0,i);
|
||||
if (node.serialConfig.bin !== "bin") { m = m.toString(); }
|
||||
node.send({"payload":m});
|
||||
m = null;
|
||||
|
Loading…
Reference in New Issue
Block a user