# Appendix A Code Examples

#### Open Device

```
if (! m_SCRA.isDeviceConnected()) 
{ 
    m_SCRA.openDevice(); 
}
```

#### Close Device <a href="#a.2_close_device" id="a.2_close_device"></a>

```
if (m_SCRA != null) 
{ 
    m_SCRA.closeDevice(); 
}
```

#### Get Connection Status Of Device <a href="#a.4_receiving_card_data_from_device" id="a.4_receiving_card_data_from_device"></a>

```
if (! m_SCRA.isDeviceConnected()) 
{ 

}
```

#### Receiving Card Data From Device <a href="#a.4_receiving_card_data_from_device" id="a.4_receiving_card_data_from_device"></a>

```
private Handler m_SCRAHandler =     
    new Handler(new SCRAHandlerCallback()); 
    
private MTSCRA m_SCRA = new MTSCRA(m_SCRAHandler); 

private class SCRAHandlerCallback implements Callback 
{ 
    public boolean handleMessage(Message msg) 
    { 
        Switch (msg.what) 
        { 
            Case MTSCRAEvent.CardDataReceived: 
                OnCardDataReceived(); 
                break; 
        } 
    } 
} 

public void OnCardDataReceived() 
{ 
    // Display raw card data 
    CardData.Text = m_SCRA.getResponseData();
    // Display last 4 digits of the card 
    CardLast4.Text = m_SCRA.getCardLast4(); 
}
```

#### &#x20;Send Command To Device <a href="#a.4_receiving_card_data_from_device" id="a.4_receiving_card_data_from_device"></a>

```
if (mSCRA.isDeviceConnected()) 
{ 
    // Send discovery command 
    m_SCRA.sendCommandToDevice(“C10206C20503840900”, 0); 
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.magtek.com/hardware/card-readers/magnetic-stripe-readers/idynamo-5-gen-iii/documentation/developers-manuals/programmers-manual-android/appendix-a-code-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
