protected override bool TryCreateDevice(object key, out HidDevice device, out object creationState)
 {
     creationState = null;
     string syspath = (string)key; var hidDevice = new LinuxHidDevice(syspath);
     if (!hidDevice.GetInfo()) { device = null; return false; }
     device = hidDevice; return true;
 }
Example #2
0
        protected override bool TryCreateDevice(object key, out HidDevice device, out object creationState)
        {
            creationState = null;
            string syspath = (string)key; var hidDevice = new LinuxHidDevice(syspath);

            if (!hidDevice.GetInfo())
            {
                device = null; return(false);
            }
            device = hidDevice; return(true);
        }
        internal void Init(string path, LinuxHidDevice device)
        {
            int handle;

            handle = DeviceHandleFromPath(path);

            _device = device;
            _handle = handle;
            HandleInitAndOpen();

            _readThread.Start();
            _writeThread.Start();
        }
Example #4
0
 internal LinuxHidStream(LinuxHidDevice device)
     : base(device)
 {
     _inputQueue  = new Queue <byte[]>();
     _outputQueue = new Queue <CommonOutputReport>();
     _handle      = -1;
     _readThread  = new Thread(ReadThread)
     {
         IsBackground = true, Name = "HID Reader"
     };
     _writeThread = new Thread(WriteThread)
     {
         IsBackground = true, Name = "HID Writer"
     };
 }
Example #5
0
 protected override bool TryCreateHidDevice(object key, out Device device)
 {
     device = LinuxHidDevice.TryCreate((string)key);
     return(device != null);
 }
Example #6
0
        internal static LinuxHidDevice TryCreate(string path)
        {
            var d = new LinuxHidDevice()
            {
                _path = path
            };

            IntPtr udev = NativeMethodsLibudev.Instance.udev_new();

            if (IntPtr.Zero != udev)
            {
                try
                {
                    IntPtr device = NativeMethodsLibudev.Instance.udev_device_new_from_syspath(udev, d._path);
                    if (device != IntPtr.Zero)
                    {
                        try
                        {
                            string devnode = NativeMethodsLibudev.Instance.udev_device_get_devnode(device);
                            if (devnode != null)
                            {
                                d._fileSystemName = devnode;

                                //if (NativeMethodsLibudev.Instance.udev_device_get_is_initialized(device) > 0)
                                {
                                    IntPtr parent = NativeMethodsLibudev.Instance.udev_device_get_parent_with_subsystem_devtype(device, "usb", "usb_device");
                                    if (IntPtr.Zero != parent)
                                    {
                                        string manufacturer = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "manufacturer");
                                        string productName  = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "product");
                                        string serialNumber = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "serial");
                                        string idVendor     = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "idVendor");
                                        string idProduct    = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "idProduct");
                                        string bcdDevice    = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "bcdDevice");

                                        int vid, pid, version;
                                        if (NativeMethods.TryParseHex(idVendor, out vid) &&
                                            NativeMethods.TryParseHex(idProduct, out pid) &&
                                            NativeMethods.TryParseHex(bcdDevice, out version))
                                        {
                                            d._vid          = vid;
                                            d._pid          = pid;
                                            d._version      = version;
                                            d._manufacturer = manufacturer;
                                            d._productName  = productName;
                                            d._serialNumber = serialNumber;

                                            return(d);
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
                            NativeMethodsLibudev.Instance.udev_device_unref(device);
                        }
                    }
                }
                finally
                {
                    NativeMethodsLibudev.Instance.udev_unref(udev);
                }
            }

            return(null);
        }
Example #7
0
        internal void Init(string path, LinuxHidDevice device)
        {
            int handle;
            handle = DeviceHandleFromPath(path);

            _device = device;
            _handle = handle;
            HandleInitAndOpen();

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