コード例 #1
0
        public override async Task InitializeAsync()
        {
            if (Disposed)
            {
                throw new Exception(DeviceDisposedErrorMessage);
            }

            await GetDeviceAsync(DeviceId);

            if (ConnectedDevice != null)
            {
                var usbInterface = ConnectedDevice.Configuration.UsbInterfaces.FirstOrDefault();

                if (usbInterface == null)
                {
                    ConnectedDevice.Dispose();
                    throw new Exception("There was no Usb Interface found for the device.");
                }

                var interruptPipe = usbInterface.InterruptInPipes.FirstOrDefault();

                if (interruptPipe == null)
                {
                    throw new Exception("There was no interrupt pipe found on the interface");
                }

                interruptPipe.DataReceived += InterruptPipe_DataReceived;

                //TODO: Fill in the DeviceDefinition...

                // TODO: It should be possible to select a different configurations, interface, and pipes

                _DefaultConfigurationInterface = ConnectedDevice.Configuration.UsbInterfaces.FirstOrDefault();

                //TODO: Clean up this messaging and move down to a base class across platforms
                if (_DefaultConfigurationInterface == null)
                {
                    throw new Exception("Could not get the default interface configuration for the USB device");
                }

                _DefaultOutPipe = _DefaultConfigurationInterface.InterruptOutPipes.FirstOrDefault();

                if (_DefaultOutPipe == null)
                {
                    throw new Exception("Could not get the default out pipe for the default USB interface");
                }

                _DefaultInPipe = _DefaultConfigurationInterface.InterruptInPipes.FirstOrDefault();

                if (_DefaultOutPipe == null)
                {
                    throw new Exception("Could not get the default in pipe for the default USB interface");
                }
            }
            else
            {
                throw new Exception($"Could not connect to device with Device Id {DeviceId}. Check that the package manifest has been configured to allow this device.");
            }
        }
コード例 #2
0
        private async Task ConnenctDevice(DiscoverResult result)
        {
            await VideoPlayer.StopVideo();

            _connectionDisposables.Clear();
            ConnectedDevice.Dispose();
            ConnectedDevice = new DeviceModel();
            if (result == null)
            {
                return;
            }

            var oldViewMode = _viewMode.Value;
            var nextDevice  = new DeviceModel(result);

            nextDevice.ModeChanged.Subscribe(async(_) => await OnDeviceModeChanged()).AddTo(_connectionDisposables);
            nextDevice.PreviewModeChanged.Subscribe(async(_) => await OnDeviceModeChanged()).AddTo(_connectionDisposables);
            nextDevice.VideoSwitcherStatusChanged.Subscribe(OnVideoSwitcherStatusChanged).AddTo(_connectionDisposables);
            await nextDevice.Connect();

            if (nextDevice.IsConnected == false)
            {
                _connectionDisposables.Clear();
                nextDevice.Dispose();
                return;
            }

            switch (oldViewMode)
            {
            case ViewMode.Input:
                await nextDevice.PreviewInputTile();

                break;

            case ViewMode.Output:
                await nextDevice.PreviewProgramOut();

                break;

            default:
                break;
            }

            ConnectedDevice = nextDevice;
            VideoPlayer.SetEnable();
        }
コード例 #3
0
        protected virtual async void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources.
                await VideoPlayer.StopVideo();

                _connectionDisposables.Dispose();
                ConnectedDevice.Dispose();
                _disposables.Dispose();
            }

            // Dispose unmanaged resources.

            // Set disposed flag.
            _disposed = true;
        }