简体   繁体   English

如何创建RFID应用程序以读取HID OMNIKEY 5427 CK

[英]How to create RFID application to read HID OMNIKEY 5427 CK

My coworkers and I are trying to create a Java program to read cards with a HID OMNIKEY 5427 CK. 我和我的同事正在尝试创建一个Java程序来读取带有HID OMNIKEY 5427 CK的卡。 We have no previous experience with RFID and checked: https://support.impinj.com/hc/communities/public/questions/201883748-How-do-I-create-RFID-applications-with-Java- 我们之前没有使用RFID的经验并已检查过: https : //support.impinj.com/hc/communities/public/questions/201883748-How-do-I-create-RFID-applications-with-Java-

for some sample code (we haven't been able to find much sample code apart from this), which we have adapted and used, but when running our code we get 对于一些示例代码(除此之外,我们无法找到很多示例代码),我们已经对其进行了修改和使用,但是在运行我们的代码时,

java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.mina.transport.socket.nio.SocketConnector.connect(SocketConnector.java:187)
at org.apache.mina.transport.socket.nio.SocketConnector.connect(SocketConnector.java:137)
at org.apache.mina.common.support.BaseIoConnector.connect(BaseIoConnector.java:40)
at org.llrp.ltk.net.LLRPConnector.connect(LLRPConnector.java:135)
at org.llrp.ltk.net.LLRPConnector.connect(LLRPConnector.java:116)
at hellojavaltk.HelloJavaLtk.connect(HelloJavaLtk.java:212)
at hellojavaltk.HelloJavaLtk.run(HelloJavaLtk.java:227)
at hellojavaltk.HelloJavaLtkMain.main(HelloJavaLtkMain.java:9)​

code is basically: 代码基本上是:

public class HelloJavaLtkMain
{
public static void main(String[] args) throws InterruptedException
{
HelloJavaLtk app = new HelloJavaLtk();

System.out.println("Starting reader.");
app.run("HID-OMNIKEY-5427-CK");
Thread.sleep(30000);
System.out.println("Stopping reader.");
app.stop();
System.out.println("Exiting application.");
System.exit(0);
}
}

and HelloJavaLtk is a class that implements the LLRPEndpoint interface, basically copy-pasted form the link above. 而HelloJavaLtk是实现LLRPEndpoint接口的类,基本上是从上面的链接复制粘贴的。

So we don't know if we are just not addressing the device correctly with that run("HID-OMNIKEY-5427-CK") or if we should be doing something completely different when trying to reach that Endpoint. 因此,我们不知道是否只是使用该run(“ H​​ID-OMNIKEY-5427-CK”)无法正确寻址设备,还是在尝试到达该端点时是否应该做完全不同的事情。

We would appreciate any help if somebody has been able to use the OMNIKEY-5427-CK (or other card readers) with Java code, could point us to other code examples or give us further insights on what are we doing wrong. 如果有人能够将OMNIKEY-5427-CK(或其他读卡器)与Java代码一起使用,可以为我们提供其他代码示例或对我们做错的事情有进一步的了解,我们将不胜感激。

Thanks all. 谢谢大家

The HID OMNIKEY 5427 CK is a PC/SC (CCID) compliant smartcard reader. HID OMNIKEY 5427 CK是PC / SC(CCID)兼容的智能卡读取器。 The library you are trying to use is intended for EPC RFID readers. 您尝试使用的库专用于EPC RFID阅读器。 This Omnikey reader is accessed through PC/SC, however. 但是,可以通过PC / SC访问此Omnikey阅读器。 Current Oracle Java has built in support for access to PC/SC smartcard readers using the Java SmartcardIO API . 当前的Oracle Java内置支持使用Java SmartcardIO API访问PC / SC智能卡读取器。

I think the code you are using is not compatible, as it looks to work with LLRP protocol and your device supports CCID and keyboard wedge. 我认为您使用的代码不兼容,因为它看起来可以与LLRP协议一起使用,并且您的设备支持CCID和键盘楔。

CCID: CCID:

I couldn't find the documentation for your device, however it looks like CCID might work using a serial connection, if that's the case you can use RXTX to connect to the device ( http://mfizz.com/oss/rxtx-for-java ), and then send commands and read responses from it. 我找不到您设备的文档,但是CCID似乎可以通过串行连接使用,如果是这种情况,则可以使用RXTX连接到设备( http://mfizz.com/oss/rxtx-for -java ),然后发送命令并从中读取响应。

This is a small example: 这是一个小例子:

// change to right port
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyS0"); 
    if (portIdentifier.isCurrentlyOwned()) {
        throw new RfidReaderUnavailableException();
    } else {
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
        if (commPort instanceof SerialPort) {
            SerialPort serialPort = (SerialPort) commPort;
            // This details have to match your device configuration or it won't work
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);

            in = serialPort.getInputStream();
            out = serialPort.getOutputStream();

            <-- Here you write the commands on out and read the responses from in -->

        } else {
            System.out.println("Error: Only serial ports are handled by this.");
        }
   }

In case CCID doesn't support serial communication they will have to provide a driver for it. 如果CCID不支持串行通信,则必须为其提供驱动程序。 If the driver doesn't come with Java compatibility then you will need to write a JNI wrapper to use it from your Java code. 如果驱动程序不具有Java兼容性,那么您将需要编写JNI包装器以从Java代码中使用它。

Keyboard wedge: 键盘楔:

The functionality on this mode will be probably reduced to write the card id as if it was a keyboard, much like barcode scanners. 类似于条形码扫描器,此模式下的功能可能会减少,以像刷键盘一样写入卡ID。 you won't be able to tell from keyboard input and the reader and you wont be able to read or write data from the card memory either, however it might work for you depending of what your app has to achieve. 您将无法通过键盘输入和读取器辨别,也无法从卡内存中读取或写入数据,但是它可能对您有用,这取决于您的应用程序必须实现什么。

I know this is very old question, Since I didn't find a working example anywhere with command, With the below code you can get the ATR and UID of the card. 我知道这是一个非常老的问题,由于我在任何地方都没有找到可用的示例命令,因此,使用下面的代码,您可以获得卡的ATR和UID。

TerminalFactory factory = TerminalFactory.getDefault(); 
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// get the first terminal
CardTerminal terminal = terminals.get(0);

// establish a connection with the card
Card card = terminal.connect("*");
System.out.println("card: " + card);
ATR atr = card.getATR();
System.out.println("Card ATR: " + DatatypeConverter.printHexBinary(atr.getBytes()));
CardChannel channel = card.getBasicChannel();
CommandAPDU commandAPDU;
commandAPDU = new CommandAPDU(new byte[]{(byte) 0xFF,(byte) 0xCA,(byte) 0x00,(byte) 0x00,(byte) 0x00});             
ResponseAPDU r = channel.transmit(commandAPDU);
System.out.println("Response: " + r.toString() + ", NR: " + r.getNr());
String hex = DatatypeConverter.printHexBinary(r.getBytes());
System.out.println("Response: " + hex);
System.out.println("Card UID: " + DatatypeConverter.printHexBinary(r.getData()));
byte[] copyOf = Arrays.copyOf(r.getBytes(), r.getNr());
System.out.println("Card UID from bytes: " + DatatypeConverter.printHexBinary(copyOf));
// disconnect
card.disconnect(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM