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

**URL:** <https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313>\
**Category:** General\
**Created:** [26 October 2018 09:34 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313 "2018-10-26T09:34:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orfait](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orfait/32/6108_2.png) [@Orfait](https://discourse.nodered.org/u/Orfait)\
**Post date:** [26 October 2018 09:34 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/1 "2018-10-26T09:34:18Z")

</div>

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 :

> <https://github.com/Orfait/node-red-nodes/blob/master/io/serialport/25-serial.js>

---

<div class="post-metadata">

**Author:** ![david.fs](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/david.fs/32/99_2.png) [@david.fs](https://discourse.nodered.org/u/david.fs)\
**Post date:** [11 December 2018 10:39 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/2 "2018-12-11T10:39:21Z")

</div>

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](https://nodered.org/docs/creating-nodes/packaging)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 December 2018 14:28 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/3 "2018-12-11T14:28:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Orfait](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orfait/32/6108_2.png) [@Orfait](https://discourse.nodered.org/u/Orfait)\
**Post date:** [11 December 2018 15:45 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/4 "2018-12-11T15:45:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dharminec1](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dharminec1](https://discourse.nodered.org/u/dharminec1)\
**Post date:** [16 February 2019 21:37 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/5 "2019-02-16T21:37:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![linho](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@linho](https://discourse.nodered.org/u/linho)\
**Post date:** [6 June 2019 12:22 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/6 "2019-06-06T12:22:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charlotte](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@Charlotte](https://discourse.nodered.org/u/Charlotte)\
**Post date:** [25 October 2019 11:23 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/7 "2019-10-25T11:23:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Orfait](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/orfait/32/6108_2.png) [@Orfait](https://discourse.nodered.org/u/Orfait)\
**Post date:** [26 August 2020 08:41 UTC](https://discourse.nodered.org/t/node-red-node-serialport-change-baudrate-on-the-fly/4313/8 "2020-08-26T08:41:35Z")

</div>

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:

> <https://github.com/node-red/node-red-nodes/pull/675>
