深圳德卡D3-U讀寫卡器windows(Java),linux(C)驅動開發

來源:互聯網
上載者:User

一、windows32(Java語言)驅動開發

1.1、檔案用途

在D3的Java檔案夾下有檔案夾兩個:classpackage、example,檔案一個:readme.txt。

classpackage中的 javaRD800.dll 是一個面向Java JNI 的windows動態連結程式庫。

classpackage中的 javaRD800.java 是一個面向Java的 JNI 介面。

example中的javaRD800Demo.java 是一個使用Java編寫的 讀寫卡器測試程式。

調用的順序如下:

javaRD800Demo.java---> javaRD800.java---> javaRD800.dll

 javaRD800.DLL 檔案下載

/* * @(#)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、動手測試

在 Eclipse 中建立一個 Java 工程,javaRD800Demo.java、javaRD800.java 放在 src 檔案夾內,javaRD800.dll 放在工程根目錄下。

編譯成功!

運行出錯!提示找不到依賴的類庫。

1.3、分析、解決問題

估計是缺少dll檔案,下載 dll檔案依賴查看器 發現缺少 dcrf32.DLL 檔案。

這個檔案 Java 檔案夾裡面沒有這個檔案,可以在 D3--->win32-dll目錄下找到此檔案,拷貝此檔案到工程根目錄下。

調用的順序如下:

javaRD800Demo.java---> javaRD800.java---> javaRD800.dll---> dcrf32.dll

編譯成功!

運行成功!

二、Linux_x86(C語言)驅動開發(Ubuntu_12.04 以下操作請 sudo -s 後進行)

2.1、先安裝 libusb 相關類庫

sudo apt-get install libusb*

2.2、查看系統預設類路徑

vim /etc/ld.so.conf

顯示:

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

cd /etc/ld.so.conf.d/

ls

顯示:

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

vim libc.conf

顯示:

# libc default configuration/usr/local/lib

說明系統預設類庫路徑有一條 /usr/local/lib
 

2.3、拷貝檔案

拷貝 librf.so 到 /usr/local/lib,拷貝librf.h 到 /usr/local/include

2.4、更新系統類別庫

#ldconfig

2.5、在Eclipse cpp中建立一個C工程

拷貝 RfDemo_linux.c 到原始碼檔案夾 src;

拷貝靜態連結庫檔案 D8U.a、libusb-1.0.a
到工程根目錄下;

2.6、配置Eclipse cpp 開發環境

2.6.1、使用C99編譯標準:右鍵點擊項目->Properties->C/C++ Build -> Settings -> Tool Settings -> GCC C Complier -> Miscellaneous

在 "Other flags" 中追加 -std=c99;

2.6.2、添加使用的動態類庫:右鍵點擊項目->Properties->C/C++ Build -> Settings ->
Tool Settings -> GCC C linker -> Libraries

在 "Libraries" 中添加 rf、rt、usb、pthread

2.6.3、添加使用的靜態類庫:右鍵點擊項目->Properties->C/C++
Build -> Settings -> Tool Settings -> GCC C
linker -> Miscellaneous

在 "Other objects" 中添加工程根目錄下的 D8U.a、libusb-1.0.a

2.7、完成

編譯成功!

運行成功!

PS1:某些讀卡機的Linux驅動測試失敗時,可以試試這個讀卡機升級包

PS2:開發用的API協助文檔下載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.