1

I'm looking to automate a process i already have working with the Eltima Serial Port Monitor. I have a piece of hardware with its proprietary software, which shows me data it receives over serial, but will not allow any datalog natively. I use the serial port monitor to sniff the communication, then filter down just the data i need, then process the text file output until i get what i want. My question regards node-serialport or socket.io or similar in order to sniff an already open port? I know i could open the port using those, but for starters, i'd prefer to just piggyback something on the existing connection, and simply skim the information i require without delving into the specifics of how the provided windows app talks to the hardware.

I apologize if the question seems elaborate, but i'm just looking to be pointed in the direction of something which is known to work, not to be given a complete solution. I don't have a lot of time to devote to this, and would rather not have to learn a framework just to find out it simply doesn't do the thing i wanted to use it for. Can someone please confirm whether a node solution can listen in on an already active port?

domi
  • 123
  • 1
  • 9

1 Answers1

3

of course you can read stream from the serial ports. One way i can imagine is ( in linux environment because i feel more confortable with it ) : considering you can print the stream as plain text

cat /dev/ttyS0 

you can create and call a bash where you can just read the serial port you will need to know is in which tty is establishing and after that you can redirect stdout to file and do some greps ... etc etc , after you can use file watchers to trigger an action when you receive desired values.

Anyway it's just on of the most quickest ways ( probably not the best optimal )

About reading serial ports with node.js there are tons of examples and libraries surfing on internet for example this :

https://www.npmjs.com/package/serialport

Install the library :

npm install --save-dev serialport

And after something moreless like this ( i didn't tried ) just following some docs :

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
/*need to know in which port is connected in case of windows i think 
COM1*/
var serialPort = new SerialPort("/dev/ttyS0", {
  baudrate: 9600,
  parser: serialport.parsers.readline("\n")
});

serialPort.on("open", function () {
 console.log('open');
  serialPort.on('data', function(data) {
  console.log(data);
  });
});

Hope I helped

Good luck!

Joaquin Javi
  • 880
  • 7
  • 12
  • Thanks for the direction with bash. I might try that if everything else fails, but as a plan A i'd like to find something node. I was reading that documentation earlier, but all the examples had to do with opening a port through node. In my brief experience with monitoring serial ports, i've already faced a few softwares which can only work with a port they hold open, and cannot read what's being passed on an already open port. Do you know if this library can monitor a port held by another process? – domi May 14 '18 at 16:00
  • I was surfering on the docs and seem's not ... i will check in more deeply when i will have a while. Many time ago i built some programs to flash firmware trough serial... and i remembering did it by redirecting output to a file and with file watchers , i had meany problems to accomplish it with node.js ( because is single thread process ) so i moved to write it in Java , which is multi thread (you can spawn parallel works) and it worked like a charm! – Joaquin Javi May 14 '18 at 16:15
  • @JoaquinJavi Hi, sorry to ressurect this post but I'm trying to install this package on my node and it has been failing for more than two hours now: "error code 1" "error path serial/bindings" "node-gyp not recognized", etc. Any ideas? – Pedro Araujo Jorge Nov 06 '20 at 17:31
  • This seem's node version issue try to install nvm and use a lower version such as 6 or 10 ... – Joaquin Javi Nov 07 '20 at 14:53