Ejemplo n.º 1
0
        protected override bool TryCreateDevice(object key, out HidDevice device, out object creationState)
        {
            creationState = null;
            var path = (NativeMethods.io_string_t)key; var hidDevice = new MacHidDevice(path);

            using (var handle = NativeMethods.IORegistryEntryFromPath(0, ref path).ToIOObject())
            {
                if (!handle.IsSet || !hidDevice.GetInfo(handle))
                {
                    device = null; return(false);
                }
                device = hidDevice; return(true);
            }
        }
Ejemplo n.º 2
0
        internal void Init(NativeMethods.io_string_t path, MacHidDevice device)
        {
            IntPtr handle;

            using (var service = NativeMethods.IORegistryEntryFromPath(0, ref path).ToIOObject())
            {
                handle = NativeMethods.IOHIDDeviceCreate(IntPtr.Zero, service);
                if (handle == IntPtr.Zero)
                {
                    throw new IOException("HID class device not found.");
                }

                if (NativeMethods.IOReturn.Success != NativeMethods.IOHIDDeviceOpen(handle))
                {
                    NativeMethods.CFRelease(handle); throw new IOException("Unable to open HID class device.");
                }
            }
            _device = device;
            _handle = handle;
            HandleInitAndOpen();

            _readThread.Start();
            _writeThread.Start();
        }