Device object

Device object — Basic methods to create and use devices.

Functions

Types and Values

typedef mccr_device_t

Description

This section defines the MCCR device type as well as methods to create and use them.

Example 2. Opening and closing the device

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mccr_status_t  st;
mccr_device_t *device;

device = mccr_device_new (NULL);
if (!device) {
  fprintf (stderr, "error: couldn't find a MagTek credit card reader\n");
  return EXIT_FAILURE;
}

if ((st = mccr_device_open (device)) != MCCR_STATUS_OK) {
  fprintf (stderr, "error: couldn't open MagTek credit card reader: %s\n", mccr_status_to_string (st));
  return EXIT_FAILURE;
}

// Use the device here

mccr_device_close (device);
mccr_device_unref (device);

Functions

mccr_enumerate_devices ()

mccr_device_t **
mccr_enumerate_devices (void);

Enumerates all available MagTek credit card reader devices.

Returns

a newly allocated NULL-terminated array of mccr_device_t instances or NULL if no devices found. When no longer needed, mccr_device_unref() should be called on each mccr_device_t in the array, and free() for the array itself.


mccr_device_new ()

mccr_device_t *
mccr_device_new (const char *path);

Creates a mccr_device_t from the given path. There is no predefined format for the path, the user should use a path previously returned by mccr_enumerate_devices().

If a NULL path is given, the mccr_device_t is created from the first device found.

Parameters

path

the enumerated path that identifies this device.

 

Returns

a new mccr_device_t reference.


mccr_device_ref ()

mccr_device_t *
mccr_device_ref (mccr_device_t *device);

Increases the reference count on the mccr_device_t.

Parameters

device

a mccr_device_t.

 

Returns

a new mccr_device_t reference.


mccr_device_unref ()

void
mccr_device_unref (mccr_device_t *device);

Decreases the reference count on the mccr_device_t. When the count reaches zero, the instance is disposed.

Parameters

device

a mccr_device_t.

 

mccr_device_get_path ()

const char *
mccr_device_get_path (mccr_device_t *device);

Get USB path of the device.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a constant string.


mccr_device_get_vid ()

uint16_t
mccr_device_get_vid (mccr_device_t *device);

Get the USB vendor ID.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a uint16_t.


mccr_device_get_pid ()

uint16_t
mccr_device_get_pid (mccr_device_t *device);

Get the USB product ID.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a uint16_t.


mccr_device_get_serial_number ()

const wchar_t *
mccr_device_get_serial_number (mccr_device_t *device);

Get the serial number of the device.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a wide-character constant string.


mccr_device_get_manufacturer ()

const wchar_t *
mccr_device_get_manufacturer (mccr_device_t *device);

Get the manufacturer string of the device.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a wide-character constant string.


mccr_device_get_product ()

const wchar_t *
mccr_device_get_product (mccr_device_t *device);

Get the product string of the device.

This method doesn't require the device to be open previously with mccr_device_open().

Parameters

device

a mccr_device_t.

 

Returns

a wide-character constant string.


mccr_device_open ()

mccr_status_t
mccr_device_open (mccr_device_t *device);

Open the mccr_device_t.

Parameters

device

a mccr_device_t.

 

Returns

a mccr_status_t.


mccr_device_is_open ()

bool
mccr_device_is_open (mccr_device_t *device);

Checks whether the mccr_device_t is open.

Parameters

device

a mccr_device_t.

 

Returns

true if open, false otherwise.


mccr_device_close ()

void
mccr_device_close (mccr_device_t *device);

Close the mccr_device_t.

Parameters

device

a mccr_device_t.

 

mccr_device_reset ()

mccr_status_t
mccr_device_reset (mccr_device_t *device);

Request a power cycle of the mccr_device_t.

Parameters

device

an open mccr_device_t.

 

Returns

a mccr_status_t.

Types and Values

mccr_device_t

typedef struct mccr_device_s mccr_device_t;

This is an opaque type representing a physical MagTek credit card reader device.