0

我在一个按钮上有这个代码,当我按下它时,我得到了错误:

  Error: Exception connecting to NXT.
  Caused by lejos.pc.comm.NXTCommException: Open of NXT failed.
at lejos.pc.comm.NXTCommBluecove.open(NXTCommBluecove.java:136)
   Caused by javax.bluetooth.BluetoothConnectionException: Failed to connect; [10048]
 Only one usage of each socket address (protocol/network address/port) is normally permitted.
at com.intel.bluetooth.BluetoothStackMicrosoft.connect(Native Method)
Failed to connect to any NXT

我发帖是因为它昨天工作正常,但今天似乎没有工作。

btnConnectBot.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (Cnt1){
                try {
                    conn.close();
                    Cnt1=!Cnt1;
                    txtConnState.setText("Off");
                    txtConnState.setForeground(Color.RED);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
            else{   
                conn.addLogListener(new NXTCommLogListener() {
                public void logEvent(String message) {
                System.out.println(message);
                }

                public void logEvent(Throwable throwable) {
                System.err.println(throwable.getMessage());
                }
                });
                conn.setDebug(true);
                if (!conn.connectTo(txtBotName.getText(), NXTComm.LCP)) {
                System.err.println("Fallo de conexión");
                txtConnState.setText("Off");
                txtConnState.setForeground(Color.RED);
                System.exit(1);
                }
                Cnt1=!Cnt1;     
                txtConnState.setText("On");
                txtConnState.setForeground(Color.GREEN);

                if (chckbxLock_2.isSelected()){
                    btnConnectBot_2.doClick();
                }
                if (chckbxLock_1.isSelected()){
                    btnConnectBot_1.doClick();
                }
            }
        }
    });

根据我的研究,这是因为正在使用的蓝牙端口被多个实例访问。但我看不出这段代码是如何发生的。

4

1 回答 1

0

您是否为远程设备配置了蓝牙虚拟 COM 端口?也许它是由某些程序打开的......

或者,错误是否在您第一次运行程序时发生?您的程序是否有任何旧副本正在运行 - 检查 taskmgr.exe

于 2012-09-06T09:33:38.187 回答