We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing and the libnfc library in C
Pages: 1 2 
Processing and the libnfc library in C (Read 7456 times)
Re: Processing and the libnfc library in C
Reply #15 - Feb 9th, 2010, 6:41am
 
Worked like a charm Smiley Do you think it would be useful to create an article for the hack section? Someone might need to use libnfc and RFID capabilities in Processing
Re: Processing and the libnfc library in C
Reply #16 - Feb 9th, 2010, 9:44am
 
I suggest to write the article (it can be useful to yourself to pin down your experience and go back to the project later!), but to wait a little, a new Wiki is coming to replace the old Hacks section.
Re: Processing and the libnfc library in C
Reply #17 - Feb 9th, 2010, 3:29pm
 
Will do Smiley I'll write a version for SWIG and one for JNI. Thanks a lot for all your help Smiley
Re: Processing and the libnfc library in C
Reply #18 - Mar 8th, 2010, 5:19pm
 
I'm now trying to create a simple to use library, instead of using the Main.java file with Processing.

In the Main.java I had:

Code:
package libnfcjava;

public class Main {

   static {
       System.load("C:\\RFIDtest\\code\\libnfc.dll");
       System.load("C:\\RFIDtest\\code\\LibNFCNative.dll");
   }

   public Main() {
   }

   public static void main(String[] args) {
   }

   public native String nativeTagID();
   public native boolean nativeConnectedRFID();
}


I accessed the native functions (JNI) from within Processing by doing (for example):

boolean RFIDON = new Main().nativeConnectedRFID();


For the Processing library I now have a slightly different .java:

Code:
package libnfc;

import processing.core.PApplet;

public class LibNFC {

   PApplet myParent;

   public final String VERSION = "0.1.0";

   static {
      System.load("C:\\RFIDtest\\code\\libnfc.dll");
      System.load("C:\\RFIDtest\\code\\LibNFCNative.dll");
   }

   public LibNFC(PApplet theParent) {
       myParent = theParent;
   }

   public String version() {
       return VERSION;
   }

   public boolean isOn() {
       boolean status = this.nativeConnectedRFID();
       return status;
   }

   public String tagID() {
       String tag = this.nativeTagID();
       return tag;
   }

   public native String nativeTagID();
   public native boolean nativeConnectedRFID();
}


But when I try to run this example:

Code:
import libnfc.*;

LibNFC rfid;

void setup() {
 rfid = new LibNFC(this);
 
 size(400, 400);
 background(255);
}

void draw() {
  rectMode(CENTER);

  while(rfid.isOn()) {
    stroke(0);
    fill(255);
    rect(200,200,100,100);
 
    String tag = rfid.tagID();
 
    if(tag.equals("0400ae51962281")) {
      stroke(0);
      fill(127,0,0);
      rect(200,200,100,100);
    } else if(tag.equals("04ece051962280")) {
        stroke(0);
fill(255,200,200);
rect(200,200,100,100);
    } else {
      stroke(0);
      fill(255);
      rect(200,200,100,100);
    }
  }
  background(255);
}


I get the following error as soon I get to the while(rfid.isOn()):

UnsatisfiedLinkError: libnfc.LibNFC.nativeConnectedRFID()Z
Re: Processing and the libnfc library in C
Reply #19 - Mar 9th, 2010, 1:36am
 
UnsatisfiedLinkError can be thrown by System.load too. Are you sure you don't have this error earlier? (for example, add a println() before and after the new LibNFC() call).
Beside, I don't know why you have this error if you provide an absolute path (but as a library, it should load the DLL from the same place than your jar).
Re: Processing and the libnfc library in C
Reply #20 - Mar 9th, 2010, 12:26pm
 
PhiLho  wrote on Mar 9th, 2010, 1:36am:
UnsatisfiedLinkError can be thrown by System.load too. Are you sure you don't have this error earlier (for example, add a println() before and after the new LibNFC() call).
Beside, I don't know why you have this error if you provide an absolute path (but as a library, it should load the DLL from the same place than your jar).


Adding a println before and after rfid = new LibNFC(this); prints two strings correctly, giving me the same error in while(rfid.isOn()).

If I had the dlls in the library folder, together with the jar, how should I write the System.load

Is it possible that the error is from the way I call the native functions from within my methods Ex.:

Code:
boolean status = this.nativeConnectedRFID(); 


Re: Processing and the libnfc library in C
Reply #21 - Mar 9th, 2010, 2:35pm
 
No idea... But in theory, you can drop the this since it is implicit in any class anyway.
Re: Processing and the libnfc library in C
Reply #22 - Mar 10th, 2010, 8:52am
 
PhiLho  wrote on Mar 9th, 2010, 2:35pm:
No idea... But in theory, you can drop the this since it is implicit in any class anyway.


Thanks anyway. If I had the dlls in the library folder, together with the jar, how should I write the System.load so it would work on any computer
Re: Processing and the libnfc library in C
Reply #23 - Mar 10th, 2010, 9:29am
 
Have you tried without any path, just the file name?
Re: Processing and the libnfc library in C
Reply #24 - Mar 11th, 2010, 2:55am
 
PhiLho  wrote on Mar 10th, 2010, 9:29am:
Have you tried without any path, just the file name


Using System.loadLibrary("name.dll"); works fine, thanks Smiley

I've managed to get the library working, I had the recompile my dlls with some changes.
Pages: 1 2