예제 #1
0
static PyObject *
Reader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    Reader *self;
    char *deviceUri;
    int baudRate = 0;
    TMR_Status ret;

    static char *kwlist[] = {"uri", "baudrate", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwlist, &deviceUri, &baudRate))
        return NULL;

    self = (Reader *)type->tp_alloc(type, 0);
    if (self == NULL)
        return NULL;

    if ((ret = TMR_create(&self->reader, deviceUri)) != TMR_SUCCESS)
        goto fail;

    if (baudRate > 0)
    {
        if ((ret = TMR_paramSet(&self->reader, TMR_PARAM_BAUDRATE, &baudRate)) != TMR_SUCCESS)
            goto fail;
    }

    /* install the callback wrapper for asynchronous reading */
    self->readListener.listener = invoke_read_callback;
    self->readListener.cookie = self;
    if ((ret = TMR_addReadListener(&self->reader, &self->readListener)) != TMR_SUCCESS)
        goto fail;

    if ((ret = TMR_connect(&self->reader)) != TMR_SUCCESS)
        goto fail;

    return (PyObject *)self;
fail:
    PyErr_SetString(PyExc_TypeError, TMR_strerr(&self->reader, ret));
    Py_TYPE(self)->tp_free((PyObject*)self);
    return NULL;
}
예제 #2
0
void setupReader(char *arg)
{
  rp = &r;
  ret = TMR_create(rp, arg);
  region =  TMR_REGION_NA;
  ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
  if (TMR_READER_TYPE_SERIAL == rp->readerType)
    tlb.listener = serialPrinter;
  else
    tlb.listener = stringPrinter;
  tlb.cookie = stdout;
#if 0
  TMR_addTransportListener(rp, &tlb);
#endif
  ret = TMR_connect(rp);
  rlb.listener = callback;
  rlb.cookie = NULL;
  reb.listener = exceptionCallback;
  reb.cookie = NULL;
  ret = TMR_addReadListener(rp, &rlb);
  ret = TMR_addReadExceptionListener(rp, &reb);
}
예제 #3
0
int main(int argc, char *argv[])
{

#ifndef TMR_ENABLE_BACKGROUND_READS
  errx(1, "This sample requires background read functionality.\n"
          "Please enable TMR_ENABLE_BACKGROUND_READS in tm_config.h\n"
          "to run this codelet\n");
  return -1;
#else

  TMR_Reader r, *rp;
  TMR_Status ret;
  TMR_Region region;
#if USE_TRANSPORT_LISTENER
  TMR_TransportListenerBlock tb;
#endif
  TMR_ReadListenerBlock rlb;
  TMR_ReadExceptionListenerBlock reb;
  TMR_StatsListenerBlock slb;
 
  if (argc < 2)
  {
    errx(1, "Please provide reader URL, such as:\n"
        "tmr:///com4\n"
        "tmr://my-reader.example.com\n");
  }

  rp = &r;
  ret = TMR_create(rp, argv[1]);
  checkerr(rp, ret, 1, "creating reader");

#if USE_TRANSPORT_LISTENER

  if (TMR_READER_TYPE_SERIAL == rp->readerType)
  {
    tb.listener = serialPrinter;
  }
  else
  {
    tb.listener = stringPrinter;
  }
  tb.cookie = stdout;

  TMR_addTransportListener(rp, &tb);
#endif

  ret = TMR_connect(rp);
  checkerr(rp, ret, 1, "connecting reader");

  region = TMR_REGION_NONE;
  ret = TMR_paramGet(rp, TMR_PARAM_REGION_ID, &region);
  checkerr(rp, ret, 1, "getting region");

  if (TMR_REGION_NONE == region)
  {
    TMR_RegionList regions;
    TMR_Region _regionStore[32];
    regions.list = _regionStore;
    regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
    regions.len = 0;

    ret = TMR_paramGet(rp, TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions);
    checkerr(rp, ret, __LINE__, "getting supported regions");

    if (regions.len < 1)
    {
      checkerr(rp, TMR_ERROR_INVALID_REGION, __LINE__, "Reader doesn't supportany regions");
    }
    region = regions.list[0];
    ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
    checkerr(rp, ret, 1, "setting region");  
  }

  {
    /* Code to get the reader stats after the sync read */
    TMR_Reader_StatsValues stats;
    TMR_Reader_StatsFlag setFlag;
    TMR_PortValueList value;
    TMR_PortValue valueList[64];
    int i, j;

    printf("\nReader stats after the sync read\n");

    /** request for the statics fields of your interest, before search */
    setFlag = TMR_READER_STATS_FLAG_ALL;
    value.max = sizeof(valueList)/sizeof(valueList[0]);
    value.list = valueList;

    ret = TMR_paramSet(rp, TMR_PARAM_READER_STATS_ENABLE, &setFlag);
    checkerr(rp, ret, 1, "setting the  fields");

    for (j = 1; j < 4; j++)
    {
      /**
       * perform three iterations to see that reader stats are
       * resetting after each search operation.
       **/ 
      printf("\nIteration:%d\n", j);
      /**
       * performing the search operation. for 1 sec,
       * Individual search will reset the reader stats, before doing the search
       */
      printf("Performing the search operation. for 1 sec\n");
      ret = TMR_read(rp, 1000, NULL);
      checkerr(rp, ret, 1, "reading tags");

      /** Initialize the reader statics variable to default values */
      TMR_STATS_init(&stats);

      /* Search is completed. Get the reader stats */
      printf("Search is completed. Get the reader stats\n");
      ret = TMR_paramGet(rp, TMR_PARAM_READER_STATS, &stats);
      checkerr(rp, ret, 1, "getting the reader statistics");

      /** Each  field should be validated before extracting the value */
      if (TMR_READER_STATS_FLAG_CONNECTED_ANTENNAS & stats.valid)
      {
        printf("Antenna Connection Status\n");
        for (i = 0; i < stats.connectedAntennas.len; i += 2)
        {
          printf("Antenna %d |%s\n", stats.connectedAntennas.list[i],
              stats.connectedAntennas.list[i + 1] ? "connected":"Disconnected");
        }
      }

      /* Get the antenna return loss value, this parameter is not the part of reader stats */
      ret = TMR_paramGet(rp, TMR_PARAM_ANTENNA_RETURNLOSS, &value);
      checkerr(rp, ret, 1, "getting the antenna return loss");
      printf("Antenna Return Loss\n");
      for (i = 0; i < value.len && i < value.max; i++)
      {
        printf("Antenna %d | %d \n", value.list[i].port, value.list[i].value);
      }

      if (TMR_READER_STATS_FLAG_NOISE_FLOOR_SEARCH_RX_TX_WITH_TX_ON & stats.valid)
      {
        printf("Noise Floor With Tx On\n");
        for (i = 0; i < stats.perAntenna.len; i++)
        {
          printf("Antenna %d | %d db\n", stats.perAntenna.list[i].antenna, stats.perAntenna.list[i].noiseFloor);
        }
      }

      if (TMR_READER_STATS_FLAG_RF_ON_TIME & stats.valid)
      {
        printf("RF On Time\n");
        for (i = 0; i < stats.perAntenna.len; i++)
        {
          printf("Antenna %d | %d ms\n", stats.perAntenna.list[i].antenna, stats.perAntenna.list[i].rfOnTime);
        }
      }

      if (TMR_READER_STATS_FLAG_FREQUENCY & stats.valid)
      {
        printf("Frequency %d(khz)\n", stats.frequency);
      }
      if (TMR_READER_STATS_FLAG_TEMPERATURE & stats.valid)
      {
        printf("Temperature %d(C)\n", stats.temperature);
      }
      if (TMR_READER_STATS_FLAG_PROTOCOL & stats.valid)
      {
        printf("Protocol %s\n", protocolName(stats.protocol));
      }
      if (TMR_READER_STATS_FLAG_ANTENNA_PORTS & stats.valid)
      {
        printf("currentAntenna %d\n", stats.antenna);
      }
    }
  }

  {
    /* Code to get the reader stats after the async read */
    TMR_Reader_StatsFlag setFlag = TMR_READER_STATS_FLAG_ALL;

    rlb.listener = callback;
    rlb.cookie = NULL;

    reb.listener = exceptionCallback;
    reb.cookie = NULL;

    slb.listener = statsCallback;
    slb.cookie = NULL;

    ret = TMR_addReadListener(rp, &rlb);
    checkerr(rp, ret, 1, "adding read listener");

    ret = TMR_addReadExceptionListener(rp, &reb);
    checkerr(rp, ret, 1, "adding exception listener");

    ret = TMR_addStatsListener(rp, &slb);
    checkerr(rp, ret, 1, "adding the stats listener");

    printf("\nReader stats after the async read \n");

    /** request for the statics fields of your interest, before search */
    ret = TMR_paramSet(rp, TMR_PARAM_READER_STATS_ENABLE, &setFlag);
    checkerr(rp, ret, 1, "setting the  fields");

    printf("Initiating the search operation. for 1 sec and the listener will provide the reader stats\n");

    ret = TMR_startReading(rp);
    checkerr(rp, ret, 1, "starting reading");

#ifndef WIN32
    sleep(1);
#else
    Sleep(1000);
#endif

    ret = TMR_stopReading(rp);
    checkerr(rp, ret, 1, "stopping reading");
  }

  TMR_destroy(rp);
  return 0;
#endif /* TMR_ENABLE_BACKGROUND_READS */
}
예제 #4
0
int main(int argc, char *argv[])
{
  TMR_Reader r, *rp;
  TMR_Status ret;
  TMR_Region region;
#if USE_TRANSPORT_LISTENER
  TMR_TransportListenerBlock tb;
#endif
 
  if (argc < 2)
  {
    errx(1, "Please provide reader URL, such as:\n"
           "tmr:///com4\n"
           "tmr://my-reader.example.com\n");
  }
  
  rp = &r;
  ret = TMR_create(rp, argv[1]);
  checkerr(rp, ret, 1, "creating reader");

#if USE_TRANSPORT_LISTENER

  if (TMR_READER_TYPE_SERIAL == rp->readerType)
  {
    tb.listener = serialPrinter;
  }
  else
  {
    tb.listener = stringPrinter;
  }
  tb.cookie = stdout;

  TMR_addTransportListener(rp, &tb);
#endif

  ret = TMR_connect(rp);
  checkerr(rp, ret, 1, "connecting reader");

  region = TMR_REGION_NONE;
  ret = TMR_paramGet(rp, TMR_PARAM_REGION_ID, &region);
  checkerr(rp, ret, 1, "getting region");

  if (TMR_REGION_NONE == region)
  {
    TMR_RegionList regions;
    TMR_Region _regionStore[32];
    regions.list = _regionStore;
    regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
    regions.len = 0;

    ret = TMR_paramGet(rp, TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions);
    checkerr(rp, ret, __LINE__, "getting supported regions");

    if (regions.len < 1)
    {
      checkerr(rp, TMR_ERROR_INVALID_REGION, __LINE__, "Reader doesn't supportany regions");
    }
    region = regions.list[0];
    ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
    checkerr(rp, ret, 1, "setting region");  
  }

  {
    uint16_t retryCount = 1;
    /**
     * Power cycle the reader. Calling TMR_reboot() will do that.
     **/
    ret = TMR_reboot(rp);
    checkerr(rp, ret, 1, "power cycling reader");

    /**
     * power cycle will take some time to complete.
     * 1. Fixed reader  : approximately 90sec.
     * 2. Serial reader : approximately 250ms.
     *
     * till then try to reconnect the reader.
     **/
    printf("The reader is being rebooted. Once it has finished, it will reconnect ....\n");

    //reconnect to the reader
    TMR_destroy(rp);
    ret = TMR_create(rp, argv[1]);

    do
    {
      printf("Trying to reconnect.... Attempt:%d\n", retryCount);
      ret = TMR_connect(rp);
      if (TMR_SUCCESS == ret)
      {
        /* reader reconnected */
        break;
      }
      retryCount++;
    }while(true);

    printf("Reader is reconnected successfully\n");
  }

  TMR_destroy(rp);
  return 0;
}
예제 #5
0
int main(int argc, char *argv[])
{
  TMR_Reader r, *rp;
  TMR_Status ret;
  TMR_Region region;
#if USE_TRANSPORT_LISTENER
  TMR_TransportListenerBlock tb;
#endif

  if (argc < 2)
  {
    errx(1, "Please provide reader URL, such as:\n"
           "tmr:///com4\n"
           "tmr://my-reader.example.com\n");
  }
  
  rp = &r;
  ret = TMR_create(rp, argv[1]);
  checkerr(rp, ret, 1, "creating reader");

#if USE_TRANSPORT_LISTENER

  if (TMR_READER_TYPE_SERIAL == rp->readerType)
  {
    tb.listener = serialPrinter;
  }
  else
  {
    tb.listener = stringPrinter;
  }
  tb.cookie = stdout;

  TMR_addTransportListener(rp, &tb);
#endif

  ret = TMR_connect(rp);
  checkerr(rp, ret, 1, "connecting reader");

  region = TMR_REGION_NONE;
  ret = TMR_paramGet(rp, TMR_PARAM_REGION_ID, &region);
  checkerr(rp, ret, 1, "getting region");

  if (TMR_REGION_NONE == region)
  {
    TMR_RegionList regions;
    TMR_Region _regionStore[32];
    regions.list = _regionStore;
    regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
    regions.len = 0;

    ret = TMR_paramGet(rp, TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions);
    checkerr(rp, ret, __LINE__, "getting supported regions");

    if (regions.len < 1)
    {
      checkerr(rp, TMR_ERROR_INVALID_REGION, __LINE__, "Reader doesn't supportany regions");
    }
    region = regions.list[0];
    ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
    checkerr(rp, ret, 1, "setting region");  
  }

{
  TMR_ReadPlan simpleReadPlan, multiReadPlan;
  TMR_ReadPlan subplans[5];
  TMR_ReadPlan* subplanPtrs[5];
  TMR_TagProtocolList value;
  TMR_TagProtocol valueList[32];
  int subplanCount = 0;
  int j;
  TMR_SR_GEN2_Q qValue;
  uint8_t antenna[] = {1};
  uint32_t tagCount = 1;

  /* Initial test setup */
  /* Set the Q value as per the tag population */
  qValue.type = TMR_SR_GEN2_Q_STATIC;
  qValue.u.staticQ.initialQ = 0;

  ret = TMR_paramSet(rp, TMR_PARAM_GEN2_Q, &qValue);
  checkerr(rp, ret, 1, "setting the Q Value");  

  /* The simple read plan */
  TMR_RP_init_simple (&simpleReadPlan, 1, antenna, TMR_TAG_PROTOCOL_GEN2, 1000);

  /* Stop N trigger */
  TMR_RP_set_stopTrigger (&simpleReadPlan, tagCount);

  /* The multi read plan */
  {

    value.max = 32;
    value.list = valueList;

    /* Berfore setting the readplen, we must get list of supported protocols */
    ret = TMR_paramGet(rp, TMR_PARAM_VERSION_SUPPORTEDPROTOCOLS, &value);
    checkerr(rp, ret, 1, "Getting the supported protocols");

    {
      ret = TMR_RP_init_simple(&subplans[subplanCount], 1, antenna,TMR_TAG_PROTOCOL_GEN2 , 1000);
      TMR_RP_set_stopTrigger (&subplans[subplanCount], tagCount);
      subplanCount++;
      ret = TMR_RP_init_simple(&subplans[subplanCount], 1, antenna, TMR_TAG_PROTOCOL_ISO180006B, 1000);
      TMR_RP_set_stopTrigger (&subplans[subplanCount], tagCount);
      subplanCount++;

    }

    for (j = 0; j < subplanCount; j++)
    {
      subplanPtrs[j] = &subplans[j];
    }

    TMR_RP_init_multi(&multiReadPlan, subplanPtrs, subplanCount, 0);
  }

  /* Set the read plan */
   ret = TMR_paramSet(rp, TMR_PARAM_READ_PLAN, &simpleReadPlan);
  //enable this for multi read plan
  //ret = TMR_paramSet(rp, TMR_PARAM_READ_PLAN, &multiReadPlan);
  checkerr(rp, ret, 1, "setting read plan");

    /* The sync read */
  {
    ret = TMR_read(rp, 1000, NULL);
    checkerr(rp, ret, 1, "reading tags");

    while (TMR_SUCCESS == TMR_hasMoreTags(rp))
    {
      TMR_TagReadData trd;
      char epcStr[128];

      ret = TMR_getNextTag(rp, &trd);
      checkerr(rp, ret, 1, "fetching tag");

      TMR_bytesToHex(trd.tag.epc, trd.tag.epcByteCount, epcStr);
      printf("EPC:%s\n", epcStr);
    }
  }
}

TMR_destroy(rp);
return 0;
}
int main(int argc, char *argv[])
{

#ifndef TMR_ENABLE_BACKGROUND_READS
  errx(1, "This sample requires background read functionality.\n"
          "Please enable TMR_ENABLE_BACKGROUND_READS in tm_config.h\n"
          "to run this codelet\n");
  return -1;
#else

  TMR_Reader r, *rp;
  TMR_Status ret;
  TMR_Region region;
  TMR_ReadListenerBlock rlb;
  TMR_ReadExceptionListenerBlock reb;
#if USE_TRANSPORT_LISTENER
  TMR_TransportListenerBlock tb;
#endif

  if (argc < 2)
  {
    errx(1, "Please provide reader URL, such as:\n"
           "tmr:///com4\n"
           "tmr://my-reader.example.com\n");
  }
  
  rp = &r;
  ret = TMR_create(rp, argv[1]);
  checkerr(rp, ret, 1, "creating reader");

#if USE_TRANSPORT_LISTENER

  if (TMR_READER_TYPE_SERIAL == rp->readerType)
  {
    tb.listener = serialPrinter;
  }
  else
  {
    tb.listener = stringPrinter;
  }
  tb.cookie = stdout;

  TMR_addTransportListener(rp, &tb);
#endif

  ret = TMR_connect(rp);
  checkerr(rp, ret, 1, "connecting reader");

  region = TMR_REGION_NONE;
  ret = TMR_paramGet(rp, TMR_PARAM_REGION_ID, &region);
  checkerr(rp, ret, 1, "getting region");

  if (TMR_REGION_NONE == region)
  {
    TMR_RegionList regions;
    TMR_Region _regionStore[32];
    regions.list = _regionStore;
    regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
    regions.len = 0;

    ret = TMR_paramGet(rp, TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions);
    checkerr(rp, ret, __LINE__, "getting supported regions");

    if (regions.len < 1)
    {
      checkerr(rp, TMR_ERROR_INVALID_REGION, __LINE__, "Reader doesn't supportany regions");
    }
    region = regions.list[0];
    ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
    checkerr(rp, ret, 1, "setting region");  
  }

  rlb.listener = callback;
  rlb.cookie = NULL;

  reb.listener = exceptionCallback;
  reb.cookie = NULL;

  ret = TMR_addReadListener(rp, &rlb);
  checkerr(rp, ret, 1, "adding read listener");

  ret = TMR_addReadExceptionListener(rp, &reb);
  checkerr(rp, ret, 1, "adding exception listener");

  {
    TMR_ReadPlan plan;
    TMR_TagFilter filter;
    TMR_ISO180006B_Delimiter delimiter;
    uint8_t wordData[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };

    /* Set the Delimiter to 1 */
    delimiter = TMR_ISO180006B_Delimiter1;
    ret = TMR_paramSet(rp, TMR_PARAM_ISO180006B_DELIMITER, &delimiter);
    checkerr(rp, ret, 1, "setting the delimiter");

    /* Read Plan */
    TMR_RP_init_simple(&plan, 0, NULL, TMR_TAG_PROTOCOL_ISO180006B, 1000);
    TMR_TF_init_ISO180006B_select(&filter, false, TMR_ISO180006B_SELECT_OP_NOT_EQUALS, 0, 0xff, wordData);

    /* Commit read plan */
    ret = TMR_RP_set_filter(&plan, &filter);
    checkerr(rp, ret, 1, "setting filter to the read plan");
    ret = TMR_paramSet(rp, TMR_PARAM_READ_PLAN, &plan);
    checkerr(rp, ret, 1, "setting read plan");
  }

  ret = TMR_startReading(rp);
  checkerr(rp, ret, 1, "starting reading");

#ifndef WIN32
  sleep(5);
#else
  Sleep(5000);
#endif

  ret = TMR_stopReading(rp);
  checkerr(rp, ret, 1, "stopping reading");

  TMR_destroy(rp);
  return 0;

#endif /* TMR_ENABLE_BACKGROUND_READS */
}
예제 #7
0
int RFIDstartReader(const char* deviceURI)
{
	readers = realloc(readers, (readerCount + 1) * sizeof(TMR_Reader*));
	TMR_Reader* pr = malloc(sizeof(TMR_Reader));
	readers[readerCount] = pr;

	plan = realloc(plan, (readerCount + 1) * sizeof(TMR_ReadPlan*));
	TMR_ReadPlan* prp = malloc(sizeof(TMR_ReadPlan));
	plan[readerCount] = prp;

	rlb = realloc(rlb, (readerCount + 1) * sizeof(TMR_ReadListenerBlock*));
	TMR_ReadListenerBlock* prlb = malloc(sizeof(TMR_ReadListenerBlock));
	rlb[readerCount] = prlb;

	reb = realloc(reb, (readerCount + 1) * sizeof(TMR_ReadExceptionListenerBlock*));
	TMR_ReadExceptionListenerBlock* preb = malloc(sizeof(TMR_ReadExceptionListenerBlock));
	reb[readerCount] = preb;

	region = realloc(region, (readerCount + 1) * sizeof(TMR_Region*));
	TMR_Region* preg = malloc(sizeof(TMR_Region));
	region[readerCount] = preg;

	status = realloc(status, (readerCount + 1) * sizeof(TMR_Status*));
	TMR_Status* pstat = malloc(sizeof(TMR_Status));
	status[readerCount] = pstat;

	model = realloc(model, (readerCount + 1) * sizeof(TMR_String*));
	TMR_String* pstr = malloc(sizeof(TMR_String));
	model[readerCount] = pstr;

	if(checkError(TMR_create(readers[readerCount], deviceURI), "Creating reader"))
	{
		return -1;
	}
	if(checkError(TMR_connect(readers[readerCount]), "Connecting to reader"))
	{
		return -1;
	}

	*(region[readerCount]) = TMR_REGION_NONE;
	if(checkError(TMR_paramGet(readers[readerCount], TMR_PARAM_REGION_ID, region[readerCount]), "Getting Saved Region"))
	{
		return -1;
	}

	if(*(region[readerCount]) == TMR_REGION_NONE)
	{
		printf("No saved regions\n");

		TMR_RegionList regions;
		TMR_Region _regionStore[32];
		regions.list = _regionStore;
		regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
		regions.len = 0;

		if(checkError(TMR_paramGet(readers[readerCount], TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions), "Getting List of Regions"))
		{
			return -1;
		}

		if(regions.len < 1)
		{
			printf("Reader doesn't support any regions\n");
			return -1;
		}

		*(region[readerCount]) = regions.list[0];
		if(checkError(TMR_paramSet(readers[readerCount], TMR_PARAM_REGION_ID, &*(region[readerCount])), "Setting region"))
		{
			return -1;
		}
	}

	if(checkError(TMR_RP_init_simple(plan[readerCount], 0x0, NULL, TMR_TAG_PROTOCOL_GEN2, 1000), "Initialising read plan"))
	{
		return -1;
	}

	if(checkError(TMR_paramSet(readers[readerCount], TMR_PARAM_READ_PLAN, plan[readerCount]), "Setting Read Plan"))
	{
		return -1;
	}

	rlb[readerCount]->listener = tagCallback;
	rlb[readerCount]->cookie = NULL;

	reb[readerCount]->listener = exceptionCallback;
	reb[readerCount]->cookie = NULL;

	if(checkError(TMR_addReadListener(readers[readerCount], rlb[readerCount]), "Adding read listener"))
	{
		return -1;
	}

	if(checkError(TMR_addReadExceptionListener(readers[readerCount], reb[readerCount]), "Adding Exception Listener"))
	{
		return -1;
	}

	if(checkError(TMR_startReading(readers[readerCount]), "Starting reader"))
	{
		return -1;
	}

	uniqueReaderInstance++;

	return (uniqueReaderInstance - 1);
}
예제 #8
0
int main(int argc, char *argv[])
{

#ifndef TMR_ENABLE_BACKGROUND_READS
  errx(1, "This sample requires background read functionality.\n"
          "Please enable TMR_ENABLE_BACKGROUND_READS in tm_config.h\n"
          "to run this codelet\n");
  return -1;
#else

  TMR_Reader r, *rp;
  TMR_Status ret;
  TMR_Region region;
#if USE_TRANSPORT_LISTENER
  TMR_TransportListenerBlock tb;
#endif
  TMR_ReadListenerBlock rlb;
  TMR_ReadExceptionListenerBlock reb;
 
  if (argc < 2)
  {
    errx(1, "Please provide reader URL, such as:\n"
        "customschemename://readerIP:portname\n");
  }

  rp = &r;

  /**
   * Add the custom transport scheme before calling TMR_create().
   * This can be done by using C API helper function TMR_setSerialTransport().
   * It accepts two arguments. scheme and nativeInit.
   * scheme: the custom transport scheme name. For demonstration using scheme as "tcp".
   * nativeInit: reference to the transport factory init function.
   */
  ret = TMR_setSerialTransport("tcp", &TMR_SR_SerialTransportTcpNativeInit);
  checkerr(rp, ret, 1, "adding the custom transport scheme");

  ret = TMR_create(rp, argv[1]);
  checkerr(rp, ret, 1, "creating reader");

#if USE_TRANSPORT_LISTENER

  if (TMR_READER_TYPE_SERIAL == rp->readerType)
  {
    tb.listener = serialPrinter;
  }
  else
  {
    tb.listener = stringPrinter;
  }
  tb.cookie = stdout;

  TMR_addTransportListener(rp, &tb);
#endif

  ret = TMR_connect(rp);
  checkerr(rp, ret, 1, "connecting reader");

  region = TMR_REGION_NONE;
  ret = TMR_paramGet(rp, TMR_PARAM_REGION_ID, &region);
  checkerr(rp, ret, 1, "getting region");

  if (TMR_REGION_NONE == region)
  {
    TMR_RegionList regions;
    TMR_Region _regionStore[32];
    regions.list = _regionStore;
    regions.max = sizeof(_regionStore)/sizeof(_regionStore[0]);
    regions.len = 0;

    ret = TMR_paramGet(rp, TMR_PARAM_REGION_SUPPORTEDREGIONS, &regions);
    checkerr(rp, ret, __LINE__, "getting supported regions");

    if (regions.len < 1)
    {
      checkerr(rp, TMR_ERROR_INVALID_REGION, __LINE__, "Reader doesn't supportany regions");
    }
    region = regions.list[0];
    ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, &region);
    checkerr(rp, ret, 1, "setting region");  
  }

  {
    /* Initiate a sync read */
    printf("\nDoing a sync read for 1sec duration\n");
    ret = TMR_read(rp, 1000, NULL);
    if (TMR_SUCCESS != ret)
    {
      fprintf(stderr, "Error reading tags: %s\n", TMR_strerr(rp, ret));
      /* Don't exit, tags might still have been read before the error occurred. */
    }

    while (TMR_SUCCESS == TMR_hasMoreTags(rp))
    {
      TMR_TagReadData trd;
      char epcStr[128];

      ret = TMR_getNextTag(rp, &trd);
      checkerr(rp, ret, 1, "fetching tag");

      TMR_bytesToHex(trd.tag.epc, trd.tag.epcByteCount, epcStr);
      printf("Background read: %s Protocol:%0x \n", epcStr, trd.tag.protocol);
    }
  }

  {
    /* Initiate an async read */
    printf("\nDoing an async read for 1sec duration\n");

    rlb.listener = callback;
    rlb.cookie = NULL;

    reb.listener = exceptionCallback;
    reb.cookie = NULL;

    ret = TMR_addReadListener(rp, &rlb);
    checkerr(rp, ret, 1, "adding read listener");

    ret = TMR_addReadExceptionListener(rp, &reb);
    checkerr(rp, ret, 1, "adding exception listener");

    ret = TMR_startReading(rp);
    checkerr(rp, ret, 1, "starting reading");

    tmr_sleep(1000);

    ret = TMR_stopReading(rp);
    checkerr(rp, ret, 1, "stopping reading");
  }

  TMR_destroy(rp);
  return 0;
#endif /* TMR_ENABLE_BACKGROUND_READS */
}