# Appendix A Code Examples

#### A.1        Request List of Devices

To request a list of devices:

1. Create an MTSCRANET.MTSCRA object.
2. Set the connection type with setConnectionType().
3. Add a handler for OnDeviceList().
4. Call requestDeviceList().

```
MTSCRANET.MTSCRA listMTSCRA = new MTSCRANET.MTSCRA(); 
listMTSCRA.setConnectionType(MTConnectionType.USB); 
listMTSCRA.OnDeviceList() += listMTSCRA_OnDeviceList; 
listMTSCRA.requestDeviceList(MTConnectionType.USB); 

listMTSCRA_OnDeviceList( 
object sender, 
MTConnectionType connectionType, 
List<MTDeviceInformation> deviceList) 
{ 
//Handle deviceList 
}
```

#### A.2        Open Device(s) <a href="#a.2_open_device-s" id="a.2_open_device-s"></a>

To open multiple devices:

1. Create an MTSCRANET.MTSCRA object.
2. Set the connection type with setConnectionType().
3. Add a handler for OnDeviceList().
4. Call requestDeviceList().
5. Create an MTSCRANET.MTSCRA object for each reader.
6. Set the connection type with setConnectionType() for each reader.
7. Call openDevice() for each reader.

```
MTSCRANET.MTSCRA listMTSCRA = new MTSCRANET.MTSCRA();  
listMTSCRA.setConnectionType(MTConnectionType.USB); 
listMTSCRA.OnDeviceList() += listMTSCRA_OnDeviceList; 
MTDeviceInformation listDeviceInfo; 
listMTSCRA.requestDeviceList(MTConnectionType.USB); 

listMTSCRA_OnDeviceList( 
object sender, 
MTConnectionType connectionType, 
List<MTDeviceInformation> deviceList) 
{ 
    //Handle deviceList 
    For Each (dev in deviceList) 
    { 
    
    } 
    listDeviceInfo.Add(dev) 
} 
MTSCRANET.MTSCRA msr1 = new MTSCRANET.MTSCRA(); 
MTSCRANET.MTSCRA msr2 = new MTSCRANET.MTSCRA(); 
MTSCRANET.MTSCRA msr3 = new MTSCRANET.MTSCRA(); 

msr1.setConnectionType(MTConnectionType.USB); 
msr1.setAddress(dev.Address); msr1.openDevice(); 
if (! msr1.isDeviceConnected()) 
{ 
    msr1.openDevice(); 
} 

msr2.setConnectionType(MTConnectionType.USB); 
msr2.setAddress(dev.Address); 
msr2.openDevice(); 
if (! msr2.isDeviceConnected()) 
{ 
    msr2.openDevice(); 
    } 
    
msr3.setConnectionType(MTConnectionType.USB); 
msr3.setAddress(dev.Address); 
msr3.openDevice(); 
if (! msr3.isDeviceConnected()) 
{ 
    msr3.openDevice(); 
}

```

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

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

#### Get Connection Status of Device <a href="#a.4_get_connection_status_of_device" id="a.4_get_connection_status_of_device"></a>

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

}
```

#### Receiving Card Data from Device <a href="#a.5_receiving_card_data_from_device" id="a.5_receiving_card_data_from_device"></a>

```
if (! mMTSCRA.isDeviceConnected()) 
{ 
mMTSCRA.CardDataReceived += OnCardDataReceived; 
mMTSCRA.openDevice(); 
} 

public void OnCardDataReceived(Object sender) 
{ // Display last 4 digits of the card 
CardLast4.Text = mMTSCRA.getCardLast4(); 
}
```

#### A.6        Send Command to Device <a href="#a.6_send_command_to_device" id="a.6_send_command_to_device"></a>

```
if (mMTSCRA.isDeviceConnected()) 
{ 
    // Send discovery command 
    mMTSCRA.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-.net-pcl/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.
