2017-04-02 57 views
0

我有一個Phidg​​etRFID芯片(P/N:1023,205版)。我正在嘗試製作一個簡單的程序,以檢測標籤並顯示其唯一的ID號碼。我發現下面的源代碼,從製造商的網站Phidg​​etRFID芯片:如何檢測標籤

import com.phidgets.*; 
import com.phidgets.event.*; 

public class RFIDExample 
{ 
    public static final void main(String args[]) throws Exception { 
     RFIDPhidget rfid; 

     System.out.println(Phidget.getLibraryVersion()); 

     rfid = new RFIDPhidget(); 
     rfid.addAttachListener(new AttachListener() { 
      public void attached(AttachEvent ae) 
      { 
       try 
       { 
        ((RFIDPhidget)ae.getSource()).setAntennaOn(true); 
        ((RFIDPhidget)ae.getSource()).setLEDOn(true); 
       } 
       catch (PhidgetException ex) { } 
       System.out.println("attachment of " + ae); 
      } 
     }); 
     rfid.addDetachListener(new DetachListener() { 
      public void detached(DetachEvent ae) { 
       System.out.println("detachment of " + ae); 
      } 
     }); 
     rfid.addErrorListener(new ErrorListener() { 
      public void error(ErrorEvent ee) { 
       System.out.println("error event for " + ee); 
      } 
     }); 
     rfid.addTagGainListener(new TagGainListener() 
     { 
      public void tagGained(TagGainEvent oe) 
      { 
       System.out.println("Tag Gained: " +oe.getValue() + " (Proto:"+ oe.getProtocol()+")"); 
      } 
     }); 
     rfid.addTagLossListener(new TagLossListener() 
     { 
      public void tagLost(TagLossEvent oe) 
      { 
       System.out.println(oe); 
      } 
     }); 
     rfid.addOutputChangeListener(new OutputChangeListener() 
     { 
      public void outputChanged(OutputChangeEvent oe) 
      { 
       System.out.println(oe); 
      } 
     }); 

     rfid.openAny(); 
     System.out.println("waiting for RFID attachment..."); 
     rfid.waitForAttachment(30000); 

     System.out.println("Serial: " + rfid.getSerialNumber()); 
     System.out.println("Outputs: " + rfid.getOutputCount()); 

     } 
    } 

,但我收到以下錯誤:

Phidg​​et21 - 版本2.1.8 - 內置2016年2月22日11時45分54秒 等待RFID附件... 異常線程 「main」 Phidg​​etException 13(由於已超出時間限制。) 在com.phidgets.Phidg​​et.waitForAttachment(本機方法) 在RFIDExample.main(RFIDExample.java:58)

我已經嘗試過的是增加計時器,但問題沒有解決。 我試圖使用製造商的應用程序爲我的RFID芯片,它的工作,它正確地檢測標籤。但我需要使用源代碼而不是現成的應用程序。

任何幫助將是非常有用的! 提前謝謝! :)

BR, Loukas

回答

0

最後,問題是,我試圖執行的代碼,我不得不準備申請在同一時間打開。

現在它工作正常。

問題解決。