最近接受一个老项目,其中用到了comm.jar这个包,
但是没有相关文档参考,查了好多资料,也没找到,
谁哪里有的话,麻烦给我发一份,谢谢了!
我的邮箱:linwu_gao@163.com
------解决方案--------------------
网上有下载的,LZ可以搜索一下 java.comm包文档说明
前几天为了回答一个多线程读写串口问题的帖子,在公司下了一个看了一下,现在家里没有
------解决方案--------------------
你可以试下rxtx,这也是一个串口开发的东西,如下为使用代码
- Java code
CommPortIdentifier portId; Enumeration en = CommPortIdentifier.getPortIdentifiers(); // iterate through the ports. while(en.hasMoreElements()) { portId = (CommPortIdentifier) en.nextElement(); System.out.println(portId.getName()); if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println(portId.getName()); } } portId = CommPortIdentifier.getPortIdentifier("COM1"); SerialPort sPort = (SerialPort) portId.open("串口所有者名称", 1000); System.out.println("start-----------"); final InputStream is = sPort.getInputStream(); sPort.addEventListener(new SerialPortEventListener() { public void serialEvent(SerialPortEvent e) { //System.out.println("-->" + e.getEventType()); if(e.getEventType() == SerialPortEvent.DATA_AVAILABLE) { try { //System.out.println(is.available()); int x = 0; byte[] msgPack = new byte[35]; while(true) { int j = is.read(msgPack, x, msgPack.length - x); System.out.println("j=" + j); if(j <= 0) break; x += j; if(false) break;// System.out.println("x->" + x);// for(int i = 0;i < 4;i++) {// int newData;// if((newData = is.read()) != -1) {// msgPack[i] = (byte) newData;// System.out.println(newData);// } else {// break;// }// System.out.println("--------");// } } System.out.println("x-> " + x); for(byte a : msgPack) { System.out.print(Integer.toHexString(a) + " "); } System.out.println(); System.out.println(new String(msgPack, 0, 34)); if(1 == 1) return; } catch(Exception es) { es.printStackTrace(); } } } }); sPort.notifyOnDataAvailable(true); sPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
------解决方案--------------------
http://download.oracle.com/docs/cd/E17802_01/products/products/javacomm/reference/api/index.html
在线官方文档