Example #1
0
        private void EnumerateUSBDevices()
        {
            var availableDevices = SerialPortIOKit.GetUSBCommunicationDevices();
            var keys             = new string[] { "ComName", "Vendor", "VendorID", "Product", "ProductID" };


            foreach (var item in availableDevices)
            {
                if (!deviceList.Any(k => k["ComName"].ToString().Equals(item.ComName)))
                {
                    var objects = new object[] {
                        new NSString(item.ComName),
                        new NSString(item.VendorString ?? "?"),
                        new NSString("0x" + item.VendorID.ToString("X")),
                        new NSString(item.ProductString ?? "?"),
                        new NSString("0x" + item.ProductID.ToString("X"))
                    };
                    var dictionary = NSMutableDictionary.FromObjectsAndKeys(objects, keys);
                    deviceList.Add(dictionary);

                    tableContent.AddObject(dictionary);
                }
            }

            var deletedValue = false;

            do
            {
                deletedValue = false;

                foreach (var item in deviceList)
                {
                    if (!availableDevices.Any(k => k.ComName.Equals(item["ComName"].ToString())))
                    {
                        deviceList.Remove(item);
                        tableContent.RemoveObject(item);
                        deletedValue = true;
                        break;
                    }
                }
            } while (deletedValue);
        }
Example #2
0
 private static bool TryGetDevice(int vendorId, int productId, out USBCommunicationDevice device)
 {
     device = SerialPortIOKit.GetUSBCommunicationDevices().FirstOrDefault(d => d.VendorID == vendorId && d.ProductID == productId);
     return(device.VendorID == vendorId && device.ProductID == productId);
 }