有許多學校運用NXT進行JAVA程式教學,或是機器人課程以JAVA進行控制。
參考何老師的書籍,裡面的範例程式應該是使用iCommand 0.5
目前iCommand 0.7的程式庫已經有一些修改。
從JAVA討論區得知這個問題,原始程式碼如下:
import icommand.nxtcomm.*;
public class GetDeviceInfo {
    public static void main(String[] args) {
         NXTCommand.setVerify(true);
         DeviceInfo nxt = NXTCommand.getDeviceInfo();
         FirmwareInfo firmware = NXTCommand.getFirmwareVersion();
         System.out.println("==============================");
         System.out.println("NXT name: "+ nxt.NXTname.trim());
         System.out.println("藍芽裝置位址: "+ nxt.bluetoothAddress);
         System.out.println("剩餘記憶體: "+ nxt.freeFlash);
         System.out.println("NXT 韌體版本: "+ firmware.firmwareVersion);
         NXTCommand.close();
    }
}
=======================================
一開始我從一些範例程式學習,
只知道import icommand.nxtcomm.*;
需要改為import icommand.nxt.comm.*;
接下來卻遇到這樣的錯誤訊息:
Cannot make a static reference to the non-static method getDeviceInfo() from the type NXTCommand	 
  
 Cannot make a static reference to the non-static method getFirmwareVersion() from the type NXTCommand 由於我不瞭解JAVA,當場傻眼,做了許多嘗試還是無法解決問題,最後只好向LeJOS論壇求援。
還好馬上獲得
善心人士ChrisB01的解答(請點擊連結觀看論壇文章),
終於知道如何更正程式,最後的程式碼如下:
import icommand.nxt.comm.*;   
 public class GetDeviceInfo { 
    static NXTCommand command = NXTCommand.getSingleton(); // Create own pointer here   
    public static void main(String[] args) {         
       NXTCommand.open(); //You might also need this static method to open the connection   
       NXTCommand.setVerify(true);  // This IS a static method so you CAN use the class name 
       DeviceInfo Devinfo = command.getDeviceInfo(); // NOTICE command NOT NXTCommand 
       FirmwareInfo firmware = command.getFirmwareVersion(); // NOTICE command NOT NXTCommand   
       System.out.println("==============================="); 
       System.out.println("NXT Name: " + Devinfo.NXTname.trim()); 
       System.out.println("藍牙裝置位置: " + Devinfo.bluetoothAddress); 
       System.out.println("剩餘記憶體: " + Devinfo.freeFlash); 
       System.out.println("NXT韌體版本: " + firmware.firmwareVersion);   
       NXTCommand.close(); // This IS a static method so you CAN use the class name 
    } 
 }
不過執行結果還是有一點小問題,NXT名稱的前一個字母不見了。
總之經過這一次實驗的心得是:
1. JAVA真難懂。

2. iCommand真難懂,或許還要修正。

3. 善用論壇,總有善心前輩熱心幫忙。

使用iCommand的達人請多多幫忙喔!謝謝!
