beautypg.com

C language features, C read iterator – ThingMagic Mercury API v1.23.0 User Manual

Page 96

background image

C Language Features

96

C Language Interface

C Language Features

For clarity of definition, C99 datatypes (bool, uintN_t) are used. If these types are not
defined on the target platform, a substitute typedef for bool can be define, but a custom
stdint.h must be created to define specific integer sizes in terms of the target
environment.

Types with multiple fields to set, such as TMR_ReadPlan or TMR_Filter, have constructor
macros, such as TMR_RP_init_simple() to set the fields of the structure compactly and
conviently

C Read Iterator

To avoid dynamically allocating large buffers, the

TMR_read function doesn't

automatically create a list of

TMR_TagReadData. Instead, you must repeatedly call

TMR_hasMoreTags(reader) and TMR_getNextTag(reader, &tagread) to
extract tag reads from the module.

TMR_Status err = TMR_read(reader, timeout, &tagCount);

if (TMR_SUCCESS != err) { FAIL(err); }

while (TMR_SUCCESS == TMR_hasMoreTags(reader))

{TMR_TagReadData trd;

err = TMR_getNextTag(reader, &trd);

if (TMR_SUCCESS != err) { FAIL(err); }

}

If dynamic memory allocation can be used, a convenience method is provided called
TMR_readIntoArray()

TMR_TagReadData* tagReads;

TMR_Status err = TMR_read(reader, timeout, &tagCount;

if (TMR_SUCCESS != err) { FAIL(err); }

TMR_readIntoArray(reader, timeout, &tagCount, &tagReads)

while (TMR_SUCCESS == TMR_hasMoreTags(reader))

{TMR_TagReadData trd;

err = TMR_getNextTag(reader, &trd);

if (TMR_SUCCESS != err) { FAIL(err); }

}