简体   繁体   English

如何在Java中将RFID标签数据(Askii)转换为字符串

[英]how to convert rfid tag data (askii) to string in JAVA

I'm using the (id12 innovations) RFID read with a Raspberry Pi. 我正在使用(id12创新)Raspberry Pi读取RFID。 Using the PI4J java library and it's serial example, I'm able to read some data like (5002CF13C6) i'm not sure what this data is! 使用PI4J Java库及其串行示例,我能够读取一些数据,例如(5002CF13C6),我不确定该数据是什么! it suppose to get this number (0002948115). 它假定获得此号码(0002948115)。

here's is my code: 这是我的代码:

// create an instance of the serial communications class
final Serial serial = SerialFactory.createInstance();

// create and register the serial data listener
serial.addListener(new SerialDataListener() {
@Override
public void dataReceived(SerialDataEvent event) {
    //-----------
    System.out.print("\n" + event.getData());
    //-----------
}

});

try {
    // open the default serial port provided on the GPIO header
    serial.open("/dev/ttyAMA0", 9600);

    // continuous loop to keep the program running until the user terminates the program
    for (;;) {
        try {

        } catch (IllegalStateException ex) {
            ex.printStackTrace();
        }
        try {
            // wait 1 second before continuing
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            Logger.getLogger(Rfid.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

} catch (SerialPortException ex) {
    System.out.println("e: RFID setup failed : " + ex.getMessage());
}

what should i do to event.getData() in order to be able to read the real data? 为了能够读取真实数据,我应该对event.getData()做什么?

event.getData() , is returning to you exactly what the id12 chip is saying on the serial port. event.getData()完全返回给您id12芯片在串行端口上所说的内容。 The data is a 10 character string representation of a hexadecimal number, followed by a 2 character checksum. 数据是十六进制数字的10个字符串表示形式,后跟2个字符的校验和。

The behavior is specified in the id12 datasheet, which can be quickly found on google, or here: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/ID/ID-2LA,%20ID-12LA,%20ID-20LA(2013-4-10).pdf . 该行为是在ID12数据表中指定的,该数据表可以在Google上找到,也可以在以下位置快速找到: http ://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/ID/ID-2LA,%20ID-12LA,%20ID-20LA ( 2013-4-10).pdf In the linked PDF, it is page 4. 在链接的PDF中,它是第4页。

If you would like some help parsing this data in java, please supply some actual read data, and the corresponding expected values belonging to that read data. 如果您希望在Java中解析此数据有帮助,请提供一些实际读取的数据以及属于该读取数据的相应期望值。

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

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