The readCard method reads data from a card using either the magnetic swipe reader (MSR) or the contactless NFC reader. It supports Mifare cards only for NFC. This method is commonly used in loyalty or identification scenarios.

If the user cancels the operation or the request times out, it can be aborted using the abortReadCard method.

Request

📘

JSON-RPC 2.0

All methods in TweezerComm follow a JSON-RPC 2.0 structure. See Get Startedfor more details on how the requests are structured and sent.

In the request, the method field should be set to readCard the parameters should define the reader configuration and user interface messages.

{
    "jsonrpc": "2.0",
    "method": "readCard",
    "id": "1234567890",
    "params": [
        "device",
        {
            "readMsr": true,
            "readMifare": true,
            "message1": "SWIPE OR PRESENT CARD",
            "message2": "",
            "message3": "",
            "timeout": 40,
            "cancelable": true,
            "mifare": {
                "type": "classic",
                "commType": 2,
                "appId": "A12345",
                "appKey": "00000000000000000000000000000123",
                "appKeyNo": 0,
                "appCryptoMethod": 1,
                "fileNo": 0,
                "fileType": 0,
                "expectedDataLen": 4
            }
        }
    ]
}

Request Parameters

See the table below for a description of the available request parameters for this method.

NameTypeDescription
readMsrboolWhether to enable the magnetic stripe reader.
readMifareboolWhether to enable the NFC reader (Mifare only).
message1stringMain message shown to the user.
message2stringFirst subtitle shown to the user.
message3stringSecond subtitle shown to the user.
timeoutintTimeout in seconds.
cancelableboolWhether to allow canceling the operation.

Mifare Object Parameters

NameTypeDescription
typestringCard type (classic, desfireev2, etc.)
commTypeintCommunication type
appIdstringApplication ID
appKeystringApplication key
appKeyNointApplication key number
appCryptoMethodintCrypto method
fileNointFile number
fileTypeintFile type
expectedDataLenintExpected data length

Response

A successful request will return a response similar to the one in the code block below:

{
    "jsonrpc": "2.0",
    "id": "123454352",
    "result": {
        "statusCode": 0,
        "statusMessage": "ok",
        "cardEntryMode": 1,
        "cardId": "string"
    }
}

Response Parameters

Below is a table with all the possible response parameters and their description

NameTypeDescription
statusCodeintegerOperation status (0 = success)
statusMessagestringOperation result message
cardEntryModeintEntry mode: 0 = Swipe, 1 = Contactless
track2stringTrack 2 data (for swipe only)
cardIdstringCard ID (for contactless only)