1

I am new to android programming smart card detection (read). We have RFC card reader(RFID-RC522) connected to the android device using otg cable. RFC Card reader is detected using usb-serial port api, but unable to read card from RFC card reader. We have implemented card reading in java but unable to implement in android.

1) How to get port number equivalent to windows COM ports

2) If it is not possible, how can I communicate using connection.controlTransfer(UsbConstants.USB_DIR_OUT, 0x00, 0x0000, 0, null, 0, 0); method

3) Java Code for Connecting Device

static int connect ( String portName ) throws IOException
{

     CommPortIdentifier portIdentifier = null;


     try {
         portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
     } catch (NoSuchPortException e) {
         System.out.println("Port " + portName + " is not available");
     }
     if ( portIdentifier.isCurrentlyOwned() )
     {
         System.out.println("Error: Port " + portName + " is currently in use");
     }
     else
     {
         CommPort commPort = null;
         try {
             commPort = portIdentifier.open(portName,2000);
         } catch (PortInUseException e) {
             System.out.println("Error: Port " + portName + " is currently in use");
         }
         System.out.println("Info: Port Availble "+portName);
         if ( commPort instanceof SerialPort )
         {
             SerialPort serialPort = (SerialPort) commPort;
             try {
                 serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
             } catch (UnsupportedCommOperationException e) {
                 System.out.println("Error: Port " + portName + " is currently in use");
             }

             InputStreamIn = serialPort.getInputStream();
             OutputStreamOut = serialPort.getOutputStream();
             return 0;
         }
         else
         {
             //System.out.println("Error: Only serial ports are handled by this example.");
             System.out.println("Error: Port " + portName + " is currently in use");
         }
     }    
     return -1;
 }

4) Please tell me how on android can I communicate like on java

rminaj
  • 560
  • 6
  • 28

1 Answers1

-1

You have to use USB Host Android API: http://developer.android.com/guide/topics/connectivity/usb/host.html to enumerate devices, grant permission.

To communicate you could also use this API or there's also open-source library for usb-serial devices as this one: https://github.com/mik3y/usb-serial-for-android

UPDATE1

For instance, in this lib, you have a class https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/UsbSerialPort.java with read and write methods.

LaurentY
  • 7,495
  • 3
  • 37
  • 55