示例#1
0
/*----------------------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION:		discoverDevices

DATE:			18/10/2015

INTERFACE:		bool discoverDevices()

RETURNS:		If any of the discover devices/reader API calls fail, false is returned. Otherwise on succession, true is returned.

NOTES:			Calls the SkyeTek API to check if any USB devices are plugged into the host machine. If there are devices found, the 
				next API call is to	look for RFID readers. If the reader happens to be a serial device, the function will get the
				appropriate baud rate. If none of the API calls fail, a succeed dialog box is printed to the console.

------------------------------------------------------------------------------------------------------------------------------------------------------------*/
bool discoverDevices()
{
	MessageBox(NULL, "Connecting to devices...", "Connection Status", MB_OK);

	if (!(numDevices = SkyeTek_DiscoverDevices(&devices)))	// Check for any USB devices, return false if none are found.
	{
		return false;
	}
	if (!(numReaders = SkyeTek_DiscoverReaders(devices, numDevices, &readers)))		//Check for any USB devices, return false if none are found.
	{
		SkyeTek_FreeDevices(devices, numReaders);
		return false;
	}
	st = SkyeTek_GetSystemParameter(readers[0], SYS_BAUD, &lpData);		//Get the baud rate if we have serial communication
	if (st != SKYETEK_SUCCESS)	//Check if getting the baud rate failed
	{
		SkyeTek_FreeReaders(readers, numReaders);
		SkyeTek_FreeDevices(devices, numDevices);
		return false;
	}
	MessageBox(NULL, "Connected!", "Connection Status", MB_OK);
	return true;
}
示例#2
0
int _tmain(int argc, TCHAR* argv[])
{
	LPSKYETEK_DEVICE *devices = NULL;
  LPSKYETEK_READER *readers = NULL;
  LPSKYETEK_DEVICE lpDevice = NULL;
  LPSKYETEK_READER lpReader = NULL;
  LPSKYETEK_DATA lpData = NULL;
  LPSKYETEK_STRING lpStr = NULL;
  SKYETEK_STATUS st;
  TCHAR addr[256];
  unsigned int numDevices = 0;
  unsigned int numReaders = 0;
  unsigned int i = 0;
  double f = 0.0;

  // set debugger -- uncomment this to see debug output
  // SkyeTek_SetDebugger(debug);
  
  // if you already know your USB address...
  // USB1: \\?\hid#vid_afef&pid_0f01#6&119ec940&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
  // NOTE: you need to escape the slash '\' character with a slash
  memset(addr,0,256*sizeof(TCHAR));
  _tcscpy(addr,_T("\\\\?\\hid#vid_afef&pid_0f01#6&119ec940&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"));


  /* -------------- USE THIS TO GET YOUR USB ADDRESS ---------------
  // discover devices
  _tprintf(_T("Discovering devices...\n"));
  numDevices = SkyeTek_DiscoverDevices(&devices);
  if( numDevices == 0 )
  {
    _tprintf(_T("error: could not discover any devices\n"));
    goto failure;
  }
  _tprintf(_T("Discovered %d devices\n"), numDevices);
  for( i = 0; i < numDevices; i++ )
    _tprintf(_T("Device %d: %s: %s\n"), i, devices[i]->friendly, devices[i]->address);

  // discover readers
  _tprintf(_T("Discovering readers...\n"));
  numReaders = SkyeTek_DiscoverReaders(devices, numDevices, &readers);
  if( numReaders == 0 )
  {
    _tprintf(_T("error: could not discover any readers\n"));
    goto failure;
  }

  // find USB reader
  for( i = 0; i < numReaders; i++ )
  {
    if( _tcscmp(readers[i]->lpDevice->type,SKYETEK_USB_DEVICE_TYPE) == 0 )
    {
      _tprintf(_T("Found USB reader: %s\n"), readers[i]->friendly);
      _tcscpy(addr,readers[i]->lpDevice->address);
      break;
    }
  }

  // find any?
  if( _tcslen(addr) == 0 )
  {
    _tprintf(_T("error: could not discover any readers\n"));
    goto failure;
  }

  // clean up readers and devices
  SkyeTek_FreeReaders(readers,numReaders);
  SkyeTek_FreeDevices(devices,numDevices);
  numReaders = 0;
  numDevices = 0;

  ------------- END -------------------------*/


  // create new USB device
  st = SkyeTek_CreateDevice(addr, &lpDevice);
  if( st != SKYETEK_SUCCESS )
  {
    _tprintf(_T("error: could not create USB port device: %s: %s\n"), 
      addr, SkyeTek_GetStatusMessage(st));
    goto failure;
  }

  // open device 
  st = SkyeTek_OpenDevice(lpDevice);
  if( st != SKYETEK_SUCCESS )
  {
    _tprintf(_T("error: could not open USB port: %s: %s\n"), 
      addr, SkyeTek_GetStatusMessage(st));
    goto failure;
  }
  _tprintf(_T("connected to %s\n"), addr);

  // create reader
  st = SkyeTek_CreateReader(lpDevice, &lpReader);
  if( st != SKYETEK_SUCCESS )
  {
    _tprintf(_T("error: could not find reader on USB port: %s: %s\n"), 
      addr, SkyeTek_GetStatusMessage(st));
    goto failure;
  }
  _tprintf(_T("created USB reader: %s\n"), lpReader->friendly);

  // get system parameter
  st = SkyeTek_GetSystemParameter(lpReader,SYS_FIRMWARE,&lpData);
  if( st != SKYETEK_SUCCESS )
  {
    _tprintf(_T("error: could not get SYS_FIRMWARE: %s\n"), 
      SkyeTek_GetStatusMessage(st));
    goto failure;
  }

  // check value
  if( lpData == NULL || lpData->size == 0 )
  {
    _tprintf(_T("error: SYS_FIRMWARE is NULL or empty\n"));
    goto failure;
  }

  // print frequency value
  lpStr = SkyeTek_GetStringFromData(lpData);
  _tprintf(_T("current SYS_FIRMWARE is: 0x%s\n"), lpStr);

  SkyeTek_FreeString(lpStr);
  SkyeTek_FreeData(lpData);
  SkyeTek_FreeReader(lpReader); // do nothing if NULL
  SkyeTek_FreeDevice(lpDevice); // do nothing if NULL
  _tprintf(_T("done\n"));

  return 1;

failure:
  if( numReaders > 0 ) SkyeTek_FreeReaders(readers,numReaders);
  if( numDevices > 0 ) SkyeTek_FreeDevices(devices,numDevices);
  SkyeTek_FreeReader(lpReader); // do nothing if NULL
  SkyeTek_FreeDevice(lpDevice); // do nothing if NULL
  SkyeTek_FreeData(lpData); // do nothing if NULL
	return 0;

}
示例#3
0
int main(int argc, char* argv[])
{
	LPSKYETEK_DEVICE *devices = NULL;
	LPSKYETEK_READER *readers = NULL;
	LPSKYETEK_TAG *tags = NULL;
	SKYETEK_STATUS status;
	unsigned short count = 0;
	int numDevices = 0;
	int numReaders = 0;
	const int delay = 400000;  	//wait at least 400ms after closing the interface before re-opening (USB enumeration)
	const int tests = 3; 		//number of open/close tests to perform
	const int iterations = 10; 	//number of select tag operations to perform for each test
	int failures = 0;
	int total = 0;

	for(int m = 0; m < tests; m++)
	{
		total ++;
		printf("\n\nTEST #%d\n", total);
		if((numDevices = SkyeTek_DiscoverDevices(&devices)) > 0)
		{
			//printf("example: devices=%d", numDevices);
			if((numReaders = SkyeTek_DiscoverReaders(devices,numDevices,&readers)) > 0 )
			{
				//printf("example: readers=%d\n", numReaders);
				for(int i = 0; i < numReaders; i++)
				{
					printf("Reader Found: %s-%s-%s\n", readers[i]->manufacturer, readers[i]->model, readers[i]->firmware);
					for(int k = 0; k < iterations; k++)
					{
						printf("\tIteration = %d\n",k);
						status = SkyeTek_GetTags(readers[0], AUTO_DETECT, &tags, &count);
						if(status == SKYETEK_SUCCESS)
						{
							if(count == 0)
							{
								printf("\t\tNo tags found\n");
							}
							else
							{
								for(int j = 0; j < count; j++)
								{
									printf("\t\tTag Found: %s-%s\n", SkyeTek_GetTagTypeNameFromType(tags[j]->type), tags[j]->friendly);
								}
							}
						}
						else
						{
							printf("ERROR: GetTags failed\n");
						}
					}
					SkyeTek_FreeTags(readers[i],tags,count);
				}
			}
			else
			{
				failures ++;
				printf("failures = %d/%d\n", failures, total);
				printf("ERROR: No readers found\n");
			}		
		}
		else
		{
			failures ++;
			printf("failures = %d/%d\n", failures, total);
			printf("ERROR: No devices found\n");
		}
		SkyeTek_FreeDevices(devices,numDevices);
		SkyeTek_FreeReaders(readers,numReaders);
		usleep(delay);
	}
}
示例#4
0
// chngintf [numTimes]
int _tmain(int argc, TCHAR* argv[])
{
	LPSKYETEK_READER lpReader = NULL;
	LPSKYETEK_DEVICE *devices = NULL;
	LPSKYETEK_READER *readers = NULL;
  LPSKYETEK_TAG *lpTags = NULL;
  LPSKYETEK_DATA lpData = NULL;
  LPSKYETEK_DATA lpDataOrig = NULL;
  SKYETEK_ADDRESS addr;
  SKYETEK_STATUS st;
  TCHAR *str = NULL;
  unsigned short count;
  unsigned int numDevices;
  unsigned int numReaders;
  unsigned int i = 0;
  double f = 0.0;
  int numTimes = 10;
  int failures = 0;
  int index = 0;
  unsigned char tto;
  unsigned char ctl;

  // Initialize debugging
  fp = _tfopen(_T("debug.txt"),_T("w"));
  if( fp == NULL )
  {
    _tprintf(_T("ERROR: could not open debug.txt output file\n"));
    return 0;
  }
  output(_T("SkyeTek API Change EM Config Example\n"));
  SkyeTek_SetDebugger(debug);

  // Get command line arguments
  if( argc >= 2 )
  {
    numTimes = _ttoi(argv[1]);
  }

  // Discover reader
  output(_T("Discovering reader...\n"));
  numDevices = SkyeTek_DiscoverDevices(&devices);
  if( numDevices == 0 )
  {
    output(_T("*** ERROR: No devices found.\n"));
    fclose(fp);
    return 0;
  }
  output(_T("Discovered %d devices\n"), numDevices);
  numReaders = SkyeTek_DiscoverReaders(devices, numDevices, &readers);
  if( numReaders == 0 )
  {
    SkyeTek_FreeDevices(devices,numDevices);
    output(_T("*** ERROR: No readers found.\n"));
    fclose(fp);
    return 0;
  }

  lpReader = NULL;
  for( int i = 0; i < (int)numReaders; i++ )
  {
    output(_T("Found reader: %s [%s]\n"), readers[i]->friendly, readers[i]->lpDevice->address);
    output(_T("Firmware: %s\n"), readers[i]->firmware);
    if( _tcscmp(readers[0]->model,_T("M9")) == 0 )
    {
      lpReader = readers[i];
      break;
    }
  }

  if( lpReader == NULL )
  {
    output(_T("*** ERROR: No M9 found; this test is only for M9 readers.\n"));
    SkyeTek_FreeReaders(readers, numReaders);
    SkyeTek_FreeDevices(devices, numDevices);
    fclose(fp);
    return 0;
  }

  // Increase the timeout
  output(_T("Setting additional timeout: 5 seconds\n"));
  SkyeTek_SetAdditionalTimeout(lpReader->lpDevice,5000);

  // Set retry count
  lpData = SkyeTek_AllocateData(1);
  lpData->data[0] = 20;
  st = SkyeTek_SetSystemParameter(lpReader,SYS_COMMAND_RETRY,lpData);
  SkyeTek_FreeData(lpData);
  lpData = NULL;
  if( st != SKYETEK_SUCCESS )
  {
    output(_T("*** ERROR: failed to set M9 retries to 20: %s\n"), STPV3_LookupResponse(st));
    SkyeTek_FreeReaders(readers, numReaders);
    SkyeTek_FreeDevices(devices, numDevices);
    fclose(fp);
    return 0;
  }
  output(_T("Set M9 retries to 20\n"), STPV3_LookupResponse(st));

  // Discover tags
  lpTags = NULL;
  count = 0;
  st = SkyeTek_GetTags(lpReader,EM4444,&lpTags,&count);
  if( st != SKYETEK_SUCCESS )
  {
    output(_T("*** ERROR: SkyeTek_GetTags failed to find an EM4444 tag: %s\n"), readers[0]->friendly);
    SkyeTek_FreeReaders(readers, numReaders);
    SkyeTek_FreeDevices(devices, numDevices);
    fclose(fp);
    return 0;
  }
  if( count == 0 )
  {
    output(_T("*** ERROR: Could not find any EM4444 tags in the field\n"));
    SkyeTek_FreeReaders(readers, numReaders);
    SkyeTek_FreeDevices(devices, numDevices);
    fclose(fp);
    return 0;
  }
    
  output(_T("Tag ID: %s\n"), lpTags[0]->friendly);
  output(_T("Tag Type: %s\n"), SkyeTek_GetTagTypeNameFromType(lpTags[0]->type));

  // Loop and read and write config
  for( int i = 0; i < numTimes; i++ )
  {
    // Loop
    output(_T("Loop %d...\n"),i);

    // Read configuration
    output(_T("Reading tag current configuration\n"));
    addr.start = 0x000F;
    addr.blocks = 1;
    st = SkyeTek_ReadTagData(lpReader,lpTags[0],&addr,0,0,&lpDataOrig);
    if( st != SKYETEK_SUCCESS )
    {
      output(_T("*** ERROR: Failed to read tag configuration: %s\n"),STPV3_LookupResponse(st));
      failures++;
      continue;
    }
    str = SkyeTek_GetStringFromData(lpDataOrig);
    output(_T("Current system page: %s\n"),str);
    SkyeTek_FreeString(str);
    lpData = NULL;

    // Adjust index
    index++;
    if( index >= 8 )
      index = 0;
    
    addr.start = 7;
    addr.blocks = 1;
    lpData = SkyeTek_AllocateData(1);
    lpData->data[0] = ctlVals[index];
    //lpDataOrig->data[0] &= 0xC3;
    //lpData->data[0] |= lpDataOrig->data[0];
    ctl = lpData->data[0];
    st = SkyeTek_WriteTagConfig(lpReader,lpTags[0],&addr,lpData);
    if( st != SKYETEK_SUCCESS )
    {
      output(_T("*** ERROR: Could not set control bits to 0x%02X: %s\n"),
        ctl, STPV3_LookupResponse(st));
      SkyeTek_FreeData(lpData);
      lpData = NULL;
      SkyeTek_FreeData(lpDataOrig);
      lpDataOrig = NULL;
      failures++;
      continue;
    }

    // Write configuration
    addr.start = 6;
    addr.blocks = 1;
    lpData->data[0] = ttoVals[index];
    tto = lpData->data[0];
    st = SkyeTek_WriteTagConfig(lpReader,lpTags[0],&addr,lpData);
    if( st != SKYETEK_SUCCESS )
    {
      output(_T("*** ERROR: Could not set TTO to 0x%02X: %s\n"),
        tto, STPV3_LookupResponse(st));
      SkyeTek_FreeData(lpData);
      lpData = NULL;
      SkyeTek_FreeData(lpDataOrig);
      lpDataOrig = NULL;
      failures++;
      continue;
    }
    SkyeTek_FreeData(lpData);
    lpData = NULL;
    SkyeTek_FreeData(lpDataOrig);
    lpDataOrig = NULL;

    // Read the configuration
    addr.start = 6;
    addr.blocks = 1;
    st = SkyeTek_ReadTagConfig(lpReader,lpTags[0],&addr,&lpData);
    if( st != SKYETEK_SUCCESS )
    {
      output(_T("*** ERROR: Could not read TTO configuration: %s\n"),STPV3_LookupResponse(st));
      failures++;
      continue;
    }
    if( lpData->data[0] != tto )
    {
      output(_T("*** ERROR: TTO does not match what was written: read: 0x%02X != written: 0x%02X\n"),
        lpData->data[0], tto);
      SkyeTek_FreeData(lpData);
      lpData = NULL;
      failures++;
      continue;
    }
    output(_T("TTO matches what was written: read: 0x%02X == written: 0x%02X\n"),
      lpData->data[0], tto);
    SkyeTek_FreeData(lpData);
    lpData = NULL;
    addr.start = 7;
    addr.blocks = 1;
    st = SkyeTek_ReadTagConfig(lpReader,lpTags[0],&addr,&lpData);
    if( st != SKYETEK_SUCCESS )
    {
      output(_T("*** ERROR: Could not read control bits configuration: %s\n"),STPV3_LookupResponse(st));
      failures++;
      continue;
    }

	  lpData->data[0] &= 0x3C;
	  ctl &= 0x3C;

    if( lpData->data[0] != ctl )
    {
      output(_T("*** ERROR: Control bits do not match what was written: read: 0x%02X != written: 0x%02X\n"),
        lpData->data[0], ctl);
      SkyeTek_FreeData(lpData);
      lpData = NULL;
      failures++;
      continue;
    }
    output(_T("Control bits matches what was written: read: 0x%02X == written: 0x%02X\n"),
      lpData->data[0], ctl);
    SkyeTek_FreeData(lpData);
    lpData = NULL;

  } // end loop

  // Report result
  if( numTimes > 0 )
  {
    double percent = 0.0;
    percent = 100*((double)(numTimes-failures))/((double)numTimes);
    output(_T("Failed %d times out of %d attempts\n"), failures, numTimes); 
    output(_T("RESULTS: Loop success percentage: %.01f %%\n"), percent); 
  }

  SkyeTek_FreeTags(lpReader,lpTags,count);
  SkyeTek_FreeReaders(readers, numReaders);
  SkyeTek_FreeDevices(devices, numDevices);
  output(_T("Done.\n"));
  fclose(fp);
  return 1;
}