public interface MSRDevice extends Device, TimeConstants
The MSR device object is obtained from the POSTerminal
, its' as follows:
MSRDevice msrDevice = (MSRDevice) POSTerminal.getInstance().getDevice("cloudpos.device.msr");Among them, the "cloudpos.device.msr" string is to identify the MSR device, defined by the specific implementation.
Uses the MSR device object to control the operation of the MSR device.
An app can request permission to access the device, as shown below:
<uses-permission android:name="android.permission.CLOUDPOS_MSR"/>
FOREVER, IMMEDIATE, MilliSECOND, SECOND
Modifier and Type | Method and Description |
---|---|
void |
listenForSwipe(OperationListener listener,
int timeout)
Initiates the operation to obtain the data read from selected tracks.
|
void |
open(int logicalID)
Connects the MSR device to a specific logical ID.
|
MSROperationResult |
waitForSwipe(int timeout)
The synchronous method of
listenForSwipe(OperationListener,int) . |
cancelRequest, close, getFailCount, getUsageCount, open
void open(int logicalID) throws DeviceException
logicalID
- The logical ID of the MSR device to openDeviceException
- for the standard reasons that are documented in
DeviceException
.void listenForSwipe(OperationListener listener, int timeout) throws DeviceException
listenForSwipe
request will complete and generate the
resulted operation result once a new card has been swiped after this
request was posted. In order to ensure the integrity of data,
listenForSwipe()
first reinitializes any existing card data
buffer that may have been created by previous card swipings, before
waiting for a new card to be swiped. No effective reading of the card
tracks will be done until a request is pending.
This method is asynchronous and results in an
MSROperationResult
sent to the handleResult
method of the OperationListener
. On success, the read data
can be retrieved using the operation result's getMSCardData
method.
Because this method uses a timeout parameter, the device receiving this request MUST be able to
successfully respond to cancelRequest()
and abort the operation.
In case of a timeout occurring, the operation result will contain code=
ERR_TIMEOUT
, and no information about
card will be available.
listener
- operation listener.timeout
- the maximum pending time of the method, in milliseconds.
Note that the timeout will begin when the request begins to be
processed. The timeout
parameter is then only
indicative. There are two special cases for
timeout
, as follows:
timeout == FOREVER
, the method will wait
until something is available on the associated service's
input. timeout == IMMEDIATE
, the method
will immediately read the input
DeviceException
- for the standard reasons that are documented in
DeviceException
.OperationListener.handleResult(com.cloudpos.OperationResult)
,
MSROperationResult
,
MSRTrackData
MSROperationResult waitForSwipe(int timeout) throws DeviceException
listenForSwipe(OperationListener,int)
.
This method will block the invoker's thread until timeout, data arrived or canceled by another thread.
timeout
- the maximum pending time of the method, in milliseconds.
Note that the timeout will begin when the request begins to be
processed. The timeout
parameter is then only
indicative. There are two special cases for
timeout
, as follows:
timeout == FOREVER
, the method will wait
until something is available on the associated service's
input. timeout == IMMEDIATE
, the method
will immediately read the input
DeviceException
- for the standard reasons that are documented in
DeviceException
.