仅当另一个应用程序已连接到端口时,node-serialport才与Arduino通信 [英] node-serialport only communicates with Arduino if another app has already connected to the port

查看:95
本文介绍了仅当另一个应用程序已连接到端口时,node-serialport才与Arduino通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X中的节点上运行,我试图使用 node-serialport 与之交谈一个Arduino使用Arduino IDE的串行监视器或OS X实用程序 SerialTools .但是,当仅运行我的节点应用程序时,node-serialport会告诉我连接成功,但是没有任何通信.如果我首先使用Arduino IDE的Serial Monitor或SerialPorts连接到arduino,然后运行我的节点应用程序,则该节点应用程序可以使用node-serialport发送和接收数据.

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.

有没有一种方法可以获取绝对的所有连接信息,因此我可以将实用程序的成功连接与node-serialports非工作连接进行比较?

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?

推荐答案

我有一个可行的解决方案,但不幸的是没有完整的解释.查看一些相关问题,例如

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

这篇关于仅当另一个应用程序已连接到端口时,node-serialport才与Arduino通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆