Node-red-node-serialport port selection

When the node-red starts, the flow(program) picks up the hard-coded serial ports and open them. But when a device re-connects after disconnecting for any reason, it may be possible the port number change, but the end user of the flow can't change the port unless he/she has the access to the node-red editor.

Recently I had to develop a feature on top of node-red-node-serialport that enables the end user of node-red to change the port number/name without the access to the node-red editor.

I would like to contribute my work to node-red-node-serialport, and I would like to understand & follow the procedures to do this.

Please advise.
Thanks.

1 Like

Hi @yhur, welcome to the forum and thanks for your contribution.

I have moved this to the feature requests category and tagged with the module name.

The core devs generally prefer to see suggestions appear here in the forum first so that they can be discussed. If they agree that it is worth looking at further, they will probably ask you to do a PR.

Sure,
The main work is as follows.

  1. SerialPortNode was changed to have a new function close the current port and open a new port with passed parameters like port number/name, baudrate, databits, parity, stopbits, and so on.
  2. SerialOutNode and SerialInNode are modified to reflect newly changed port connection on 'newport' event.
  3. a new PortSelectNode is introduced that has in and out ports. It receives the port config information, updates, emit 'newport' event.

This is the basic idea implemented. And this is the diff of the changes

Hi @yhur thanks for your efforts & your desire to feedback into the community. It is much appreciated.

Can I ask you to do some screenshots or better still - a short video that demonstrates the features you are adding?

This will permit us to quickly understand the features & make sense of your offering. I'm sure it is all good but we might spot soothing that needs addressing before accepting a pr. I'm sure you understand.

Would that be something you could provide please?

Do you mean here, when the interface (eg /dev/ttyUSB0 or COM1) disconnects and reconnects as /dev/ttyUSB1, rather than a device disconnecting from the serial interface, but the interface remains active in the system.

Yes, I think you got me there.

To repeat, what I meant was the user physically disconnecting and reconnecting the device. For Linux and macOS, it's not big problem, but for Windows, the COM? port may or may not change. Besides, the project team who used my work needed to connect several different devices in turn to test with them.

Hi @Steve-Mcl , I'll take footage and post it here some time later today.

Hi @Steve-Mcl , here is the footage.

https://github.com/yhur/node-red-nodes/assets/13171662/5d5f2e7b-0cc8-421c-ad05-6361a4ececdd

That still is ambiguous. For example, if I have a USB serial adaptor wired to a serial slave of some sort, if I disconnect the wire from the slave and reconnect it then the port should not change. If, however, I unplug the serial adaptor from the USB socket and plug it in again, then the port may change.

Colin, for the purposes of this request I don't think it matters. He just wants the ability for the end user to be able to change / select which serial port they want to use without editing the flow itself, whether it has changed replugging USB and it moving or the user plugging a device into a different port.

@Colin,
Sorry for the unclear explanation on device. What you said later is what I meant. As you said when the USB FTDI device is unplugged and replugged there are chances the port number change on the Windows.

@dceejay, I appreciate your insight. Thanks.

This will be handy to use the /dev/serial/by-id/xxx locations also, that will stop port names changing in *nix

But not in Windows which I think the OP is asking about. There you only have COMn: ports which can indeed swap around.

and some dodgy clone usb chips have identical IDs - so if you plug in more than one it can get confusing also...

But regardless - this suggestion of a new way of letting the user manage the port does seem to have merit. IE having a separate node to manage the underlying control node - so advanced users can use it if they want to - but for simple use cases it is not necessary and doesn't add extra complexity to the existing simple in and out nodes.

3 Likes

I know, but for others finding this I thought it was useful to clarify that disconnecting the serial device (not the adaptor) should not cause the com port to change.

@dceejay,
I agree with you to that we shouldn't bring any unnecessary complexity.

So I keep the backward compatibility which gives

  1. no additional work or procedure to use it if they want to use it the way they used to.
  2. the existing flows works without break with this update
  3. and then if the user would like to bring in the port selection capability to even existing flow, they can just drag & drop the newly added port select node and program the dialog as shown in this link https://github.com/yhur/node-red-nodes/assets/13171662/5d5f2e7b-0cc8-421c-ad05-6361a4ececdd

Hope this clarifies the suggestion and the implementation. :wink:

1 Like

Yes please raise a PR so we can try/look at it.. Thanks

Great!

I'm glad to have my code considered for the contribution. I'll raise a PR with my code. Thanks.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.