2013-07-11 18 views
1

我想在Ubuntu中使用Mag Stripe读取器读取RS232串行端口。我有一个USB工作正常(ID技术)。但是我想让神经元读者也能工作。我一般不熟悉的串口通信,但与节点串行我写了一个简单的应用程序,坐着等待设备:使用节点序列读取串行端口

node tester.js /dev/ttyS0 

比吐出从读卡器输出。 USB ID-Tech阅读器非常有效,但是当我插入串口设备时,我什么也得不到。我也不确定如何判断它使用的是哪个串行端口。有没有更好的工具来“探测”Ubuntu中的串行端口,并找出Mag Reader正在使用哪一个?

UPDATE

周围似乎研究所用的工具有:

sudo cat /dev/ttyS0 

我遇到的问题是哪个端口连接到设备上,做上述上ttyS0,1,2 ,3什么也不做,并应该从设备中输出一些输出。但是我不知道这是否需要先运行:

sudo inputattach -dump /dev/ttyS0 

这只是挂在光标,我想尝试和键盘类型的读卡器,但同样的问题,只是挂起。来自dmesg |的输出grep ttyS显示启用的端口:

[ 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 
+0

您是否有什么能够真正验证串口上的电气活动,例如带有LED的加密狗,或者您知道其他设备实际上是否可以通过串行连接正常工作?测试将是一个简单的事情发送一些字节到端口和看灯闪烁。 –

+0

谢谢,所以在Linux中,我假设我只是写入串行端口,并期望在设备上有一些反馈? – Michael

+0

是的,假设您可以以可见的方式这样做。例如每半秒钟提升和降低RTS或CTS系列(过去一段时间)。 –

回答

0

插入设备后,您可以运行此节点代码并检查每个端口的信息。你可能会认识一些东西,那就是你要找的港口。

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); 
    }); 
}); 

然后您连接使用:

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

希望它能帮助!

+0

你可以看看[这个](https://stackoverflow.com/questions/45936310/serialport-module-in-node-js-works-only-if-minicom-is-active-on-the-端口)问题?将不胜感激任何指针... – Sam