# Appendix B Code Examples

#### Open Device

```
self.mtSCRALib = [[MTSCRA alloc] init]; 
[self.mtSCRALib 
listenForEvents: TRANS_EVENT_OK|TRANS_EVENT_START|TRANS_EVENT_ERROR)]; 

//iDynamo 
[self.mtSCRALib setDeviceType:(MAGTEKIDYNAMO)]; 
[self.mtSCRALib setDeviceProtocolString:(“com.magtek.idynamo”)]; 

//Audio 
//[self.mtSCRALib setDeviceType:(MAGTEKAUDIOREADER)]; 
[self.mtSCRALib openDevice];
```

#### Close Device

```
[self.mtSCRALib closeDevice];
```

#### Get Track Data from Reader

```
[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(trackDataReady:) name:@"trackDataReadyNotification" 
object:nil];

-  (void)trackDataReady:(NSNotification *)notification
{
    NSNumber *status = [[notification userInfo] 
valueForKey:@"status"];
    [self performSelectorOnMainThread:@selector(onDataEvent:) 
withObject:status waitUntilDone:YES];
}
-  (void)onDataEvent:(id)status
{
    //[self clearLabels];
    switch ([status intValue]) {
    
        case TRANS_STATUS_OK: 
        NSLog(@"TRANS_STATUS_OK");
        break;
        
        case TRANS_STATUS_ERROR: 
        NSLog(@"TRANS_STATUS_ERROR");
        break;
        
        default:
            break;
    }
}
```

#### Get Connection Status of Reader

```
[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(devConnStatusChange) 
name:@"devConnectionNotification" object:nil];

- (void)devConnStatusChange
{
    BOOL isDeviceConnected = [self.mtSCRALib isDeviceConnected]; 
    if (isDeviceConnected)
    {
        self.deviceStatus.text = @"Device Connected";
    }
    else
    {
        self.deviceStatus.text = @"Device Disconnected";
    }
}
```

#### Diagrams

**MSR Card Swipe**

<figure><img src="/files/BBBo2nwu3kuWPEn914r6" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:** This is broad to cover multiple devices. For devices that do not need or support a specific command, (i.e. SetMSRAlwaysOn), that portion may be omitted in the flow.
{% endhint %}

<figure><img src="/files/E9CF2qJoVTHgXNe6hdmx" alt=""><figcaption></figcaption></figure>

**EMV Transaction (Quick Chip)**

<figure><img src="/files/8G59FMXoQpJOnVdSy3s4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**: This is broad to cover multiple devices. For devices that do not need or support a specific command, (i.e. SetMSRAlwaysOn), that portion may be omitted in the flow.
{% endhint %}

<figure><img src="/files/sPg9KbYtEFkBKZGqJe9w" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Hl6FnfpxVUftmM1JLoAk" alt=""><figcaption></figcaption></figure>

**EMV Transaction (Full)**

<figure><img src="/files/jY3CBXU69jlxAfOlcXSc" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2vXDA9BJrsavQdXEUyfz" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Y58uxNEBWs8hJyDzDd5S" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**: This is broad to cover multiple devices. For devices that do not need or support a specific command, (i.e. SetMSRAlwaysOn), that portion may be omitted in the flow.
{% endhint %}


---

# 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/secure-card-reader-authenticators-sdk-programmers-manual-ios/appendix-b-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.
