⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcom.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.test;

import javax.comm.*;
import java.util.Enumeration;
import java.io.*;

public class TestCom {
  Enumeration e =null;
  CommPort cp = null;
  CommPortIdentifier cpi = null;
  InputStream is = null;
  public TestCom() {
   e = CommPortIdentifier.getPortIdentifiers();
  }
  public void print(){
    while(e.hasMoreElements()){
      cpi = getIdentifier(e.nextElement());
      //if(cpi.getName().substring(0,3).toLowerCase().equals("com")){
      if(cpi.getPortType()==CommPortIdentifier.PORT_SERIAL){
        System.out.println(cpi.getName());
        this.testIfLink();
      }

      //}
      //this.openComm(getIdentifier(e.nextElement()));
      //System.out.println(getIdentifier(e.nextElement()).getCurrentOwner());
      //this.closeComm();
      //System.out.println(cpi.getPortType());
    }
  }
  public void testIfLink(){
    try {
      cp = cpi.open(new String(cpi.getName()+"B"), 100);
      cp.enableReceiveTimeout(100000);
      cp.enableReceiveThreshold(200);
      cp.enableReceiveFraming(50);
      is = cp.getInputStream();
      byte[] b = new byte[2];

      System.out.println("inputStream:"+is.available()+"|owner:"+cpi.getCurrentOwner());
      System.out.println("timout:"+cp.isReceiveTimeoutEnabled()+"|"+cp.getReceiveTimeout());
      System.out.println("threshold:"+cp.isReceiveThresholdEnabled()+"|"+cp.getReceiveThreshold());
      System.out.println("frameing:"+cp.isReceiveFramingEnabled()+"|"+cp.getReceiveFramingByte());
      cp.close();
    }
    catch (PortInUseException ex) {
      System.out.println("PortInUseException:"+ex.currentOwner);
    }catch (IOException ex) {}
    catch (UnsupportedCommOperationException  ex) {}
  }
  public CommPortIdentifier getIdentifier(Object ob){
    return (CommPortIdentifier)ob;
  }
  //(SerialPort) CommPortIdentifier.getPortIdentifier (cc.getSerialPort ()).open (new String ("Garmin GPS"), 100);
  public void openComm(CommPortIdentifier comm){
    try {
      cp = comm.open(new String(comm.getName()), 100);
    }
    catch (PortInUseException ex) {
      System.out.println(ex);
    }catch (NullPointerException ex){
      System.out.println(ex);
    }
  }
  public void closeComm(){
    try {
      cp.close();
    }catch (Exception ex){
      System.out.println(ex);
    }
  }
  public static void main(String sr[]){
   // TestCom tc = new TestCom();
    //tc.print();
//    String test = "(&*(#$(*wqew";//[&*[#$[*wqew
//    test = test.replace('(','[');
//    System.out.println(test);
//    String encoding = System.getProperty("file.encoding");
//
//    System.out.println("Default System Encoding: " + encoding);
//    boolean temp = true;
//    for (int i = 0; i < 10; i++) {
//      System.out.println(i);
//      if (temp) {
//        temp = false;
//        i--;
//      }
//
//    }
//    if ((new Double(1.2)).equals(new Double(1.2))) {
//      System.out.println(new Double(1.2));
//    }else{
//      System.out.println(false);
//    }

//    char[] ch1 = "繁阳河堤".toCharArray();
//    if (ch1 != null) {
//      for (int i = 0; i < ch1.length; i++) {
//        System.out.println("ch1[" + i + "]:"+ ch1[i] +  " = " +((int)ch1[i]));
//      }
//
//    }else {
//      System.out.println("ch1 == null");
//    }
//    String[] test = new String[2];
//    test[0] = null;
//    if (test[0] == null) {
//      System.out.println("test[0] == null");
//    }

//    for (int i = 48; i <= 122; i++) {
//      if ((i % 10) == 0) {
//        System.out.println("");
//      }
//      System.out.print(i + " = " + (char)i + "   ");
//    }
//    File[] f = new File[10];
//    for (int i = 0; i < f.length; i++) {
//      f[i] = new File(""+i);
//    }
//    Object[] teset = new Object[f.length];
//    for (int i = 0; i < teset.length; i++) {
//      teset[i] = f[i];
//    }
//    Class[] tt = teset.getClass().getClasses();
//    for (int i = 0; i < tt.length; i++) {
//      System.out.println(tt[i]);
//    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -