Ejemplo n.º 1
0
        public static async Task <bool> OpenAsync()
        {
            var deviceDefinitions = new FilterDeviceDefinition(AbletonVendorID, Push2ProductId);
            var deviceFactory     = WindowsUsbDeviceFactoryExtensions.CreateWindowsUsbDeviceFactory(deviceDefinitions);
            var deviceDefinition  = deviceFactory.GetConnectedDeviceDefinitionsAsync().Result;

            if (deviceDefinition == null || deviceDefinition.Count() < 1)
            {
                return(false);
            }

            var PushDeviceId = deviceDefinition.First().DeviceId;

            //This is the only platform specific part. Each platform has a UsbInterfaceManager
            var usbInterfaceManager = new WindowsUsbInterfaceManager(PushDeviceId);

            usbDevice = new UsbDevice(PushDeviceId, usbInterfaceManager);

            try
            {
                await usbDevice.InitializeAsync();
            }
            catch (Exception)
            {
                usbDevice = null;
                return(false);
            }

            KeepDisplayRefreshed();
            return(true);
        }
Ejemplo n.º 2
0
        private UsbDevice CreateUsbDeviceWithInterface()
        {
            const string deviceId            = "";
            var          usbInterfaceManager = new WindowsUsbInterfaceManager(deviceId, _loggerFactory, null, null);
            var          usbDevice           = new UsbDevice(deviceId, usbInterfaceManager, _loggerFactory);
            var          windowsUsbInterface = new WindowsUsbInterface(null, 0, null, null, null);

            usbDevice.UsbInterfaceManager.UsbInterfaces.Add(windowsUsbInterface);
            return(usbDevice);
        }
Ejemplo n.º 3
0
        private static UsbDevice CreateUsbDeviceWithInterface()
        {
            var          logger              = Substitute.For <ILogger>();
            var          tracer              = Substitute.For <ITracer>();
            const string deviceId            = "";
            var          usbInterfaceManager = new WindowsUsbInterfaceManager(deviceId, logger, tracer, null, null);
            var          usbDevice           = new UsbDevice(deviceId, usbInterfaceManager, logger, tracer);
            var          windowsUsbInterface = new WindowsUsbInterface(null, logger, tracer, 0, null, null);

            usbDevice.UsbInterfaceManager.UsbInterfaces.Add(windowsUsbInterface);
            return(usbDevice);
        }
Ejemplo n.º 4
0
        public void TestValidationExceptionInvalidReadInterface()
        {
            try
            {
                var          logger              = new Mock <ILoggerFactory>();
                const string deviceId            = "";
                var          usbInterfaceManager = new WindowsUsbInterfaceManager(deviceId, logger.Object, null, null);
                var          usbDevice           = new UsbDevice(deviceId, usbInterfaceManager, _loggerFactory);
                usbDevice.UsbInterfaceManager.ReadUsbInterface = new WindowsUsbInterface(null, 0, null, null, null);
            }
            catch (ValidationException vex)
            {
                Assert.AreEqual(Messages.ErrorMessageInvalidInterface, vex.Message);
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 5
0
        public void TestValidationExceptionInvalidReadInterface()
        {
            try
            {
                var          logger              = Substitute.For <ILogger>();
                var          tracer              = Substitute.For <ITracer>();
                const string deviceId            = "";
                var          usbInterfaceManager = new WindowsUsbInterfaceManager(deviceId, logger, tracer, null, null);
                var          usbDevice           = new UsbDevice(deviceId, usbInterfaceManager, logger, tracer);
                usbDevice.UsbInterfaceManager.ReadUsbInterface = new WindowsUsbInterface(null, logger, tracer, 0, null, null);
            }
            catch (ValidationException vex)
            {
                Assert.AreEqual(Messages.ErrorMessageInvalidInterface, vex.Message);
                return;
            }

            Assert.Fail();
        }
Ejemplo n.º 6
0
        private static async Task Run()
        {
            var logger = new DebugLogger();
            var tracer = new DebugTracer();

            DeviceManager.Current.DeviceFactories.Add(new CustomWindowsUsbDeviceFactory(WindowsDeviceConstants.GUID_DEVINTERFACE_USB_DEVICE, logger, tracer));

            var devices = await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(null);

            ConnectedDeviceDefinition garminDefinition = devices.SingleOrDefault(device => device.VendorId == 0x091E && device.ProductId == 0x0003);

            if (garminDefinition == null)
            {
                Console.WriteLine("No connected Garmin device found");
                return;
            }
            var usbInterfaceManager = new WindowsUsbInterfaceManager
                                      (
                garminDefinition.DeviceId,
                logger,
                tracer,
                null,
                null
                                      );

            var usbDevice = new UsbDevice(garminDefinition.DeviceId, usbInterfaceManager, logger, tracer);

            await usbDevice.InitializeAsync();

            var firstUsbInterface = usbDevice.UsbInterfaceManager.UsbInterfaces.First();

            usbInterfaceManager.WriteUsbInterface = firstUsbInterface;
            firstUsbInterface.WriteEndpoint       = firstUsbInterface.UsbInterfaceEndpoints.First(e => e.IsWrite);

            var writeBuffer = Unhexify("140000002f0400000100000000");
            await usbDevice.WriteAsync(writeBuffer);

            Console.WriteLine("Command sent");
        }