为什么当我运行使用NetBeans 6.8和Eclipse这个code输出有什么不同? [英] Why do the outputs differ when I run this code using NetBeans 6.8 and Eclipse?

查看:188
本文介绍了为什么当我运行使用NetBeans 6.8和Eclipse这个code输出有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正在使用Eclipse和NetBeans 6.8以下code。我想看看我的电脑上可用的COM端口。当在Eclipse中运行它返回我所有可用的COM端口,但在NetBeans中运行它时,它似乎并没有找到任何端口。

 公共静态无效测试(){
    枚举列表= CommPortIdentifier.getPortIdentifiers();    的System.out.println(lists.hasMoreElements());
    而(lists.hasMoreElements()){
        CommPortIdentifier CN =(CommPortIdentifier)lists.nextElement();        如果((CommPortIdentifier.PORT_SERIAL == cn.getPortType())){
            的System.out.println(
              名字是逃portzzzz+
              cn.getName()+
              国有身份+
              cn.isCurrentlyOwned());            尝试{
                端口1的SerialPort =(的SerialPort)cn.open(ComControl,800000);
                port1.setSerialPortParams(
                  9600,
                  SerialPort.DATABITS_8,
                  SerialPort.STOPBITS_1,
                  SerialPort.PARITY_NONE);
                的System.out.println(以前获得流);
                OutputStream的OUT = port1.getOutputStream();
                输入的InputStream = port1.getInputStream();
                的System.out.println(写之前);
                out.write(AT.getBytes());
                的System.out.println(后写);
                INT样本= 0;
                //而(((样本= input.read())!= - 1)){
                的System.out.println(读之前);
                //System.out.println(input.read()+测试);
                //}
                的System.out.println(后读);
                的System.out.println(接收超时是+ port1.getReceiveTimeout());
            }
            赶上(例外五){
                通信System.err.println(e.getMessage());
            }
        }
        其他{
            的System.out.println(
              姓名平行portzzzz+
              cn.getName()+
              国有身份+
              cn.isCurrentlyOwned()+
              cn.getPortType()+);
        }
    }
}

使用Netbeans输出,

使用Eclipse输出,

 
名称是逃portzzzz COM1国有虚假身份
GET流之前
写之前
写后
读前
后读
接收超时为-1
名称是逃portzzzz COM2国有虚假身份
GET流之前
写之前
写后
读前
后读
接收超时为-1
名称是平行portzzzz LPT1拥有状态false2
名称是平行portzzzz LPT2拥有状态false2


解决方案

您使用相同的Java虚拟机运行在NetBeans和Eclipse中的code?

When I am running the following code using Eclipse and NetBeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COM ports but when running it in NetBeans, it does not seem to find any ports ..

public static void test(){
    Enumeration lists=CommPortIdentifier.getPortIdentifiers();

    System.out.println(lists.hasMoreElements());
    while (lists.hasMoreElements()) {
        CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

        if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())) {
            System.out.println(
              "Name is serail portzzzz " +
              cn.getName() +
              " Owned status " +
              cn.isCurrentlyOwned());

            try{
                SerialPort port1=(SerialPort)cn.open("ComControl",800000);
                port1.setSerialPortParams(
                  9600,
                  SerialPort.DATABITS_8,
                  SerialPort.STOPBITS_1,
                  SerialPort.PARITY_NONE);
                System.out.println("Before get stream");
                OutputStream out=port1.getOutputStream();
                InputStream input=port1.getInputStream();
                System.out.println("Before write");
                out.write("AT".getBytes());
                System.out.println("After write");
                int sample=0;
                //while((( sample=input.read())!=-1)){
                System.out.println("Before read");
                //System.out.println(input.read() + "TEsting ");
                //}
                System.out.println("After read");
                System.out.println("Receive timeout is "+port1.getReceiveTimeout());
            }
            catch(Exception e) {
                System.err.println(e.getMessage());
            }
        }
        else {
            System.out.println(
              "Name is parallel portzzzz " +
              cn.getName() +
              " Owned status " +
              cn.isCurrentlyOwned() +
              cn.getPortType()+"    ");
        }
    }
}

Output with Netbeans,

false

Output using Eclipse,

true
Name is serail portzzzz COM1 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail portzzzz COM2 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is parallel portzzzz LPT1 Owned status false2
Name is parallel portzzzz LPT2 Owned status false2

解决方案

Are you using the same Java VM to run the code in NetBeans and Eclipse?

这篇关于为什么当我运行使用NetBeans 6.8和Eclipse这个code输出有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆