Orfait  
                
               
                 
              
                  
                    26 October 2018 09:34
                   
                   
              1 
               
             
            
              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 : 
  
  
    
module.exports = function(RED) {
    "use strict";
    var settings = RED.settings;
    var events = require("events");
    var serialp = require("serialport");
    var bufMaxSize = 32768;  // Max serial buffer size, for inputs...
    // TODO: 'serialPool' should be encapsulated in SerialPortNode
    // Configuration Node
    function SerialPortNode(n) {
        RED.nodes.createNode(this,n);
        this.serialport = n.serialport;
        this.newline = n.newline; /* overloaded: split character, timeout, or character count */
        this.addchar = n.addchar || "false";
        this.serialbaud = parseInt(n.serialbaud) || 57600;
        this.databits = parseInt(n.databits) || 8;
        this.parity = n.parity || "none";
        this.stopbits = parseInt(n.stopbits) || 1;
 
  This file has been truncated. show original 
   
  
    
    
  
  
 
             
            
               
               
              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 
            
            
           
          
            
              
                Orfait  
                
               
              
                  
                    11 December 2018 15:45
                   
                   
              4 
               
             
            
              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.
             
            
               
               
               
            
            
           
          
            
              
                linho  
                
               
              
                  
                    6 June 2019 12:22
                   
                   
              6 
               
             
            
              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: 
  
  
    
  
  
    
    
      node-red:master ā Orfait:master
    
    
      
        opened 09:27AM - 26 Aug 20 UTC