Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from inventid/check-for-synchronized-errors
Browse files Browse the repository at this point in the history
Add more logging to check for synchronized blocks
  • Loading branch information
rogierslag committed Oct 29, 2015
2 parents 4b3ca31 + 2981de4 commit 7794910
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/nl/inventid/rfidReader2keyboard/Read.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public Read(ScheduledThreadPoolExecutor executorService) {
*/
private void determineCardTerminalToUse() {
try {
System.out.println("Will enter sychronizer block [determineCardTerminalToUse]");
synchronized (synchronizer) {
System.out.println("Inside sychronizer block [determineCardTerminalToUse]");
// show the list of available terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
Expand All @@ -141,6 +143,7 @@ private void determineCardTerminalToUse() {
}
}
}
System.out.println("Exited sychronizer block [determineCardTerminalToUse]");
}
catch (Throwable e) {
// Probably no reader found...
Expand All @@ -157,7 +160,9 @@ private void determineCardTerminalToUse() {
*/
public void findAndConnectToTerminal() {
try {
System.out.println("Will enter sychronizer block [findAndConnectToTerminal]");
synchronized (synchronizer) {
System.out.println("Inside sychronizer block [findAndConnectToTerminal]");
// show the list of available terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
Expand All @@ -170,6 +175,7 @@ public void findAndConnectToTerminal() {
}
}
}
System.out.println("Exited sychronizer block [findAndConnectToTerminal]");
}
catch (Throwable e) {
// Probably no reader found...
Expand Down Expand Up @@ -200,7 +206,9 @@ public void run() {
return;
}
try {
System.out.println("Will enter sychronizer block [run]");
synchronized (synchronizer) {
System.out.println("Inside sychronizer block [run]");
// Connect to card and read
Card card = terminal.connect("T=1");

Expand All @@ -224,6 +232,7 @@ public void run() {
System.out.println("ready for next card");
System.out.println("Card scan run: " + i);
}
System.out.println("Exited sychronizer block [run]");
}
catch (CardException e) {
// Something went wrong when scanning the card
Expand Down Expand Up @@ -271,17 +280,21 @@ public void run() {
* @throws CardException in case of an error
*/
private String getCardUid(CardChannel channel) throws CardException {
System.out.println("Will enter sychronizer block [getCardUid]");
String uid;
synchronized (synchronizer) {
System.out.println("Inside sychronizer block [getCardUid]");
ResponseAPDU response = channel.transmit(READ_COMMAND);
String uid = new String(Hex.encodeHex(response.getData())).toUpperCase();
uid = new String(Hex.encodeHex(response.getData())).toUpperCase();
if (!new String(Hex.encodeHex(response.getBytes())).endsWith("9000")) {
throw new CardException(CARD_READ_FAILURE);
}
if (uid.isEmpty()) {
throw new CardException(EMPTY_CODE);
}
return uid;
}
System.out.println("Exited sychronizer block [getCardUid]");
return uid;
}

/**
Expand Down

0 comments on commit 7794910

Please sign in to comment.