public class PcscliteWrapper extends Object
PcscliteLibrary| Modifier and Type | Field and Description |
|---|---|
protected PcscliteLibrary |
instance |
protected String |
nativeLocation |
| Constructor and Description |
|---|
PcscliteWrapper() |
PcscliteWrapper(String nativeLocation) |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose() |
protected String |
getNativeLocation() |
CardHandle |
sCardConnect(long hContext,
String readerName,
CardShareMode shareMode,
SCardProtocol... preferredProtocols)
The sCardConnect function establishes a connection (using a specific
resource manager context) between the calling application and a smart
card contained by a specific reader.
|
void |
sCardDisconnect(CardHandle hCard,
int dwDisposition)
The SCardDisconnect function terminates a connection previously opened
between the calling application and a smart card in the target reader.
|
long |
sCardEstablishContext(int scope) |
PcscReaderState[] |
sCardGetStatusChange(long hContext,
int timeout,
PcscReaderState[] rState)
Blocks execution until the current availability of the cards in a
specific set of readers changes.
|
boolean |
sCardisValidContext(long hContext) |
String[] |
sCardListReaderGroups(long hContext) |
String[] |
sCardListReaders(long hContext) |
void |
sCardReleaseContext(long hContext) |
void |
sCardSetTimeout(long hContext) |
protected final String nativeLocation
protected PcscliteLibrary instance
public PcscliteWrapper()
throws IOException
IOExceptionpublic PcscliteWrapper(String nativeLocation) throws IOException
IOExceptionprotected String getNativeLocation()
public void dispose()
public long sCardEstablishContext(int scope)
throws PcscException
PcscExceptionpublic PcscReaderState[] sCardGetStatusChange(long hContext, int timeout, PcscReaderState[] rState) throws PcscException
Blocks execution until the current availability of the cards in a specific set of readers changes.
This function receives a structure or list of structures containing reader names. It then blocks waiting for a change in state to occur for a maximum blocking time of dwTimeout or forever if INFINITE is used.
Sample usage:
PcscLiteWrapper pcscw=...
long hContext= pcscw.sCardEstablishContext(PcscLiteConstants.SCARD_SCOPE_USER);
String[] terminals = pcscw.sCardListReaders(context);
final PcscReaderState[] rstates = new PcscReaderState[terminals.length];
for (int i = 0; i < terminals.length; i++) {
final String tname = terminals[i];
rstates[i] = new PcscReaderState(null,
PcscLiteConstants.SCARD_STATE_UNAWARE, 0, tname, null);
}
// set the timeout to 5 second
final PcscReaderState[] result = pcscw.sCardGetStatusChange(
context, 5000, rstates);
for (int i = 0; i < result.length; i++) {
final PcscReaderState state = result[i];
final int eventState = state.getEventState();
if (((eventState & PcscLiteConstants.SCARD_STATE_PRESENT) != 0)
&& (state.getATR() != null) && (state.getATR().length > 0)) {
if ((eventState & (PcscLiteConstants.SCARD_STATE_MUTE | PcscLiteConstants.SCARD_STATE_UNAVAILABLE)) == 0) {
System.out.println(StringUtilsCN.toHexString(state
.getATR());
}
}
}
hContext - Active pc/sc context as returned by
sCardEstablishContext(int)timeout - timeout of the request in milliseconds.rState - Array of reader state.PcscException - Thrown when there is an error in PC/SC. Use
PcscException.getErrorCode() to get the error code.PcscliteLibrary#SCardGetStatusChange(NativeLong, int, SCARD_READERSTATE_A, int)}public String[] sCardListReaders(long hContext) throws PcscException
PcscExceptionpublic String[] sCardListReaderGroups(long hContext) throws PcscException
hContext - Active pc/sc context as returned by
sCardEstablishContext(int)PcscExceptionSCardListReaderGroupspublic void sCardReleaseContext(long hContext)
throws PcscException
PcscExceptionpublic boolean sCardisValidContext(long hContext)
hContext - Active pc/sc context as returned by
sCardEstablishContext(int)PcscliteLibrary.SCardIsValidContext(com.sun.jna.NativeLong)public void sCardSetTimeout(long hContext)
throws PcscException
PcscExceptionpublic CardHandle sCardConnect(long hContext, String readerName, CardShareMode shareMode, SCardProtocol... preferredProtocols) throws PcscException
hContext - Active pc/sc context as returned by
sCardEstablishContext(int)readerName - shareMode - flag that indicates whether other applications may form
connections to the card. CardShareModepreferredProtocols - PcscExceptionpublic void sCardDisconnect(CardHandle hCard, int dwDisposition) throws PcscException
hCard - Reference value obtained from a previous call to
sCardConnect(long, String, CardShareMode, SCardProtocol...) .dwDisposition - Action to take on the card in the connected reader on close.PcscExceptionPcscliteWrapper#sCardConnect(long, String, CardShareMode, SCardProtocol...)}Copyright © 2011-2013. All Rights Reserved.