java中使用串口进行设备通信
- 如何进行这样的沟通呢?
- 有哪些库可用?
- 数据如何被视为位?
- How to do this kind of communication?
- What libraries are available?
- How is the data seen as bits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 上的串行入门有点棘手,但是一旦启动并运行它,它就非常简单了。
串行在不同操作系统上的实现方式并不统一,因此 Sun 的方法是开发 JavaComm 规范和参考实现。无论好坏,Sun 几年前似乎就失去了兴趣,并于 2005 年放弃了
对 Windows 的支持。因此,参考实现很大程度上已被名为 RXTX 的项目“取代”。 RXTX 适用于 Windows、Linux、BSD、Mac 等,因此这通常足以成为使用它的理由。
这两种实现都需要使用本机库(.so 或 .dll),需要安装并安装这些库。以每个平台的方式配置。
请参阅此链接以获得平衡的介绍,包括代码示例:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java
这是 RXTX项目: http://rxtx.qbang.org/wiki/index.php/Main_Page
HTH
编辑:为了回答你的最后一个问题,javacomm SerialPort类提供了 getInputStream() 和 getOutputStream() 方法,因此您可以像在 java.io 中一样使用它们
Serial on Java is a bit tricky to get started, but once you've got it up and running, it's quite straightforward.
Serial is not implemented in a uniform way on different OS's, so Sun's approach was to develop the JavaComm specification and a reference implementation. For better or worse, Sun appeared to lose interest several years ago, and dropped Windows support in 2005.
So, the reference implemetation has largely been 'superceded' by a project called RXTX. RXTX works with Windows, Linux, BSD, Mac etc, so this is normally reason enough to use it.
Both these implementations require use of a native library (.so or .dll), which needs to be installed & configured in a per-platform way.
See this link for a balanced introduction, including code samples:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java
Here is the RXTX project: http://rxtx.qbang.org/wiki/index.php/Main_Page
HTH
Edit: in answer to your final question, the javacomm SerialPort class provides getInputStream() and getOutputStream() methods, so you can use these as you normally would in java.io
Java 通信 API。
从这里开始可能会得到您需要的信息:
http://www.oracle .com/technetwork/java/index-jsp-141752.html
Java Communications API.
Starting here might get to you info you need:
http://www.oracle.com/technetwork/java/index-jsp-141752.html