示例#1
0
        /// <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();
        }
示例#2
0
        private static ISerialPortNotifier CreatePortNotifier()
        {
            ISerialPortNotifier portNotifier = null;

            var portNotifierKind = DeviceManagementInterfaceKindHelpers.GetKind();

            switch (portNotifierKind)
            {
            case DeviceManagementInterfaceKind.IOKit:
                portNotifier = new IOKitNotificationPort();
                break;

            case DeviceManagementInterfaceKind.Dev:
                portNotifier = new FileSystemNotifcationPort();
                break;
            }

            return(portNotifier);
        }