Package com.zebra.sdk.device
Interface MagCardReader
public interface MagCardReader
Provides access to the magnetic card reader, for devices equipped with one.
package test.zebra.sdk.device.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.device.MagCardReader;
import com.zebra.sdk.device.MagCardReaderFactory;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
public class MagCardReaderExample {
public static void main(String[] args) throws Exception {
Connection connection = new TcpConnection("192.168.1.100", TcpConnection.DEFAULT_CPCL_TCP_PORT);
try {
connection.open();
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
MagCardReader mcr = MagCardReaderFactory.create(printer);
if (mcr != null) {
String[] trackData = mcr.read(10 * 1000);
System.out.println("Track1: " + trackData[0]);
System.out.println("Track2: " + trackData[1]);
System.out.println("Track3: " + trackData[2]);
}
} catch (ConnectionException e) {
e.printStackTrace();
} catch (ZebraPrinterLanguageUnknownException e) {
e.printStackTrace();
} finally {
connection.close();
}
}
}
-
Method Summary
-
Method Details
-
read
Activates the device's magnetic card reader, if present, and waits for a card to be swiped. If the device does not have a reader the call will timeout.- Parameters:
timeoutMS- the amount of time in milliseconds to enable the reader and wait for a card to be swiped.- Returns:
- An array of three strings corresponding to the tracks of the card. If a track could not be read that string will be empty.
- Throws:
ConnectionException- if an I/O error occurs.
-