如何使用 C++ 通过串行接口与 Arduino 进行通信 在 Linux 上?
我有一个连接到 Arduino 板的 RFID 读取器。 我想通过其串行接口连接到它,并且每当 RFID 读取器忽略信号时(当它读取 (RF)ID 时),我想在我的 C++ 程序中检索它。
我已经有了简单地将 RFID 从 Arduino 打印到串行的代码。
我不知道的是,如何在 Linux 中从 C++ 读取它?
我看过libserial,它看起来很简单。 但是,我如何让 C++ 程序对信号做出反应,然后读取 RFID,而不是持续监听? 有这个必要吗?
编辑:在我读过的大多数示例中,(c ++)程序发送输入并接收输出。 我只是想听并接收 Arduino 的输出。
I have an RFID reader connected to an Arduino board. I'd like to connect to it over its serial interface, and whenever the RFID reader omits a signal ( when it has read an (RF)ID ), I'd like to retrieve it in my C++ program.
I already have the code for simply printing the RFID to serial from the Arduino.
What I don't know, is how to read it from C++ in Linux ?
I have looked at libserial, which looks straightforward. However, how can I have the C++ program react to a signal and then read the RFID, instead of listening continously? Is this necessary?
EDIT: In most examples I have read, the (c++) program sends input, and recieves output. I just want to listen and recieve output from the Arduino.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Unix 上,您使用 select() 调用来等待输入。
select() 调用就像睡眠一样 - 不使用任何 CPU,直到内核收到硬件中断并触发 select()。
http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html
On unix you use the select() call to wait for an input.
The select() call acts like a sleep - using no CPU until the kernel receives the hardware interrupt and triggers the select().
http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html
我找到了 Boost::Asio 库,它从串行接口异步读取。 Boost::Asio 文档
I found the Boost::Asio library, which reads from serial interfaces asynchronously. Boost::Asio Documentation
Arduino Playground 中接口部分的 通信 部分有几个接口示例,包括一个带有 Arduino 的 Linux TTY。
尝试语法和程序论坛和Arduino 网站上的软件开发 论坛。 过去曾讨论过与许多不同语言和计算机的接口。
最后查看 处理 和 连线站点。 Arduino IDE基于Processing语言,Wiring环境和开发板与Arduino相关。 这两个网站都有更多示例和更多资源的链接。
编辑:我刚刚意识到我没有回答您的实际问题。 这些都是一般通信资源,但有些可能会提示如何提醒计算机有新的 RFID 输入。
The Communications part of the Interface section in the Arduino Playground has several examples of interfacing, including one with the Arduino as Linux TTY.
Try the Syntax and Programs forum and the Software Development forum on the Arduino site. There have been discussions about interfacing to many different languages and computers in the past.
And finally check out the Processing and Wiring sites. The Arduino IDE is based on the Processing language, and the Wiring environment and dev board is related to Arduino. Both sites have lots more examples and links to even more resources.
Edit: I just realized that I didn't answer your actual question. These are all general communications resources, but some may have hints towards how to alert the computer of a new RFID input.
您好,我为此创建了一个简单的库:cArduino
https://github.com/ranma1988/cArduino
C++可以自动查找连接Arduino端口,读取,写入
Hi I created a Simple library for this: cArduino
https://github.com/ranma1988/cArduino
C++ can find auto find connect Arduino port, read, write