<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Application Performance Using JNI for RFID

Published on
10,048 Points
4,048 Views
Last Modified:
Introduction
Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java Virtual Machine) can recognize the symbols exported by the native program. It defines how functions are to be named. Also it defines how to pass different types of data variable between the native code and Java code.

We had to implement RFID in one of our Java application. According to the application demand we choose to use network based RFID scanners. The manufacturer of the scanner supplied us with C++ SDK along with the scanner. Since the SDK is for C++ we wrote a JNI to integrate it with our application.

The Setback
The JNI is written with four functions, Connect_Scanner, Read_RFID, Clear_Buff and Disconnect_Scanner.

Connect_Scanner: This is to connect to the scanner and expects the IP address and Port number from the Java code. On success or failure of the connection this function returns a status code accordingly.

Read_RFID: On a successful connection the Java code spawns a new thread and calls this function in a continuous loop. Internally the C++ code calls a API function provided by the SDK. One of the parameter of the function was a type struct array. When the API function returns the struct array contains all the RFIDs scanned.

Clear_Buff: So that the same RFID is not scanned more than once a buffer temporarily holds all the scanned RFIDs. This function is used to clear this buffer.

Disconnect_Scanner: This function is called to disconnect the scanner from the application.

We found when we called Read_RFID from the Java code it took little more than 4secs to return. Otherwise when we called the function from the native code itself it was just about 1 to 2 milliseconds. The main reason could be because of the way strings are handled in Java vis-à-vis C++.

The Solution

We compiled the native code in to a separate executable and connected the Java application with a local loop socket. The native executable listens on IP 127.0.0.1 and port 100. The Java code makes a socket client connection to the executable. The functions are then called through the socket.    
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Join & Write a Comment

Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month