Java Code Examples for javax.smartcardio.CardTerminals#list()

The following examples show how to use javax.smartcardio.CardTerminals#list() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CardManager.java    From JCMathLib with MIT License 5 votes vote down vote up
private Card waitForCard(CardTerminals terminals)
        throws CardException {
    while (true) {
        for (CardTerminal ct : terminals
                .list(CardTerminals.State.CARD_INSERTION)) {

            return ct.connect("*");
        }
        terminals.waitForChange();
    }
}
 
Example 2
Source File: Main.java    From openjavacard-ndef with GNU General Public License v3.0 5 votes vote down vote up
public static final void main(String[] arguments) {
    PrintStream os = System.out;
    TerminalFactory tf = TerminalFactory.getDefault();
    CardTerminals terminals = tf.terminals();

    try {
        // default command is info
        String command = "info";

        // check if user specified a reader as first argument
        if(arguments.length >= 1) {
            // if yes then use that reader
            String terminalName = arguments[0];
            CardTerminal terminal = terminals.getTerminal(terminalName);
            if(terminal == null) {
                throw new RuntimeException("Could not find terminal \"" + terminalName + "\"");
            }
            // check if the user also specified a command
            if(arguments.length >= 2) {
                command = arguments[1];
            }
            // split off the command arguments
            String[] commandArguments = new String[0];
            if(arguments.length > 2) {
                commandArguments = Arrays.copyOfRange(arguments, 2, arguments.length);
            }
            // run the command
            runCommand(terminal, command, commandArguments);
        } else {
            // else list all readers
            os.println("Available terminals:");
            for (CardTerminal t : terminals.list()) {
                os.println("  \"" + t.getName() + "\"");
            }
        }
    } catch (CardException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: FancyChooser.java    From apdu4j with MIT License 4 votes vote down vote up
public static FancyChooser forTerminals(CardTerminals terminals) throws IOException, CardException {
    List<CardTerminal> terminalList = terminals.list();
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    return new FancyChooser(terminal, screen, terminals, terminalList);
}