# MTDevice Class Methods

After creating an instance of the MTDevice class in your software project, use the methods described in this section to communicate with MagTek CMS device.

#### requestDeviceList <a href="#toc_250048" id="toc_250048"></a>

This method initiates request to discover devices that are visible to the host using the specified connection interface. The OnDeviceList event will provide information regarding the available devices once the discovery process is completed.

```
public void requestDeviceList(MTConnectionType connectionType)
```

Parameters:

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">connectionType</td><td valign="top">MTConnectionType value: MTConnectionType.USB, MTConnectionType.IP, MTConnectionType.Serial</td></tr></tbody></table>

Return Value: None

#### setConnectionType <a href="#toc_250047" id="toc_250047"></a>

This method sets the connection type of the device..

```
public void setConnectionType(MTConnectionType connectionType)
```

Parameters:

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">connectionType</td><td valign="top">MTConnectionType value: MTConnectionType.USB, MTConnectionType.IP, MTConnectionType.Serial</td></tr></tbody></table>

Return Value: None

#### setAddress <a href="#toc_250046" id="toc_250046"></a>

This method sets the address of the device.

```
public void setAddress(string deviceAddress)
```

Parameters:

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">deviceAddress</td><td valign="top">String value of the address.</td></tr></tbody></table>

The following table shows the address formats supported by the different connection types:

<table data-header-hidden><thead><tr><th width="170.66668701171875" valign="top"></th><th width="250.00006103515625" valign="top"></th><th></th></tr></thead><tbody><tr><td valign="top">Connection Type</td><td valign="top">Address Format Parameter</td><td>Address Format Descroption</td></tr><tr><td valign="top">USB</td><td valign="top">[PATH]</td><td>The OS specific device path to the USB device. The path is normally retrieved from the Address property of MTDeviceInformation.</td></tr><tr><td valign="top">IP</td><td valign="top"><p>[IPA]</p><p></p></td><td>The IP address of the device in dotted-quad notation (i.e. 192.178.1.123).</td></tr><tr><td valign="top">IP</td><td valign="top">[PORT]</td><td>The TCP port of the device. (Default: 5000)</td></tr></tbody></table>

<table data-header-hidden><thead><tr><th width="115.33331298828125" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">Serial</td><td valign="top"><p>PORT=[PORT], </p><p>BAUDRATE=[BAUDRATE], </p><p>DATABITS=[DATABITS], </p><p>PARITY=[PARITY], </p><p>STOPBITS=[STOPBITS], </p><p>HANDSHAKE=[HANDSHAKE], </p><p>STARTINGBYTE=[STARTINGBYTE], </p><p>ENDINGBYTE=[ENDINGBYTE], </p><p>CRCMODE=[CRCMODE]</p></td></tr></tbody></table>

<table data-header-hidden><thead><tr><th width="174.66668701171875" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">[PORT]</td><td valign="top">The OS specific device path to the serial port (i.e. COM4).</td></tr><tr><td valign="top">[BAUDRATE]</td><td valign="top">The data baud rate . (Default: 9600)</td></tr><tr><td valign="top">[DATABITS]</td><td valign="top">The data bits per byte. (Default: 8)</td></tr><tr><td valign="top">[PARITY]</td><td valign="top"><p>The parity checking protocol. (Default: NONE).</p><p>Supported Values: NONE,EVEN,ODD,SPACE,MARK</p></td></tr><tr><td valign="top">[STOPBITS]</td><td valign="top"><p>The number of stop bits per byte. (Default: 1)</p><p> </p><p>Supported Values: 1,1.5,2</p></td></tr><tr><td valign="top">[HANDSHAKE]</td><td valign="top"><p>The handshaking protocol for serial port transmission of data.</p><p>(Default: NONE)</p><p> </p><p>Supported Values: NONE,RTS,XONXOFF,RTSXONSOFF</p></td></tr><tr><td valign="top">[STARTINGBYTE]</td><td valign="top"><p>The special character used as the starting byte for each message.</p><p>(Default is empty string)</p><p> </p><p>An empty string indicates no special character is used as the starting byte for each message.</p></td></tr><tr><td valign="top">[ENDINGBYTE]</td><td valign="top"><p>The special character used as the ending byte for each message.</p><p>(Default is 0x0A)</p></td></tr></tbody></table>

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Connection Type</td><td valign="top">Address Format</td></tr><tr><td valign="top"> </td><td valign="top"> An empty string indicates no special character is used as the ending byte for each message</td></tr><tr><td valign="top">[CRCMODE]</td><td valign="top"><p>A value of 0 indicates CRC is disabled, otherwise CRC is enabled.</p><p>(Default: 0)</p></td></tr><tr><td valign="top"></td><td valign="top"></td></tr></tbody></table>

Return Value: None

#### setDeviceID

This method sets the device ID.

```
public void setDeviceID(string deviceID)
```

Parameters:

<table data-header-hidden><thead><tr><th width="146" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">deviceID</td><td valign="top">String value of the device ID.</td></tr></tbody></table>

Return Value: None

#### openDevice <a href="#toc_250044" id="toc_250044"></a>

This method opens the connection to the device.

```
public void openDevice()
```

Parameters: None&#x20;

Return Value: None

#### closeDevice <a href="#toc_250043" id="toc_250043"></a>

This method closes the connection to the device.

```
public void closeDevice()
```

Parameters: None&#x20;

Return Value: None

#### isDeviceConnected <a href="#toc_250042" id="toc_250042"></a>

This method returns whether the device is connected or not.

```
public bool isDeviceConnected()
```

Parameters: None

Return Value:

Return true if the device is connected. Otherwise, return false.

#### sendDataString <a href="#toc_250041" id="toc_250041"></a>

This method sends a data string to the device.

```
public int sendDataString(string dataString)
```

Parameters:

<table data-header-hidden><thead><tr><th width="156.66668701171875" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">dataString</td><td valign="top">Data to be sent in hexadecimal string format.</td></tr></tbody></table>

Return Value:

* 0 = Success (MTDevice.SEND\_SUCCESS)
* 9 = Error (MTDevice.SEND\_ERROR)
* 15 = Busy (MTDevice.SEND\_BUSY)

#### sendDataBytes <a href="#toc_250040" id="toc_250040"></a>

This method sends data bytes to the device.

```
public int sendDataBytes(byte[] dataBytes)
```

Parameters:

<table data-header-hidden><thead><tr><th width="164.6666259765625" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">dataBytes</td><td valign="top">Data to be sent in byte array format.</td></tr></tbody></table>

Return Value:

* 0 = Success (MTDevice.SEND\_SUCCESS)
* 9 = Error (MTDevice.SEND\_ERROR)
* 15 = Busy (MTDevice.SEND\_BUSY)

#### sendMTCMSMessage <a href="#toc_250039" id="toc_250039"></a>

This method sends a MagTek CMS message to the device.

```
public int sendMTCMSMessage(MTCMSMessage message)
```

Parameters:

<table data-header-hidden><thead><tr><th width="154.66668701171875" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Description</td></tr><tr><td valign="top">message</td><td valign="top">MTCMSMessage to be sent to the device.</td></tr></tbody></table>

Return Value:

* 0 = Success (MTDevice.SEND\_SUCCESS)
* 9 = Error (MTDevice.SEND\_ERROR)
* 15 = Busy (MTDevice.SEND\_BUSY)


---

# 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/oem-readers-and-components/oem-readers/odynamo/documentation/programmers-manuals/common-message-structure-mtcms-microsoft-.net-java-applet/mtdevice-class-methods.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.
