Shenzhen de-card D3-U read and write reader windows (Java), Linux (c) driver development

Source: Internet
Author: User
Tags psdata

I. Windows 32 (Java language)-driven development

1.1 File Usage

In the Java folder of D3, there are two folders: classpackage and example. The file is readme.txt.

Javard800.dll in classpackage is a Windows dynamic link library for Java JNI.

Javard800.java in classpackage is a JNI interface for Java.

Javard800demo. Java in example is a test program written in Java.

The Calling sequence is as follows:

Javard800demo. Java ---> javard800.java ---> javard800.dll

Javard800.dll File Download

/* * @(#)JavaRD800.java 1.0 03/11/27 * * You can modify the template of this file in the * directory ..\JCreator\Templates\Template_1\Project_Name.java * * You can also create your own project template by making a new * folder in the directory ..\JCreator\Template\. Use the other * templates as examples. * */public class JavaRD800{public JavaRD800(){}static{System.loadLibrary("javaRD800");}public native int dc_init(int lPort,int lBaud);public native short dc_exit(int lDevice);public native short dc_card(int lDevice,short iMode,int[] pSnr);public native short dc_authentication(int lDevice,short iMode,short iSecNr);public native short dc_halt(int lDevice);public native short dc_read(int lDevice,short iAdr,char[] pData);public native short dc_write(int lDevice,short iAdr,char[] pData);public native short dc_increment(int lDevice,short iAdr,int lValue);public native short dc_decrement(int lDevice,short iAdr,int lValue);public native short dc_initval(int lDevice,short iAdr,int lValue);public native short dc_readval(int lDevice,short iAdr,int[] pValue);public native short dc_transfer(int lDevice,short iAdr);public native short dc_restore(int lDevice,short iAdr);public native short dc_load_key(int lDevice,short iMode,short iSecNr,char[] pKey);public native short dc_beep(int lDevice,short iMsec);public native short dc_high_disp(int lDevice,short iOffset,short iDispLen,char[] pDispStr);public native short dc_request(int lDevice,short iMode,int[] pTagType);public native short dc_anticoll(int lDevice,short iBcnt,int[] pSnr);public native short dc_select(int lDevice,int lSnr,short[] pSize);public native short dc_gettime(int lDevice,char[] pTimeStr);public native short dc_gettimehex(int lDevice,char[] pTimeStr);public native short dc_settime(int lDevice,char[] pTimeStr);public native short dc_settimehex(int lDevice,char[] pTimeStr);public native short dc_setbright(int lDevice,short iBright);public native short dc_ctl_mode(int lDevice,short iMode);public native short dc_disp_mode(int lDevice,short iMode);public native short dc_cpureset(int lDevice,short[] pLen,char[] pData);public native short dc_cpuapdu(int lDevice,short iLen,char[] pSData,short[] pLen,char[] pRData);public native short dc_cpuapdusource(int lDevice,short iLen,char[] pSData,short[] pLen,char[] pRData);public native short dc_cpudown(int lDevice);public native short dc_swr_eeprom(int lDevice,int lOffset,int lLen,char[] pBuffer);public native short dc_srd_eeprom(int lDevice,int lOffset,int lLen,char[] pBuffer);public native short dc_disp_str(int lDevice,char[] pDispStr);}

class JavaRD800Demo{public static void main(String[] args){short status;int lDevice = 0;int[] pSnr = new int[1];char[] pSBuffer = new char[16];char[] pRBuffer = new char[16];JavaRD800 rd = new JavaRD800();lDevice = rd.dc_init(100,115200);if(lDevice <= 0){System.out.print("dc_init error!\n");return;}System.out.print("dc_init ok!\n");rd.dc_beep(lDevice,(short)10);             status = rd.dc_card(lDevice,(short)0,pSnr);if(status != 0){System.out.print("dc_card error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_card ok!\n");System.out.println(pSnr[0]);pSBuffer[0] = 0xFF;pSBuffer[1] = 0xFF;pSBuffer[2] = 0xFF;pSBuffer[3] = 0xFF;pSBuffer[4] = 0xFF;pSBuffer[5] = 0xFF;pSBuffer[6] = 0x00;status = rd.dc_load_key(lDevice,(short)0,(short)0,pSBuffer);if(status != 0){System.out.print("dc_load_key error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_load_key ok!\n");status = rd.dc_authentication(lDevice,(short)0,(short)0);if(status != 0){System.out.print("dc_authentication error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_authentication ok!\n");for(int i=0;i<16;i++){pSBuffer[i] = 'M';}status = rd.dc_write(lDevice,(short)2,pSBuffer);if(status != 0){System.out.print("dc_write error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_write ok!\n");status = rd.dc_read(lDevice,(short)2,pRBuffer);if(status != 0){System.out.print("dc_read error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_read ok!\n");System.out.println(pRBuffer);status = rd.dc_exit(lDevice);if(status != 0){System.out.print("dc_exit error!\n");rd.dc_exit(lDevice);return;}System.out.print("dc_exit ok!\n");}}

1.2 hands-on Testing

Create a new Java project in eclipse. Place javard800demo. Java and javard800.java In the SRC folder and javard800.dll in the project root directory.

Compiled successfully!

An error occurred while running! The system prompts that the dependent class library cannot be found.

1.3. analyze and solve problems

It is estimated that the DLL file is missing. The dcrf32.dll file is missing when downloading the DLL file dependency viewer.

This file does not exist in the Java folder, you can find this file in D3 ---> win32-dll directory, copy this file to the project root directory.

The Calling sequence is as follows:

JavaRD800Demo. java ---> javaRD800.java ---> javaRD800.dll ---> dcrf32.dll

Compiled successfully!

Running successful!

Ii. _x86 (C Language) driver development (ubuntu_12.04 perform the following operations after Sudo-S)

2.1 install libusb-related class libraries first

Sudo apt-get install libusb *

2.2 view the default system path

Vim/etc/ld. so. conf

Display:

include /etc/ld.so.conf.d/*.conf

Cd/etc/ld. so. conf. d/

Ls

Display:

i386-linux-gnu_GL.conf  libc.conf    x86_64-linux-gnu_GL.confi686-linux-gnu.conf     oracle.conf

Vim libc. conf

Display:

# libc default configuration/usr/local/lib

The default path of the system class library is/usr/local/lib.
 

2.3 copy an object

Copy librf. so to/usr/local/lib, and copy librf. h to/usr/local/include.

2.4. Update the system library

# Ldconfig

2.5 create a C Project in Eclipse cpp.

Copy RfDemo_linux.c to the source code folder src;

Copy static link library file D8U. a, libusb-1.0.a
Go to the project root directory;

2.6 configure the Eclipse cpp Development Environment

2.6.1. Use C99 to compile the standard. Right-click the project and choose Properties> C/C ++ Build> Settings> Tool Settings> gcc c Complier> Miscellaneous.

Append-std = c99 in "Other flags;

2.6.2. Add a dynamic Class Library: Right-click the project and choose Properties> C/C ++ Build> Settings>
Tool Settings-> gcc c linker-> Libraries

Add rf, rt, usb, pthread to "Libraries"

2.6.3. Add a static Class Library: Right-click the project and choose Properties> C/C ++.
Build-> Settings-> Tool Settings-> GCC C
Linker-> Miscellaneous

Add D8U. a, libusb-1.0.a under the project root directory in "Other objects"

2.7 completed

Compiled successfully!

Running successful!

PS1: If the Linux driver test of some card readers fails, you can try thisCard Reader upgrade package

PS2: Development API help documentDownload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.