我是 android 编程智能卡检测(读取)的新手。我们使用 otg 电缆将 RFC 读卡器 (RFID-RC522) 连接到 android 设备。使用 USB 串行端口 API 检测到 RFC 读卡器,但无法从 RFC 读卡器读取卡。我们已经在java中实现了读卡,但无法在android中实现。
1) 如何获取相当于windows COM端口的端口号
2)如果不可能,我该如何使用 connection.controlTransfer(UsbConstants.USB_DIR_OUT, 0x00, 0x0000, 0, null, 0, 0); 方法
3) 连接设备的Java代码
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) 请告诉我如何在 android 上进行交流,就像在 java 上一样