Beispiel #1
0
std::vector<std::string>
LoadedDeviceAdapter::GetAvailableDeviceNames() const
{
   unsigned deviceCount = GetNumberOfDevices();
   std::vector<std::string> deviceNames;
   deviceNames.reserve(deviceCount);
   for (unsigned i = 0; i < deviceCount; ++i)
   {
      ModuleStringBuffer nameBuf(this, "GetDeviceName");
      bool ok = GetDeviceName(i, nameBuf.GetBuffer(), nameBuf.GetMaxStrLen());
      if (!ok)
      {
         throw CMMError("Cannot get device name at index " + ToString(i) +
               " from device adapter module " + ToQuotedString(name_));
      }
      deviceNames.push_back(nameBuf.Get());
   }
   return deviceNames;
}
int Hub::DetectInstalledDevices()
{
    ClearInstalledDevices();

    InitializeModuleData();

    char hubname[MM::MaxStrLength];
    GetName(hubname);
    for(unsigned i = 0; i < GetNumberOfDevices(); i++)
    {
        char devname[MM::MaxStrLength];
        if(GetDeviceName(i, devname, MM::MaxStrLength) &&
                strcmp(hubname, devname) != 0)
        {
            MM::Device* dev = CreateDevice(devname);
            AddInstalledDevice(dev);
        }
    }

    return DEVICE_OK;
}
//  Constructor initializes the USDigital's SEI communication, and prepares to read the A2
vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2 (const char * name,
                                                    vrpn_Connection * c,
                                                    vrpn_uint32 portNum,
                                                    vrpn_uint32 numChannels,
                                                    vrpn_int32 reportOnChangeOnly) :
vrpn_Analog (name, c),
_SEIopened(vrpn_false),
_devAddr(NULL),
_reportChange(reportOnChangeOnly!=0),
_numDevices(0)
{
#ifdef VRPN_USE_USDIGITAL
    this->_devAddr = new long[vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2_CHANNEL_MAX] ;
    if (this->_devAddr == NULL) {
        fprintf(stderr,"vrpn_Analog_USDigital_A2: Out of memory!\n");
	return;
    }    

    this->setNumChannels( numChannels );

    // Check if we got a connection.
    if (d_connection == NULL) {
        fprintf(stderr,"vrpn_Analog_USDigital_A2: Can't get connection!\n");
	return;
    }    

    //  Prepare to get data from the SEI bus
    long err;
#ifdef VRPN_USE_USDIGITAL
    err = InitializeSEI(portNum, AUTOASSIGN) ;
#else
    fprintf(stderr,"vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2(): Not yet implemented for this architecture\n");
    err = -1;
#endif
    if (err) {
        fprintf(stderr, "vrpn_Analog_USDigital_A2:  Can't initialize SEI bus for port %d.\n", 
#ifdef VRPN_USE_USDIGITAL
        GetCommPort()
#else
	0
#endif
	);

        return ;
    } else {
        _SEIopened = vrpn_true ;
    }

    //  Check if the number of devices matches that expected
#ifdef VRPN_USE_USDIGITAL
    _numDevices = GetNumberOfDevices() ;
#endif
    if (_numDevices<0 || _numDevices>vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2_CHANNEL_MAX) {
        fprintf(stderr,
            "vrpn_Analog_USDigital_A2:  Error (%d) returned from GetNumberOfDevices call on SEI bus",
            _numDevices) ;
        _numDevices = 0 ;
    }
    if (_numDevices != numChannels)
        fprintf(stderr, 
    "vrpn_Analog_USDigital_A2:  Warning, number of requested devices (%d) is not the same as found (%d)\n", 
        numChannels, _numDevices) ;

    //  Initialize the addresses
    for (int c=0 ; c<vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2_CHANNEL_MAX ; c++)
        _devAddr[c] = -1 ;

    //  Get the device addresses.
    for (vrpn_uint32 d=0 ; d<_numDevices ; d++) {
        long deviceInfoErr, model, serialnum, version, addr ;
#ifdef VRPN_USE_USDIGITAL
        deviceInfoErr = GetDeviceInfo(d, &model, &serialnum, &version, &addr) ;
        if (!deviceInfoErr)
           _devAddr[d] = addr ;
#endif

#ifdef VERBOSE
        //  Dump out the device data
        if (deviceInfoErr)
            fprintf(stderr, "vrpn_Analog_USDigital_A2: could not get information on Device #%d!\n", d) ;
        else
            fprintf(stderr, "vrpn_Analog_USDigital_A2: Device #%d: model=%d, serialnum=%d, version=%d, addr=%d\n",
                    d, model, serialnum, version, addr) ;
#endif    //  VERBOSE
    }
#else
    fprintf(stderr,"vrpn_Analog_USDigital_A2::vrpn_Analog_USDigital_A2(): Not compiled in; define VRPN_USE_USDIGITAL in vrpn_Configure.h and recompile VRPN\n");
    portNum = portNum + 1; // Remove unused parameter warning.
    numChannels = numChannels + 1; // Remove unused parameter warning.
    _SEIopened = !_SEIopened; // Removed unused variable warning.
    _devAddr = _devAddr + 1; // Removed unused variable warning.
    _numDevices = _numDevices + 1; // Removed unused variable warning.
#endif
}    //  constructor
Beispiel #4
0
	//---------------
	long Bus::getDeviceCount() {
		return GetNumberOfDevices();
	}