2012-08-12 255 views
0

我有一個按鈕,這個代碼,當我按下它,我得到的錯誤:連接失敗[10048]

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(); 
       } 
      } 
     } 
    }); 

根據我的研究,這是因爲正在使用的藍牙端口正在被多個實例訪問。但是我不明白這個代碼是如何發生的。

回答

0

您是否爲遠程設備配置了藍牙虛擬COM端口?也許它是由一些程序打開的...

或者,錯誤是否在您第一次運行程序時發生?是否有任何運行程序的舊副本 - check in taskmgr.exe