> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr_8h.md).

# msr.h

[Typedefs](#typedef-members) | [Functions](#func-members)

`#include "`[msr\_common.h](/adk-5.0-programmers-guide/msr__common_8h_source.md)`"`

Include dependency graph for msr.h:

![](/files/Vjcb7h4AayY0Mvh6jsxS)

This graph shows which files directly or indirectly include this file:

![](/files/1NwEodA47Lel4Vcojlbq)

[Go to the source code of this file.](/adk-5.0-programmers-guide/msr_8h_source.md)

|                 |                                                                    |
| --------------- | ------------------------------------------------------------------ |
| Typedefs        |                                                                    |
| typedef void(\* | [MSR\_Callback](#a612917ffe22ec9bedebfad13038d28fd)) (void \*data) |

|           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Functions |                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| int       | [MSR\_SetOptions](#ac3c6f568aa57690a8b369936fc362c2a) (unsigned char \*options, unsigned char options\_len)                                                                                                                                                                                                                                                                                                                                                       |
| int       | [MSR\_Activate](#a1e92fd29720fecbf50da24a30c7b512f) ([MSR\_Callback](#a612917ffe22ec9bedebfad13038d28fd) cbf, void \*cb\_data)                                                                                                                                                                                                                                                                                                                                    |
| int       | [MSR\_Deactivate](#aac28b2c3771f8221fc26a35f0fd6d0f8) (void)                                                                                                                                                                                                                                                                                                                                                                                                      |
| int       | [MSR\_DataAvailable](#a8096fa193f035eb4b80673260d720477) (void)                                                                                                                                                                                                                                                                                                                                                                                                   |
| int       | [MSR\_GetData](#ad00fdde838f486d43be689650ab58d43) (int timeout\_msec, [MSR\_TrackData](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___track_data) \*tracks, [MSR\_DecodedData](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___decoded_data) \*data)      |
| int       | [MSR\_GetData2](#a1bf2f70013c79b94a09b3504607a0667) (int timeout\_msec, [MSR\_TrackData2](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___track_data2) \*tracks, [MSR\_DecodedData](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___decoded_data) \*data)   |
| int       | [MSR\_GetData3](#ab2415e817a7d2a1189897757485ff660) (int timeout\_msec, [MSR\_TrackData3](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___track_data3) \*tracks, [MSR\_DecodedData](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___decoded_data) \*data)   |
| int       | [MSR\_GetData4](#a7436a0f6d88d3eb717c10025325b47e8) (int timeout\_msec, [MSR\_TrackData4](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___track_data4) \*tracks, [MSR\_DecodedData4](/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr__common_8h.md#struct_m_s_r___decoded_data4) \*data) |
| void      | [MSR\_AbortGetData](#a70fedc4ea5687982f39102e2738d8ef5) (void)                                                                                                                                                                                                                                                                                                                                                                                                    |
| int       | [MSR\_SwitchLeds](#abca7e8953c8430d80f51c867c7699fa6) (int led1, int led2, int led3, int duration)                                                                                                                                                                                                                                                                                                                                                                |

### DetailedDescription <a href="#detailed-description" id="detailed-description"></a>

Interface definitions for libmsr. This file defines the API for the magnetic card reader library.

#### Author

Thomas Buening, GSS

Interface definitions for libmsr - part which is common for direct linking and client/server. This file defines the API for the magnetic card reader library.

#### Author

Dirk Germann, GSS

### TypedefDocumentation <a href="#typedef-documentation" id="typedef-documentation"></a>

### MSR\_Callback <a href="#a612917ffe22ec9bedebfad13038d28fd" id="a612917ffe22ec9bedebfad13038d28fd"></a>

typedef void(\\\* MSR\_Callback) (void \\\*data)

Type of function that is called after magnetic card has been swiped, see [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f).

**Parameters**

\[in] **data** : Data pointer provided by the application.

### FunctionDocumentation <a href="#function-documentation" id="function-documentation"></a>

### MSR\_AbortGetData() <a href="#a70fedc4ea5687982f39102e2738d8ef5" id="a70fedc4ea5687982f39102e2738d8ef5"></a>

void MSR\_AbortGetData

Abort blocking function [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43). If [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) is waiting for a card swipe, the blocking function can be aborted by invoking this function from another thread. If [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) wasn't invoked, this function does nothing.

### MSR\_Activate() <a href="#a1e92fd29720fecbf50da24a30c7b512f" id="a1e92fd29720fecbf50da24a30c7b512f"></a>

int MSR\_Activate

Activate magnetic card reader interface. After successful execution of this function every swiped card is read and its data is stored internally. Upon storing card data any previously stored data is erased, so only the data of the last swiped card remains available. To obtain the stored data, call [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43). After doing so, the stored data is erased as well, so that card data can only be obtained once.

**Parameters**

\[in] **cbf** : Callback function that is called every time a card has been swiped, may be NULL. Within the callback function card data can be obtained by MSR\_GetData(). \[in] **cb\_data** : Data pointer that is passed on to the callback function cbf, may be NULL.

#### Returns

\[unsupported block]

### MSR\_DataAvailable() <a href="#a8096fa193f035eb4b80673260d720477" id="a8096fa193f035eb4b80673260d720477"></a>

int MSR\_DataAvailable

Check if magnetic card has been swiped and its data is stored. After obtaining the stored data with [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) or deactivating the card reader interface with [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) the stored data is erased and not available any longer.

#### Returns

\[unsupported block]

### MSR\_Deactivate() <a href="#aac28b2c3771f8221fc26a35f0fd6d0f8" id="aac28b2c3771f8221fc26a35f0fd6d0f8"></a>

int MSR\_Deactivate

Deactivate magnetic card reader interface. After deactivating the card reader interface no more swiped cards are read and no data is stored. Any previously stored card data will be erased.

{% hint style="info" %}
Calling this function is mandatory at the end of each transaction. Otherwise the internal thread is not correctly ended and resource leaks are remain.
{% endhint %}

#### Returns

\[unsupported block]

### MSR\_GetData() <a href="#ad00fdde838f486d43be689650ab58d43" id="ad00fdde838f486d43be689650ab58d43"></a>

int MSR\_GetData

Obtain magnetic card data. With this function the internally stored card data can be obtained. In doing so, the internally stored data is erased, so that data of each card swipe can only be obtained once. If no card data is stored at the moment, the function waits for a specified time for a card swipe. If a timeout is supplied, the function is blocking and can be aborted by [MSR\_AbortGetData()](#a70fedc4ea5687982f39102e2738d8ef5). If a callback function is supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f), setting a timeout != 0 is not allowed. [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) can be called from within a callback function supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f) but there's no need to do so. Remark: In case the terminal has two magnetic heads the data from the first head is populated. If there is no data from first head the data from the second head is returned. If you need data from both heads you shall use [MSR\_GetData4()](#a7436a0f6d88d3eb717c10025325b47e8).

{% hint style="info" %}
To clear the internal resources a succeeding call to [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) is mandatory.
{% endhint %}

\*\*Parameters\*\*

\[in] **timeout\_msec** : Time (in milliseconds, < 0 : infinite) to wait for a card swipe if no card data has been stored previously. \[out] **tracks** : Track data, may be NULL. \[out] **data** : Decoded track data, may be NULL.

#### Returns

\[unsupported block]

### MSR\_GetData2() <a href="#a1bf2f70013c79b94a09b3504607a0667" id="a1bf2f70013c79b94a09b3504607a0667"></a>

int MSR\_GetData2

Obtain magnetic card data including card type. This is the same as [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) but additionally offers [Card Type Code](/adk-5.0-programmers-guide/readme/modules/group___m_s_r___c_a_r_d___c_o_d_e_s.md). With this function the internally stored card data can be obtained. In doing so, the internally stored data is erased, so that data of each card swipe can only be obtained once. If no card data is stored at the moment, the function waits for a specified time for a card swipe. If a timeout is supplied, the function is blocking and can be aborted by [MSR\_AbortGetData()](#a70fedc4ea5687982f39102e2738d8ef5). If a callback function is supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f), setting a timeout != 0 is not allowed. [MSR\_GetData2()](#a1bf2f70013c79b94a09b3504607a0667) can be called from within a callback function supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f) but there's no need to do so.

{% hint style="info" %}
To clear the internal resources a succeeding call to [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) is mandatory.
{% endhint %}

\*\*Parameters\*\*

\[in] **timeout\_msec** : Time (in milliseconds, < 0 : infinite) to wait for a card swipe if no card data has been stored previously. \[out] **tracks** : Track data, may be NULL. \[out] **data** : Decoded track data, may be NULL.

#### Returns

\[unsupported block]

### MSR\_GetData3() <a href="#ab2415e817a7d2a1189897757485ff660" id="ab2415e817a7d2a1189897757485ff660"></a>

int MSR\_GetData3

Obtain magnetic card data including additional information. This is the same as [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) but additionally offers [Card Type Code](/adk-5.0-programmers-guide/readme/modules/group___m_s_r___c_a_r_d___c_o_d_e_s.md) and [Track Type Code](/adk-5.0-programmers-guide/readme/modules/group___m_s_r___t_r_a_c_k___t_y_p_e_s.md). With this function the internally stored card data can be obtained. In doing so, the internally stored data is erased, so that data of each card swipe can only be obtained once. If no card data is stored at the moment, the function waits for a specified time for a card swipe. If a timeout is supplied, the function is blocking and can be aborted by [MSR\_AbortGetData()](#a70fedc4ea5687982f39102e2738d8ef5). If a callback function is supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f), setting a timeout != 0 is not allowed. [MSR\_GetData3()](#ab2415e817a7d2a1189897757485ff660) can be called from within a callback function supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f) but there's no need to do so.

{% hint style="info" %}
To clear the internal resources a succeeding call to [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) is mandatory.
{% endhint %}

\*\*Parameters\*\*

\[in] **timeout\_msec** : Time (in milliseconds, < 0 : infinite) to wait for a card swipe if no card data has been stored previously. \[out] **tracks** : Track data, may be NULL. \[out] **data** : Decoded track data, may be NULL.

#### Returns

\[unsupported block]

### MSR\_GetData4() <a href="#a7436a0f6d88d3eb717c10025325b47e8" id="a7436a0f6d88d3eb717c10025325b47e8"></a>

int MSR\_GetData4

Obtain magnetic card data including additional information. This is the same as [MSR\_GetData()](#ad00fdde838f486d43be689650ab58d43) but additionally offers [Card Type Code](/adk-5.0-programmers-guide/readme/modules/group___m_s_r___c_a_r_d___c_o_d_e_s.md), [Track Type Code](/adk-5.0-programmers-guide/readme/modules/group___m_s_r___t_r_a_c_k___t_y_p_e_s.md) and second magstripe data (if present). With this function the internally stored card data can be obtained. In doing so, the internally stored data is erased, so that data of each card swipe can only be obtained once. If no card data is stored at the moment, the function waits for a specified time for a card swipe. If a timeout is supplied, the function is blocking and can be aborted by [MSR\_AbortGetData()](#a70fedc4ea5687982f39102e2738d8ef5). If a callback function is supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f), setting a timeout != 0 is not allowed. [MSR\_GetData4()](#a7436a0f6d88d3eb717c10025325b47e8) can be called from within a callback function supplied to [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f) but there's no need to do so.

{% hint style="info" %}
To clear the internal resources a succeeding call to [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) is mandatory.
{% endhint %}

\*\*Parameters\*\*

\[in] **timeout\_msec** : Time (in milliseconds, < 0 : infinite) to wait for a card swipe if no card data has been stored previously. \[out] **tracks** : Track data, may be NULL. \[out] **data** : Decoded track data, may be NULL.

#### Returns

\[unsupported block]

### MSR\_SetOptions() <a href="#ac3c6f568aa57690a8b369936fc362c2a" id="ac3c6f568aa57690a8b369936fc362c2a"></a>

int MSR\_SetOptions

This function has to be called while MSR is *deactivated*. [MSR\_Activate()](#a1e92fd29720fecbf50da24a30c7b512f) / [MSR\_Deactivate()](#aac28b2c3771f8221fc26a35f0fd6d0f8) do not discard the options previously set, so setting the options once at terminal start is sufficient. Note: Options not overwritten by options\_len remain unchanged.

**Parameters**

\[in] **options** : data pointer, \[0]-\[2] Options bitmask, \[3] sensitivity (for Samsung MST usage, values 0-100, 0xFF = don't set) \[in] **options\_len** : length of options

#### Returns

\[unsupported block]

### MSR\_SwitchLeds() <a href="#abca7e8953c8430d80f51c867c7699fa6" id="abca7e8953c8430d80f51c867c7699fa6"></a>

int MSR\_SwitchLeds

Set state of MSR LEDs.

**Parameters**

\[in] **led1** : state of LED 1 (top), see LED states. \[in] **led2** : state of LED 2 (mid), see LED states \[in] **led3** : state of LED 3 (bottom), see LED states \[in] **duration** : if > 0: all LEDs are switched off after this time (in seconds).

#### Returns

\[unsupported block]


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/readme/files/dir_b259c67979486db4cd1816234700c14a/dir_699851f087f6e6136e28f04fc8a16e7d/msr_8h.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
