Node-red-node-serialport : change baudrate on the fly

Hi here,

I am using intensively the serialport node and need to have the ability to change the baudrate on the fly.

This is possible and I was able to modify the node to do so.
In fact, I would like to share the modification but I don't know the process. It is the first time I use github and I am not a professionnal developper.

Any help would be greatly appreciated.

Modification is here :

1 Like

Sorry, I'm also new to node-red, so I can't help with that, but I was looking for change baudrate dynamically, so I'll have a look to your code.

How do you modify baudrate from function node?

In order to publish your node I think you should follow packaging instructions at https://nodered.org/docs/creating-nodes/packaging

from the look of it you send in a msg with a property .baudrate and it changes it . This means you can only do this by sending a message to an out node and it will change both the in and the out.

1 Like

You are right.
In addition, if payload is absent, nothing is sent out.

Can I change the com port same way? I tried with port and serialport property, but it did not work.

Hi, copy this code in ******* REQUEST ********* after node.on(...

if (msg.hasOwnProperty("baudrate")) {
var baud = parseInt(msg.baudrate);
if (baud == NaN) {
var errmsg = err.toString().replace("Serialport","Serialport "+node.port.serial.path);
node.error(errmsg,"Cannot parse baudrate property");
} else {
node.port.update({baudRate: baud},function(err,res) {
if (err) {
var errmsg = err.toString().replace("Serialport","Serialport "+node.port.serial.path);
node.error(errmsg,msg);
}
});
}
}

verify if there is the function serial.update after write function:

write: function(m,cb) { this.serial.write(m,cb); },
update: function(m,cb) { this.serial.update(m,cb); },

now you can use request node and send msg.baudrate

Hi, did you find a way to change the COM port ? Thanks

Hi,

As I'm using the baudrate change on my projects and I don't want to stay with 'specific" nodes, I will create a pull request.

It is the first time for me making a pull request, hope it will be accepted.

EDIT: