java read com port
来源:互联网 发布:淘宝退货原因选哪个好 编辑:程序博客网 时间:2024/06/05 10:11
</pre>java 读取串口的技术<p></p><p> 1、rxtx </p><p> http://rxtx.qbang.org/wiki/index.php/Download</p><pre code_snippet_id="1674392" snippet_file_name="blog_20160506_2_2194645" name="code" class="java">package fpx.grs.aliexpress.com;import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.TooManyListenersException;import gnu.io.CommPortIdentifier;import gnu.io.PortInUseException;import gnu.io.SerialPort;import gnu.io.SerialPortEvent;import gnu.io.SerialPortEventListener;import gnu.io.UnsupportedCommOperationException;public class SimpleRead implements Runnable, SerialPortEventListener { static CommPortIdentifier portId; static Enumeration portList; InputStream inputStream; SerialPort serialPort; Thread readThread; public static void main(String[] args) { portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { if (portId.getName().equals("COM4")) { // if (portId.getName().equals("/dev/term/a")) { SimpleRead reader = new SimpleRead(); } } } } public SimpleRead() { try { serialPort = (SerialPort) portId.open("SimpleReadApp", 2000); } catch (PortInUseException e) {System.out.println(e);} try { inputStream = serialPort.getInputStream(); } catch (IOException e) {System.out.println(e);} try { serialPort.addEventListener(this); } catch (TooManyListenersException e) {System.out.println(e);} serialPort.notifyOnDataAvailable(true); try { serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) {System.out.println(e);} readThread = new Thread(this); readThread.start(); } public void run() { try { Thread.sleep(20000); } catch (InterruptedException e) {System.out.println(e);} } public void serialEvent(SerialPortEvent event) { switch(event.getEventType()) { case SerialPortEvent.BI: case SerialPortEvent.OE: case SerialPortEvent.FE: case SerialPortEvent.PE: case SerialPortEvent.CD: case SerialPortEvent.CTS: case SerialPortEvent.DSR: case SerialPortEvent.RI: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: break; case SerialPortEvent.DATA_AVAILABLE: byte[] readBuffer = new byte[20]; try { while (inputStream.available() > 0) { int numBytes = inputStream.read(readBuffer); } System.out.print(new String(readBuffer)); } catch (IOException e) {System.out.println(e);} break; } }}
2、jSerialComm
在rxtx基础上不需要增加系统的dll
https://github.com/Fazecast/jSerialComm/wiki
3、jssc
google的不需要依赖系统的dll
https://code.google.com/archive/p/java-simple-serial-connector/downloads
0 0
- java read com port
- vbs read COM port
- Com port (1)
- C# 读COM PORT
- git clone时出现ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from
- Java read
- Java serial port design
- serial port (2) 初始化com口
- Create a USB Virtual COM Port
- Create a USB Virtual COM Port
- http://photowoo.com/read/4093885
- Top 10 JDBC Best Practices for Java Programmer Read more: http://javarevisited.blogspot.com/2012/08
- boost C++ read from serial port with timeout example
- Java serial port technology agreement
- serial port communication by java
- port
- port
- port
- 一站式学习Wireshark(四):网络性能排查之TCP重传与重复ACK
- 我的开源项目 请多支持
- linux tmux 使用笔记
- 归并排序求逆序数(排序算法)
- 文件搜索命令
- java read com port
- matlab gui画图笔记
- eclipse安装jetty插件
- MathType中常见的两种符号的运用
- windows CMD常用指令
- java锁机制简介以及CAS操作
- 适配器基类--万能适配器(BaseAdapter)
- H.264 基本概念
- HDU 4389X mod f(x) 数位dp