Process analysis of Java calling Minghua RF reader DLL file
This article mainly introduces the process of Java calling Minghua RF reader DLL file parsing. It is introduced in great detail through the example code, which has a certain reference value for everyone's study or work. Friends in need can refer to it
First of all, the JDK must be 32-bit, and the IDE must also be 32-bit (I use the idea, so in order to use the 32-bit, I downloaded the version in January 2018).
Minghua RF reader and writer demonstration file provides a file named mwrf32 DLL Dynamic link library file
If Java wants to call, it must use JNI or JNA. After all, it is cross language
First, in POM In the blank space of the XML file, right-click and select dependency, search JNA in it, and select JNA: 5.4 0 or JNA platform enter import dependency.
After dependency import is successful
Create a folder named impl
Inherit library where you create an interface named connect
public interface Connect extends Library { Connect jihiseaDLL = Native.loadLibrary("mwrf32.dll",Connect.class); int rf_init(int port,int baud);//对mwrf32.dll中需要使用的rf_init函数进行声明 }
Create a connectimpl class to introduce the connect interface.
public class ConnectImpl implements Connect { public int rf_init(int port,int baud) { int icdev = jihiseaDLL.rf_init(0,9600);//设置端口号和波特率然后初始化端口 return icdev; } }
After that, you can call and complete the initialization of the reader / writer.
ConnectImpl systeminit = new ConnectImpl();//在这里对全局初始化icdev int icdev = systeminit.rf_init(0,9600);
After the computer is plugged in the reader, the system out. Println returns icdev to see if it succeeds
The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.