3

I've been testing and working on my RFID scanner code and I found something weird. When I tap the card, there are some instances where the results are truncated.

Examples:

Tap 1: [2]1,000,007 ,000242985

Tap 2: 7[3][2]1,000,0 07,0002429

Tap 3: 857[3][2]1,000 ,007,00024

Tap n: etc.

Expected Output: [2]R,AAA,TTT,NNNNNNNNNN[3]

R = if the ID is registered or not: flags 1 and 0
A = The address where the ID is located inside the scanner's memory
T = the type of card
N = the ID number

If I understand correctly, the transmission starts and ends with a ASCII character 2 and 3. So it looks like what I'm getting is an incomplete result. How can I solve this?

Here is my full code:

import jssc.SerialPort; 
import jssc.SerialPortEvent; 
import jssc.SerialPortEventListener; 
import jssc.SerialPortException;

public class ComControl{
    static SerialPort serialPort;
    String[] collector;

    public static void main(String[] args) {
        serialPort = new SerialPort("COM6"); 
        try {
            serialPort.openPort();//Open serial port
            serialPort.setParams(SerialPort.BAUDRATE_9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
            serialPort.writeBytes("\002v0\003".getBytes());//Write data to port
            serialPort.closePort();//Close serial port
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
        try {
            serialPort.openPort();//Open port
            serialPort.setParams(9600, 8, 1, 0);//Set params
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;//Prepare mask
            serialPort.setEventsMask(mask);//Set mask
            serialPort.addEventListener(new SerialPortReader());//Add SerialPortEventListener
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }
    static class SerialPortReader implements SerialPortEventListener {
        @Override
        public void serialEvent(SerialPortEvent event) {
            try{

            }catch(Exception e){
                System.out.println(e);
            }

            if(event.isRXCHAR()){//If data is available
                if(event.getEventValue() == 10){//Check bytes count in the input buffer
                    //Read data, if 10 bytes available
                    String sizer="";
                    try{
                        sizer="";
                        sizer += serialPort.readString();

                    }catch (SerialPortException ex) {
                        System.out.println(ex);
                    }
                    System.out.println(sizer);
                    sizer = "";
                }
            }
//            else if(event.isCTS()){//If CTS line has changed state
//                if(event.getEventValue() == 1){//If line is ON
//                    System.out.println("CTS - ON");
//                }
//                else {
//                    System.out.println("CTS - OFF");
//                }
//            }
//            else if(event.isDSR()){///If DSR line has changed state
//                if(event.getEventValue() == 1){//If line is ON
//                    System.out.println("DSR - ON");
//                }
//                else {
//                    System.out.println("DSR - OFF");
//                }
//            }
        }
    }
}

Here is information about the device I am using: Low Cost RFID Reader - e-Gizmo

TT.
  • 15,774
  • 6
  • 47
  • 88
Bumpy
  • 97
  • 11

1 Answers1

0

Nevermind, I got the answer. I was stupid enough to put 10 bytes when its actually 22 bytes.

Bumpy
  • 97
  • 11