# MTCMS Class Methods

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

#### requestDeviceList&#x20;

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

```
MTCMS_API void requestDeviceList(MTConnectionType connectionType); Parameters:
```

Parameters:

|                |                                                                                            |
| -------------- | ------------------------------------------------------------------------------------------ |
| Parameter      | Description                                                                                |
| connectionType | MTConnectionType value: MTConnectionType.USB, MTConnectionType.IP, MTConnectionType.Serial |

Return Value: None

#### setConnectionType&#x20;

This method sets the connection type of the device..&#x20;

```
MTCMS_API void setConnectionType(MTConnectionType connectionType); 
```

Parameters

|                |                                                                                            |
| -------------- | ------------------------------------------------------------------------------------------ |
| Parameter      | Description                                                                                |
| connectionType | MTConnectionType value: MTConnectionType.USB, MTConnectionType.IP, MTConnectionType.Serial |

Return Value: None&#x20;

#### setAddress&#x20;

This method sets the address of the device.&#x20;

```
MTCMS_API void setAddress(const char* deviceAddress);
```

Parameters:

|               |                              |
| ------------- | ---------------------------- |
| Parameter     | Description                  |
| deviceAddress | String value of the address. |

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

|                 |                          |                                                                                                                                 |
| --------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| Connection Type | Address Format Parameter | Address Format Description                                                                                                      |
| USB             | \[PATH]                  | The OS specific device path to the USB device. The path is normally retrieved from the Address property of MTDeviceInformation. |
| IP              | \[IPA]                   | The IP address of the device in dotted-quad notation (i.e. 192.178.1.123).                                                      |
| IP              | \[PORT]                  | The TCP port of the device. (Default: 5000)                                                                                     |

|                 |                                                                                                                                                                                                                                                                     |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Connection Type | Address Format                                                                                                                                                                                                                                                      |
| Serial          | <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> |

|                 |                 |                                                                                                                                                                                                                |
| --------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Connection Type | Parameter       | Description                                                                                                                                                                                                    |
| Serial          | \[PORT]         | The OS specific device path to the serial port (i.e. COM4).                                                                                                                                                    |
| Serial          | \[BAUDRATE]     | The data baud rate . (Default: 9600)                                                                                                                                                                           |
| Serial          | \[DATABITS]     | The data bits per byte. (Default: 8)                                                                                                                                                                           |
| Serial          | \[PARITY]       | <p>The parity checking protocol. (Default: NONE). </p><p></p><p>Supported Values: NONE,EVEN,ODD,SPACE,MARK</p>                                                                                                 |
| Serial          | \[STOPBITS]     | <p>The number of stop bits per byte. (Default: 1)</p><p></p><p>Supported Values: 1,1.5,2</p>                                                                                                                   |
| Serial          | \[HANDSHAKE]    | <p>The handshaking protocol for serial port transmission of data. (Default: NONE) </p><p></p><p>Supported Values: NONE,RTS,XONXOFF,RTSXONSOFF</p>                                                              |
| Serial          | \[STARTINGBYTE] | <p>The special character used as the starting byte for each message. (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> |
| Serial          | \[ENDINGBYTE]   | The special character used as the ending byte for each message. (Default is 0x0A)                                                                                                                              |
| Serial          |                 | An empty string indicates no special character is used as the ending byte for each message.                                                                                                                    |
| Serial          | \[CRCMODE]      | A value of 0 indicates CRC is disabled, otherwise CRC is enabled. (Default: 0)                                                                                                                                 |

Return Value: None

#### setDeviceID&#x20;

This method sets the device ID.

```
MTCMS_API void setDeviceID(const char* deviceID); 
```

|           |                                |
| --------- | ------------------------------ |
| Parameter | Description                    |
| deviceID  | String value of the device ID. |

Return Value: None

#### openDevice&#x20;

This method opens the connection to the device.&#x20;

```
MTCMS_API void openDevice(); 
```

Parameters: None&#x20;

Return Value: None

#### closeDevice

This method closes the connection to the device.

```
MTCMS_API void closeDevice();
```

Parameters: None Return Value: None

#### isDeviceConnected <a href="#id-4.7_isdeviceconnected" id="id-4.7_isdeviceconnected"></a>

This method returns whether the device is connected or not.

```
MTCMS_API bool isDeviceConnected();
```

Parameters: None

Return Value:

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

#### sendDataString <a href="#id-4.8_senddatastring" id="id-4.8_senddatastring"></a>

This method sends a command string to the device.

```
MTCMS_API int sendCommandString(const char* dataString);
```

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">dataString</td><td valign="top">Command to be sent in hexadecimal string format.</td></tr></tbody></table>

Return Value:

* 0 = Success
* 9 = Error
* 15 = Busy

#### sendDataBytes <a href="#id-4.9_senddatabytes" id="id-4.9_senddatabytes"></a>

This method sends a command to the device.

```
MTCMS_API int sendDataBytes( 
const unsigned char* dataBytes, 
int dataBytesLength);
```

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">dataBytes</td><td valign="top">Command to be sent in byte array format.</td></tr><tr><td valign="top">dataBytesLength</td><td valign="top">Length of the command bytes.</td></tr></tbody></table>

Return Value:

* 0 = Success
* 9 = Error
* 15 = Busy

#### sendMTCMSMessage <a href="#id-4.10_sendmtcmsmessage" id="id-4.10_sendmtcmsmessage"></a>

This method sends a command to the device.

```
MTCMS_API int sendMTCMSMessage(MTCMSMessage* message);
```

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">message</td><td valign="top">MTCMSMessage to be sent to the device.</td></tr></tbody></table>

Return Value:

* 0 = Success
* 9 = Error
* 15 = 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-programmers-reference-manual-c++/mtcms-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.
