Esempio n. 1
0
 internal void imm_removeUsableDevice(YUSBDevice yusbDevice)
 {
     if (_usableDevices.Contains(yusbDevice))
     {
         _usableDevices.Remove(yusbDevice);
     }
 }
        internal async Task <byte[]> DevRequestSync(string serial, byte[] request, YGenericHub.RequestProgress progress,
                                                    object context)
        {
            YUSBDevice d = imm_devFromSerial(serial);

            return(await d.DevRequestSync(serial, request, progress, context));
        }
Esempio n. 3
0
        internal async Task DevRequestAsync(string serial, byte[] request, YGenericHub.RequestAsyncResult asyncResult, object asyncContext)
        {
            YUSBDevice d = imm_devFromSerial(serial);

            if (d == null)
            {
                throw new YAPI_Exception(YAPI.DEVICE_NOT_FOUND, "Device has been uplugged");
            }

            await d.DevRequestAsync(serial, request, asyncResult, asyncContext);
        }
Esempio n. 4
0
        internal async Task <byte[]> DevRequestSync(string serial, byte[] request, YGenericHub.RequestProgress progress, object context)
        {
            YUSBDevice d = imm_devFromSerial(serial);

            if (d == null)
            {
                throw new YAPI_Exception(YAPI.DEVICE_NOT_FOUND, "Device has been uplugged");
            }

            return(await d.DevRequestSync(serial, request, progress, context));
        }
Esempio n. 5
0
        internal async Task <int> ImediateEnum()
        {
            // Create a selector that gets a HID device using VID/PID and a
            // VendorDefined usage.
            var selector = HidDevice.GetDeviceSelector(usagePage, usageId);
            // Enumerate devices using the selector.
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);

            foreach (YUSBDevice yusbDevice in _usableDevices)
            {
                yusbDevice.MarkForUnplug = true;
            }

            if (devices.Count > 0)
            {
                for (var i = 0; i < devices.Count; i++)
                {
                    var devinfo = devices.ElementAt(i);
                    if (!devinfo.IsEnabled)
                    {
                        _hub._yctx._Log(devinfo.Name + " is disabled (skip)\n");
                        continue;
                    }

                    bool found = false;
                    foreach (YUSBDevice yusbDevice in _usableDevices)
                    {
                        if (yusbDevice.Info.Id == devinfo.Id && yusbDevice.imm_isWorking())
                        {
                            yusbDevice.MarkForUnplug = false;
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        continue;
                    }

                    // Open the target HID device at index 0.
                    var device = await HidDevice.FromIdAsync(devinfo.Id, FileAccessMode.ReadWrite);

                    if (device == null)
                    {
                        // allready opened
                        continue;
                    }

                    if (device.VendorId == 0x24e0)
                    {
                        YUSBDevice yusbDevice = new YUSBDevice(this, _hub, device, devinfo);
                        //Debug.WriteLine("setup yusbDevice=s " + yusbDevice.GetHashCode() + " device=" + device.GetHashCode());
                        await yusbDevice.Setup(YUSBPkt.YPKT_USB_VERSION_BCD);

                        _allDevice.Add(yusbDevice);
                        _usableDevices.Add(yusbDevice);
                    }
                    else
                    {
                        Debug.WriteLine("drop" + device.VendorId + ":" + device.ProductId);
                        device.Dispose();
                    }
                }
            }

            _usableDevices.RemoveAll(item => item.MarkForUnplug);
            return(_usableDevices.Count);
        }
 internal async Task DevRequestAsync(string serial, byte[] request, YGenericHub.RequestAsyncResult asyncResult,
                                     object asyncContext)
 {
     YUSBDevice d = imm_devFromSerial(serial);
     await d.DevRequestAsync(serial, request, asyncResult, asyncContext);
 }