/// <summary> /// Mac-specific implementation. /// </summary> static partial void UpdateAvailablePorts() { var ports = Enumerable.Empty <string>(); switch (DeviceManagementInterfaceKindHelpers.GetKind()) { case DeviceManagementInterfaceKind.IOKit: // Need to set up an Autorelease pool here since we may be doing // this on a worker thread, and it makes some IOKit calls. Specifically, // some NSObject instances may be created, and thus the need for the pool. using (var pool = new NSAutoreleasePool()) { using (var masterPort = new IOMachPort()) { using (var iterator = masterPort.GetRS232SerialServicesIterator()) { DebugOutput("Got iterator of: " + iterator); ports = iterator.EnumerateSerialPorts(IOKitHelpers.BluetoothPortsExclusionFilter); } } } break; case DeviceManagementInterfaceKind.Dev: // NOTE: The MONO serial implementation lists only /dev/tty* entries. So we filter by that, then substitute since we want cu instead of tty. ports = System.IO.Ports.SerialPort.GetPortNames().Where(p => p.StartsWith("/dev/tty.") && !IOKitHelpers.BluetoothPortsExclusionFilter(p)).Select(p => System.Text.RegularExpressions.Regex.Replace(p, "^/dev/tty", "/dev/cu")); break; } _availablePorts = ports.ToArray(); }
/// <summary> /// Gets the USB serial numbers of connected LTO Flash! devices. /// </summary> /// <returns>The USB serial numbers of LTO Flash! devices currently connected to the system.</returns> /// <remarks>This technique uses the IOKit to enumerate USB devices connected to the system that have the /// vendor and product IDs matching what the LTO Flash! hardware uses. The matches are then refined further /// by examining the user-visible vendor and product strings, which are programmed into the chip during /// LTO Flash! device manufacture. These disambiguate actual LTO Flash! devices from other devices connected /// to the system that may be using the same USB to Serial chipset from FTDI. /// NOTE: If LTO Flash! hardware is ever revised to use a different USB-to-serial chipset, or driver /// behavior changes w.r.t. port naming, etc. this will need to be revised.</remarks> private static IEnumerable <string> GetConnectedDeviceSerialNumbers() { var connectedDevices = new List <string>(); using (var masterPort = new IOMachPort()) { using (var iterator = masterPort.GetUSBServicesIterator(Device.UsbVendorId, Device.UsbProductId)) { if ((iterator != null) && iterator.IsValid) { var validEntry = true; do { using (var deviceEntry = iterator.Next <IORegistryEntry>()) { validEntry = deviceEntry != null; if (validEntry) { var vendor = deviceEntry.GetProperty <NSString>(IOKitHelpers.KUSBVendorString); var product = deviceEntry.GetProperty <NSString>(IOKitHelpers.KUSBProductString); if ((vendor == Device.UsbVendorName) && (product == Device.UsbProductName)) { // The serial port for the FTDI chip are named based off the USB serial number. var deviceSerial = deviceEntry.GetProperty <NSString>(IOKitHelpers.KUSBSerialNumberString); if (!string.IsNullOrEmpty(deviceSerial)) { connectedDevices.Add(deviceSerial); } } } } }while (validEntry); } } } return(connectedDevices); }