Skip to content

Commit

Permalink
request node corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
hilschernetpi committed Jul 8, 2019
1 parent 6d171d9 commit 3d320e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
RUN [ "cross-build-start" ]

#version
ENV HILSCHERNETPI_NODERED_NPIX_RS485_VERSION 1.0.1
ENV HILSCHERNETPI_NODERED_NPIX_RS485_VERSION 1.0.2

#labeling
LABEL maintainer="netpi@hilscher.com" \
Expand Down
49 changes: 36 additions & 13 deletions node-red-contrib-npix-rs485/25-serial-rs485.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,42 @@ module.exports = function(RED) {
if (this.serialConfig) {
var node = this;
node.port = serialPool.get(this.serialConfig);
// Serial Out
node.on("input",function(msg) {
if (!msg.hasOwnProperty("payload")) { return; } // do nothing unless we have a payload
if (msg.hasOwnProperty("count") && (typeof msg.count === "number") && (node.serialConfig.out === "count")) {
node.serialConfig.newline = msg.count;
// take control of GPIO 17
gpio.setup(11, gpio.DIR_LOW, function (err) {
if (err) {
RED.log.warn(" Setting GPIO 17 to output failed");
} else {
// Serial Out
node.on("input",function(msg) {
if (!msg.hasOwnProperty("payload")) { return; } // do nothing unless we have a payload
if (msg.hasOwnProperty("count") && (typeof msg.count === "number") && (node.serialConfig.out === "count")) {
node.serialConfig.newline = msg.count;
}
if (msg.hasOwnProperty("flush") && msg.flush === true) { node.port.serial.flush(); }
node.status({fill:"yellow",shape:"dot",text:"serial.status.waiting"});
// !!!!Modification !!!!! get Mutex, set RS485 TX enable to high first, then send
mutex.lock(function () {
gpio.write(11, true, function(err) {
node.port.enqueue(msg,node,function(err,res) {
if (err) {
var errmsg = err.toString().replace("Serialport","Serialport "+node.port.serial.path);
node.error(errmsg,msg);
mutex.unlock();
} else {
// !!!!!Modification!!!! Wait till all data has been transmitted
node.port.drain(function(err) {
// set RS485 TX enable to low
gpio.write(11, false, function(err){
// unlock mutex
mutex.unlock();
});
});
}
});
});
});
});
}
if (msg.hasOwnProperty("flush") && msg.flush === true) { node.port.serial.flush(); }
node.status({fill:"yellow",shape:"dot",text:"serial.status.waiting"});
node.port.enqueue(msg,node,function(err,res) {
if (err) {
var errmsg = err.toString().replace("Serialport","Serialport "+node.port.serial.path);
node.error(errmsg,msg);
}
});
});

// Serial In
Expand Down Expand Up @@ -490,3 +512,4 @@ module.exports = function(RED) {
});
}


0 comments on commit 3d320e2

Please sign in to comment.