Example #1
0
 //========================================================================================================
 /// <summary>
 /// creates a list of devices that were detected and have a specific vendor id
 /// </summary>
 /// <param name="format">The format to return device names in</param>
 /// <returns>The list of device names</returns>
 //========================================================================================================
 public static string[] GetDeviceNames(DeviceNameFormat format)
 {
     return GetDeviceNames(format, DeviceListUsage.ReuseList);
 }
Example #2
0
        public static string[] GetDeviceNames(DeviceNameFormat format, DeviceListUsage deviceListUsage)
        {
            m_nameFormat = format;

            if (deviceListUsage == DeviceListUsage.UpdateList)
                return GetUnusedDeviceNames(format);

            if (m_daqDeviceList.Count > 0)
                throw new DaqException(ErrorMessages.DaqDeviceListNotEmpty, ErrorCodes.DaqDeviceListNotEmpty);

            PlatformInterop platformInterop = PlatformInterop.GetUsbPlatformInterop();

            if (platformInterop != null)
            {
                if (m_deviceInfoList.Count == 0 || 
                        m_deviceNames.Count == 0 || 
                            deviceListUsage == DeviceListUsage.RefreshList ||
                                deviceListUsage == DeviceListUsage.UpdateList)
                {
                    /* get a list of detected devices */
                    ErrorCodes er = platformInterop.GetDevices(m_deviceInfoList, deviceListUsage);
    				
                    /* create a DeviceInfo object for the virtual device */
                    //AddVirtualDeviceInfo();

				    if (er == ErrorCodes.LibusbCouldNotBeInitialized)
                        throw new DaqException(ErrorMessages.LibusbCouldNotBeInitialized, er);
    				
				    if (er == ErrorCodes.LibusbCouldNotBeLoaded)
                        throw new DaqException(ErrorMessages.LibusbCouldNotBeLoaded, er);

				    if (er == ErrorCodes.LibUsbGetDeviceDescriptorFailed)
                        throw new DaqException(ErrorMessages.LibUsbGetDeviceDescriptorFailed, er);
                }

                m_deviceNames.Clear();

				foreach (KeyValuePair<int, DeviceInfo> kvp in m_deviceInfoList)
                {
                    DeviceInfo di = kvp.Value;

                    di.DeviceID = platformInterop.GetDeviceID(kvp.Value);

                    if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                        di.SerialNumber = platformInterop.GetSerno(kvp.Value);

                    if (m_nameFormat == DeviceNameFormat.NameOnly)
                    {
                        m_deviceNames.Add(di.DisplayName);
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameAndSerno)
                    {
                        m_deviceNames.Add(String.Format("{0}{1}{2}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.SerialNumber));
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameAndID)
                    {
                        if (di.DeviceID != String.Empty)
                        {
                            m_deviceNames.Add(String.Format("{0}{1}{2}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.DeviceID));
                        }
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameSernoAndID)
                    {
                        if (di.DeviceID != String.Empty)
                        {
                            m_deviceNames.Add(String.Format("{0}{1}{2}{3}{4}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.SerialNumber, Constants.DEVICE_NAME_SEPARATOR, di.DeviceID));
                        }
                    }
                }
            }
            else
            {
                throw new DaqException(ErrorMessages.PlatformNotSupported, ErrorCodes.PlatformNotSupported);
            }


            return m_deviceNames.ToArray();
        }
Example #3
0
        //================================================================================================================
        /// <summary>
        /// creates a list of device names for devices that weren't detected from a previous call to GetUnusedDeviceNames
        /// </summary>
        /// <param name="format">The format to return device names in</param>
        /// <param name="format">A flag indicating if the current list should be used or recreated</param>
        /// <returns>The list of device names</returns>
        //================================================================================================================
        protected static string[] GetUnusedDeviceNames(DeviceNameFormat format)
        {
            List<string> unusedDeviceNames = new List<string>();

            m_nameFormat = format;

            PlatformInterop platformInterop = PlatformInterop.GetUsbPlatformInterop();

            if (platformInterop != null)
            {
                /* get a list of detected devices */
                ErrorCodes er = platformInterop.GetDevices(m_deviceInfoList, DeviceListUsage.UpdateList);

                /* create a DeviceInfo object for the virtual device */
                //AddVirtualDeviceInfo();

                if (er == ErrorCodes.LibusbCouldNotBeInitialized)
                    throw new DaqException(ErrorMessages.LibusbCouldNotBeInitialized, er);

                if (er == ErrorCodes.LibusbCouldNotBeLoaded)
                    throw new DaqException(ErrorMessages.LibusbCouldNotBeLoaded, er);

                if (er == ErrorCodes.LibUsbGetDeviceDescriptorFailed)
                    throw new DaqException(ErrorMessages.LibUsbGetDeviceDescriptorFailed, er);

                m_deviceNames.Clear();

                foreach (KeyValuePair<int, DeviceInfo> kvp in m_deviceInfoList)
                {
                    string name = String.Empty;
                    DeviceInfo di = kvp.Value;

                    /* get the device ID */
                    di.DeviceID = platformInterop.GetDeviceID(kvp.Value);

                    /* get the serial number */
                    if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                        di.SerialNumber = platformInterop.GetSerno(kvp.Value);

                    if (m_nameFormat == DeviceNameFormat.NameOnly)
                    {
                        name = di.DisplayName;
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameAndSerno)
                    {
                        name = String.Format("{0}{1}{2}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.SerialNumber);
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameAndID)
                    {
                        if (di.DeviceID != String.Empty)
                        {
                            name = String.Format("{0}{1}{2}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.DeviceID);
                        }
                    }
                    else if (m_nameFormat == DeviceNameFormat.NameSernoAndID)
                    {
                        if (di.DeviceID != String.Empty)
                        {
                            name = String.Format("{0}{1}{2}{3}{4}", di.DisplayName, Constants.DEVICE_NAME_SEPARATOR, di.SerialNumber, Constants.DEVICE_NAME_SEPARATOR, di.DeviceID);
                        }
                    }

                    /* add all names to the internal list */
                    if (name != String.Empty)
                        m_deviceNames.Add(name);

                    /* add only unused device names to the return list */
                    bool addToUnusedList = true;

                    foreach (DaqDevice device in m_daqDeviceList)
                    {
                        if (device.DeviceInfo.DisplayName == di.DisplayName && device.DeviceInfo.SerialNumber == di.SerialNumber)
                        {
                            addToUnusedList = false;
                        }
                    }

                    if (addToUnusedList)
                        unusedDeviceNames.Add(name);
                }
            }
            else
            {
                throw new DaqException(ErrorMessages.PlatformNotSupported, ErrorCodes.PlatformNotSupported);
            }

            return unusedDeviceNames.ToArray();
        }