Пример #1
0
//Display the properties of the attached phidget(s) to the screen.  We will be displaying the name, serial number and version of the attached device(s).
int display_devices(CPhidgetManagerHandle MAN)
{
	int serialNo, version, numDevices, i;
	const char* ptr;
	CPhidgetHandle *devices;

	CPhidgetManager_getAttachedDevices (MAN, &devices, &numDevices);

	printf("|-   # -|-              Type              -|- Serial No. -|-  Version -|\n");
	printf("|-------|----------------------------------|--------------|------------|\n");


	for(i = 0; i < numDevices; i++)
	{
		CPhidget_getDeviceType(devices[i], &ptr);
		CPhidget_getSerialNumber(devices[i], &serialNo);
		CPhidget_getDeviceVersion(devices[i], &version);

		printf("|- %3d -|- %30s -|- %10d -|- %8d -|\n", i, ptr, serialNo, version);
		printf("|-------|----------------------------------|--------------|------------|\n");
	}

	CPhidgetManager_freeAttachedDevicesArray(devices);

	return 0;
}
PhidgetManager::PhidgetManager()
: m_manager(NULL),
  m_phidget_list(NULL)
{
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&m_phidget_mutex, &attr);
	pthread_mutexattr_destroy(&attr);

	Lock();

	CPhidgetManager_create(&m_manager);
	CPhidgetManager_set_OnAttach_Handler(m_manager, ::OnAttachManager, this);
	CPhidgetManager_open(m_manager);

	OnAttach(NULL); //Special case to create a tab for the Manager tab

	int handle_count;
	CPhidgetHandle* handle_array;
	if (EPHIDGET_OK == CPhidgetManager_getAttachedDevices(m_manager, &handle_array, &handle_count))
	{
		int i;
		for (i=0; i<handle_count; i++)
		{
			OnAttach(handle_array[i]);
		}
		
		CPhidgetManager_freeAttachedDevicesArray(handle_array);
	}

	Unlock();
}