ListDevice getActiveDevices( const ListDevice& devs )
{
  ListDevice active;
  for( ListDevice::const_iterator i=devs.begin(); i!=devs.end(); i++ )
  {
    if( i->refcount > 0 )
      active.push_back( *i );
  }
  return active;
}
示例#2
0
ListDevice getDevices()
{
    ListDevice devs;

    String ccs = "SYSTEM\\CurrentControlSet\\";
    RegKey dclass( HKEY_LOCAL_MACHINE, ccs+"Control\\DeviceClasses" );
    RegKey ftdibus( HKEY_LOCAL_MACHINE, ccs+"Enum\\FTDIBUS" );
    RegKey usb6001( HKEY_LOCAL_MACHINE, ccs+"Enum\\USB\\Vid_0403&Pid_6001" );

    VecString fdev = ftdibus.getSubkeyNames();
    for( VecString::const_iterator i=fdev.begin(); i!=fdev.end(); i++ )
    {
        if( i->substr(0,18) == String("VID_0403+PID_6001+") )
        {
            Device d;
            d.id = i->substr(18,8);

            try
            {
                RegKey devkey = ftdibus[*i];
                VecString devsub = devkey.getSubkeyNames();
                d.comm = devkey[devsub[0]+"\\Device Parameters"]("PortName").data;
            }
            catch( std::runtime_error e )
            {
                d.comm = "no_comm";
            }

            try {
                d.info = usb6001[d.id]("LocationInformation").data;
            }
            catch( std::runtime_error e ) { }

            try {
                d.refcount = getRefCount( dclass, usb6001[d.id] );
            }
            catch( std::runtime_error e ) { }

            String::size_type ncomm = d.comm.find_first_of("0123456789");
            if( ncomm != String::npos )
                d.sortnum = atoi( d.comm.substr(ncomm).c_str() );

            devs.push_back(d);
        }
    }

    return devs;
}