简体   繁体   English

使用命令行从arduino获取响应

[英]get response from arduino using the command line

I've found it convenient to just execute "echo 1 >/dev/ttyACM0" from a java program to send commands to an arduino (in this case "1" toggles a relay attached to the arduino). 我发现仅从Java程序执行“ echo 1> / dev / ttyACM0”以将命令发送到arduino(在这种情况下为“ 1”会切换连接到arduino的继电器)会很方便。 Now I've decided that I'd like to get a response back from the arduino. 现在,我决定要从arduino那里得到答复。 Conceptually, what I'd like to do is simultaneously run echo and cat (read?) on the device so that I redirect what comes back from the device to stdout and then have my program capture that. 从概念上讲,我想在设备上同时运行echo和cat(read?),以便将设备返回的内容重定向到stdout,然后让我的程序捕获它。

I know that I can do the whole thing in Java but that requires using multiple threads or opening and closing several files. 我知道我可以用Java完成全部操作,但这需要使用多个线程或打开和关闭多个文件。 Using echo makes it so easy, especially testing the sketch using the command line. 使用echo使其非常容易,尤其是使用命令行测试草图。 So, is there a utility or shell script that does this? 那么,是否有执行此操作的实用程序或Shell脚本?

The terminal is a very powerful tool. 终端是一个非常强大的工具。 Sending strings you use echo read output from Arduino use this code tail -f /dev/ttyUSB0 . 发送使用Arduino的echo读取输出的字符串时,请使用以下代码tail -f /dev/ttyUSB0 replace USB0 with your serial bus . 用串行总线替换USB0 There also is this command which I have tried once or twice but should work for anyone screen /dev/cu.usbserial 9600 replace 9600 with your port . 还有一个我曾经尝试过一两次的命令,但应该对任何screen /dev/cu.usbserial 9600 9600用您的port替换9600

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM