问题描述
在 OS X 中的节点上运行,我正在尝试使用 node-serialport 与之交谈一个阿杜诺.使用 Arduino IDE 的串行监视器或 OS X 实用程序 时,与 Arduino 的所有通信都按预期工作串行工具.但是,当我运行我的节点应用程序时,节点串行端口告诉我连接成功,但我没有得到任何通信.如果我首先使用 Arduino IDE 的串行监视器或串行端口连接到 arduino,然后运行我的节点应用程序,节点应用程序使用节点串行端口发送和接收数据就好了.
Running on node in OS X, I am trying to use node-serialport to talk to an Arduino. All communication to the Arduino works as expected when using Arduino IDE's Serial Monitor, or the OS X utility SerialTools. However, when just running my node app, node-serialport tells me the connection is successful, but I get no communication. If I first make a connection to the arduino with Arduino IDE's Serial Monitor or SerialPorts, then run my node app, the node app sends and receives data just fine using node-serialport.
我不熟悉串行通信,但似乎其他串行实用程序能够正确启动连接(然后可用于 node-serialport),但 node-serialport 无法自行连接.
I'm not familiar with serial communication, but it seems like the other serial utilities are able to properly start a connection (which is then available to node-serialport), but node-serialport is not able to connect on its own.
有没有办法获得绝对所有的连接信息,以便我可以将实用程序的成功连接与节点串行端口的非工作连接进行比较?
Is there a way to get absolutely all connection information, so I can compar the utilities' successful connections to node-serialports non-working connection?
关于为什么会发生这种情况的任何其他想法?
Any other ideas as to why this would be happening?
推荐答案
我有一个可行的解决方案,但不幸的是没有完整的解释.回顾一些相关问题,例如将 DTR/RTS 发送到基于 FTDI 的 Arduino 板后发生了什么?,我确定即使只是重新启动节点应用程序(而不是需要另一个串行连接应用程序),节点也可以通过串行端口.我超出了我的深度,但我怀疑最初建立 RTS 连接会重新启动 arduino,只有在此之后节点串行端口才能通过连接进行通信.
I have a working solution, but unfortunately not a complete explanation. Reviewing some related issues such as What's going on after DTR/RTS is sent to an FTDI-based Arduino board?, I determined that even just restarting the node app (rather than requiring another serial connection app) gave node the ability to communicate through the serial port. I'm beyond my depth, but I suspect that initially establishing the RTS connection restarts the arduino, and only after that happens can node-serialport communicate through the connection.
我的解决方法是在尝试第二个串行端口连接之前简单地给 Arduino 一些时间来重置,这是有效的.
My workaround is to simply give the Arduino some time to reset before attempting a second serialport connection, which works.
var firstConnect = true;
serialPort.open(function (error) {
if (firstConnect){
firstConnect = false;
//First connection, letting Arduino reset
setTimeout(function(){serialPort.open()},4000)
} else {
//Second connection, which will work
serialPort.on('data', function(data) {
//data parsing function
//...
}
}
});
这篇关于如果另一个应用程序已经连接到端口,则节点串行端口仅与 Arduino 通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!