public static List <ParallelPortDevice> GetParallelPortDevices()
        {
            List <ParallelPortDevice> result = new List <ParallelPortDevice>();

            string[] portNames = GetLogicalParallelPortNames();

            CurrentControlSetDeviceEnumerator.EnumerateAllDevices(deviceKey =>
            {
                ParallelPortDevice device = new ParallelPortDevice(deviceKey);
                string portName           = device.PortName;
                if (null != portName)
                {
                    if (-1 != Array.IndexOf <string>(portNames, portName))              // portNames has no IndexOf, but Array<T> has
                    {
                        if (("Ports" == device.Class) || ("Parport" == device.Service)) // do not translate
                        {
                            result.Add(device);
                        }
                        if ("System" == device.Class)
                        {
                            if (!string.IsNullOrWhiteSpace(device.IEEE_1284_Manufacturer))
                            {
                                if (!string.IsNullOrWhiteSpace(device.IEEE_1284_Model))
                                {
                                    result.Add(device);
                                }
                            }
                        }
                    }
                }
            }
                                                                  );

            return(result);
        }
Esempio n. 2
0
        public static List <SerialPortDevice> GetSerialPortDevices()
        {
            List <SerialPortDevice> result = new List <SerialPortDevice>();

            string[] portNames = GetSerialPortNames();

            CurrentControlSetDeviceEnumerator.EnumerateAllDevices(deviceKey =>
            {
                SerialPortDevice device = new SerialPortDevice(deviceKey);
                string portName         = device.PortName;
                if (null != portName)
                {
                    if (-1 != Array.IndexOf <string>(portNames, portName))                   // portNames has no IndexOf, but Array<T> has
                    {
                        if (("Ports" == device.Class) || ("serenum" == device.UpperFilters)) // do not translate
                        {
                            result.Add(device);
                        }
                    }
                }
            }
                                                                  );

            return(result);
        }