class ReadIR { 
    // Declare the methods you are defining in the .c file to read the serial port
    private native int  readIR(byte buf[]);
    private native int  openIR();
    private native int  closeIR();   
    // Tell Java where to load the C object code from 
    static { 
          System.loadLibrary("serialtojava"); 
    }

    public String getbadge() { 
        int i;  
        int rcode;  
        // the C code passes back a byte array for future flexibility. We conver it to a String to print it
        byte b[] = new byte[255];
        // open the serial port 
        rcode = openIR(); 
        while (true) { 
	  // readIR only returns after it has read a valid badge 
          rcode = readIR(b);
	  //System.out.println("return code from readIR is "+rcode); 
          // if we got a good return code, convert the bytes to a StringBuffer  
          StringBuffer ident  = new StringBuffer(100); 
          i = 0; 
          while (b[i] != 0)  { 
            ident.append((char) b[i]);
            i++; 
          }
          System.out.println("Java identified a badge <"+  ident.toString()+"> "+rcode);   
          return(ident.toString()); 
        }
    } 

}


        


