zoukankan      html  css  js  c++  java
  • Java JNI调用IC卡读卡器

    Java调用IC卡读卡器的DLL一般有以下2种方式:

    1.使用JNative第三方库调用IC卡读卡器dll的接口.

    2.使用JNI调用IC卡读卡器dll的接口.

    JNative调用IC卡读卡器dll很方便,只要知道接口名称和参数类型即可调用, 缺点是仅支持32位的程序, 不支持64位。

    JNI调用IC卡读卡器的DLL,既支持64位程序也支持32位程序, 调用也非常方便,下面将介绍JNI调用IC卡读卡器DLL的方式。

    对于经常使用的普通IC卡为例, 首先声明相关的api接口:

    public native int YW_USBHIDInitial();

    public native int YW_USBHIDFree();

    public native int YW_Buzzer(int ReaderID,int Time_ON, int Time_OFF, int Cycle);

    public native int YW_Led(int ReaderID,int LEDIndex, int Time_ON, int Time_OFF, int Cycle, int LedIndexOn);

    public native int YW_AntennaStatus(int ReaderID,boolean Status);

    public native int YW_SearchCardMode(int ReaderID,int Mode);

    public native int YW_RequestCard(int ReaderID,int RequestMode, short CardType[]);

    public native int YW_AntiCollide(int ReaderID, byte LenSNO[], byte SNO[]);

    public native int YW_CardSelect(int ReaderID,byte LenSNO, byte SNO[]);

    public native int YW_DownLoadKey(int ReaderID,int KeyIndex, byte Key[]);

    public native int YW_KeyDown_Authorization(int ReaderID,int KeyMode, int BlockAddr, byte KeyIndex);

    public native int YW_KeyAuthorization(int ReaderID,int KeyMode, int BlockAddr, byte[]Key);

    public native int YW_ReadaBlock(int ReaderID,int BlockAddr, int LenData, byte pData[]);

    public native int YW_WriteaBlock(int ReaderID,int BlockAddr, int LenData, byte pData[]);

    public native int YW_Purse_Initial(int ReaderID,int BlockAddr, int IniMoney);

    public native int YW_Purse_Read(int ReaderID,int BlockAddr,  int Money[]); 

    public native int YW_Purse_Decrease(int ReaderID,int BlockAddr, int Decrement);

    public native int YW_Purse_Charge(int ReaderID,int BlockAddr, int Charge);

    public native int YW_CardHalt(int ReaderID);

    public native int YW_Restore(int ReaderID,int BlockAddr);

    public native int YW_Transfer(int ReaderID,int BlockAddr);

    public native int YW_AntiCollideAndSelect(int ReaderID,byte ReturnMode,  byte CardMem[],  byte SNLen[], byte SN[]);

    然后静态装载dll,64位程序装载64位的dll,32位装载32位的dll。

    static {

    System.loadLibrary("YW60X-32");

    }

    经过以上声明后,就可以直接调用接口了,如:

    YOWORFID rfidreader = new YOWORFID();

    rfidreader.YW_USBHIDInitial();

    int rt =0;

    rt =rfidreader.YW_RequestCard(ReaderID,Requestmode,Cardtype);

    rt = rfidreader.YW_AntiCollide(ReaderID,LenSn,CardNo);

    HexToStr(CardNo,LenSn[0]);

    rt =rfidreader.YW_CardSelect(ReaderID,LenSn[0],CardNo);

    rt =rfidreader.YW_KeyAuthorization(ReaderID,96,4,Key);

    System.out.printf("KeyAuthorization=%d",rt);System.out.println();

    rt =rfidreader.YW_ReadaBlock(ReaderID,4,16,BlockData);

    System.out.printf("YW_ReadaBlock=%d",rt);System.out.println();

    if(rt>0){HexToStr(BlockData,16);}

    rfidreader.YW_Led(ReaderID,1,1,1,3,0);

    rfidreader.YW_USBHIDFree();

    以下java代码例子包含了读卡和写卡的,可以使用32位或者64的dll,下载Java JNI调用IC卡读卡器例程

  • 相关阅读:
    TDirectory.GetParent获取指定目录的父目录
    TDirectory.GetLogicalDrives获取本地逻辑驱动器
    获取设置目录创建、访问、修改时间
    TDirectory.GetLastAccessTime获取指定目录最后访问时间
    TDirectory.GetDirectoryRoot获取指定目录的根目录
    「洛谷P1262」间谍网络 解题报告
    「洛谷P1198」 [JSOI2008]最大数 解题报告
    「洛谷P3931」 SAC E#1
    「UVA1328」「POJ1961」 Period 解题报告
    「博客美化」I 页面的CSS
  • 原文地址:https://www.cnblogs.com/yoworfid/p/15479600.html
Copyright © 2011-2022 走看看