Michael
Michael

Reputation: 903

Read SerialPort with node-serial

I am trying to read a RS232 Serial Port with a Mag Stripe reader in Ubuntu. I have a USB one working fine (ID-Tech). But I am trying to get a Neuron reader to work as well. I am unfamiliar Serial Port communication in general, but with node-serial i wrote a simple app that sits and waits for a device:

node tester.js /dev/ttyS0 

Than spits out the output from the card reader. Works great with the USB ID-Tech reader, but when I have the Serial Port device plugged in I get nothing. I'm also a bit unsure on how to tell which Serial Port it's using. Is there a better tool to "probe" the serial ports in Ubuntu and figure out which one is in use by the Mag Reader?

UPDATE

Researching around it seems the tools to use are:

sudo cat /dev/ttyS0

The problem I'm having is which port is the device attached to, doing the above on ttyS0,1,2,3 does nothing and should dump out some output from the device. However I'm not sure if this needs to be run first:

sudo inputattach -dump /dev/ttyS0

This just hangs at the cursor and I figured to try and keyboard type for the card reader, but same issue just hangs. The output from dmesg | grep ttyS shows ports enabled:

[    1.906700] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    1.927250] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[    1.947758] serial8250: ttyS2 at I/O 0x3e8 (irq = 4) is a 16550A
[    1.968273] serial8250: ttyS3 at I/O 0x2e8 (irq = 3) is a 16550A
[    1.990199] 00:04: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    2.010770] 00:05: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[    2.031335] 00:06: ttyS2 at I/O 0x3e8 (irq = 5) is a 16550A
[    2.051952] 00:07: ttyS3 at I/O 0x2e8 (irq = 11) is a 16550A

Upvotes: 2

Views: 5689

Answers (1)

ladislas
ladislas

Reputation: 3070

With your device plugged in, you can run this node code and check the info of every ports. You will likely recognize something and that's the port your looking for.

var serialport = require("serialport");

serialport.list(function (err, ports) {
    ports.forEach(function(port) {

        console.log("pnpId: " + port.pnpId);
        console.log("manufacturer: " + port.manufacturer);
        console.log("comName: " + port.comName);
        console.log("serialNumber: " + port.serialNumber);
        console.log("vendorId: " + port.vendorId);
        console.log("productId: " + port.productId);
    });
});

then you connect using:

var myPort = new SerialPort("/dev/ttyACM0", { // replace ttyACM0 with the right port on your computer
    baudrate: 115200,
    parser: serialport.parsers.readline("\r\n")
});

Hope it helps!

Upvotes: 1

Related Questions