예제 #1
0
        private async Task <bool> _getNetworks()
        {
            WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync();

            if (access != WiFiAccessStatus.Allowed)
            {
                _done = true;
                return(false);
            }
            else
            {
                DeviceInformationCollection adapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());

                if (adapterResults.Count() >= 1)
                {
                    _WiFiAdapter = await WiFiAdapter.FromIdAsync(adapterResults[0].Id);
                }
                else
                {
                    _done = true;
                    return(false);
                }
            }
            await _WiFiAdapter.ScanAsync();

            foreach (WiFiAvailableNetwork availableNetwork in _WiFiAdapter.NetworkReport.AvailableNetworks)
            {
                _WiFiNetworks.Add(availableNetwork.Ssid);
            }
            return(true);
        }
예제 #2
0
        private async void StartCameraPreview()
        {
            // Setup the video preview
            try
            {
                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);



                m_mediaCapture = new MediaCapture();
                await m_mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = devices[devices.Count() - 1].Id
                });

                ui_cameraCapture.Source = m_mediaCapture;
                await m_mediaCapture.StartPreviewAsync();
            }
            catch (Exception)
            {
                return;
            }


            m_videoTimer          = new DispatcherTimer();
            m_videoTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            m_videoTimer.Tick    += M_videoTimer_Tick;
            m_videoTimer.Start();
        }
예제 #3
0
        async void InitializeRfcommDeviceService()
        {
            try
            {
                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));


                var numDevices = DeviceInfoCollection.Count();

                // By clearing the backing data, we are effectively clearing the ListBox
                _pairedDevices = new ObservableCollection <PairedDeviceInfo>();
                _pairedDevices.Clear();

                if (numDevices == 0)
                {
                    //MessageDialog md = new MessageDialog("No paired devices found", "Title");
                    //await md.ShowAsync();
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                    // Found paired devices.
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        _pairedDevices.Add(new PairedDeviceInfo(deviceInfo));
                    }
                }
                PairedDevices.Source = _pairedDevices;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// 异步加载串口列表
        /// </summary>
        public async void SerialList()
        {
            string selectors = SerialDevice.GetDeviceSelector();
            DeviceInformationCollection decices = await DeviceInformation.FindAllAsync(selectors);

            if (decices.Any())
            {
                for (int i = 0; i < decices.Count(); i++)
                {
                    if (AllPortName.Contains(decices[i].Name))
                    {
                        continue;
                    }
                    else
                    {
                        AllPortName.Add(decices[i].Name);
                    }
                }
                //PortName = PortName.Distinct().ToList();
            }
            else
            {
                AllPortName.Clear();
            }
        }
        async void InitializeRfcommDeviceService()
        {
            try
            {
                //string aqs = SerialDevice.GetDeviceSelector();
                //var dis = await DeviceInformation.FindAllAsync(aqs);

                //var numDevices1 = dis.Count;

                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                //DeviceInformationCollection DeviceInfoCollection2 = await DeviceInformation.FindAllAsync();
                //var asdf = (from n in DeviceInfoCollection2 select n.Name).Distinct();

                var numDevices = DeviceInfoCollection.Count();

                // By clearing the backing data, we are effectively clearing the ListBox
                _pairedDevices.Clear();

                if (numDevices == 0)
                {
                    //MessageDialog md = new MessageDialog("No paired devices found", "Title");
                    //await md.ShowAsync();
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                    // Found paired devices.
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        if (deviceInfo.Name.ToUpper().Contains("DEV")) //"SPP"
                        {
                            _pairedDevices.Add(new PairedDeviceInfo(deviceInfo));
                        }
                    }
                }
                numDevices           = _pairedDevices.Count();
                PairedDevices.Source = _pairedDevices;
                if (numDevices == 1)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ConnectDevices.SelectedIndex = 0;
                    });

                    ConnectDevices_DoubleTapped(null, null);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// 串口异步设置
        /// </summary>
        /// <param name="PortName"></param>
        private async void SerialSet(string PortName)
        {
            string selectors = SerialDevice.GetDeviceSelector();
            DeviceInformationCollection decices = await DeviceInformation.FindAllAsync(selectors);

            if (decices.Any())
            {
                for (int i = 0; i < decices.Count(); i++)
                {
                    if (decices[i].Name.Equals(PortName))
                    {
                        Device = await SerialDevice.FromIdAsync(decices[i].Id);
                    }
                }
            }
        }
예제 #7
0
        async void InitializeRfcommDeviceService()
        {
            try
            {
                //var aqsDevices = SerialDevice.GetDeviceSelector();
                //    //.GetDeviceSelector(RfcommServiceId.SerialPort);
                //DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqsDevices);

                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                //HostName hostname = new HostName( "DESKTOP-GCCKFIE");
                //var BTdev = await BluetoothDevice.FromIdAsync("Bluetooth#Bluetooth00:02:72:40:c1:d6-00:15:83:ea:77:4d#RFCOMM:00000000:{00001101-0000-1000-8000-00805f9b34fb}");

                ////DeviceInformationCollection DeviceInfoCollection2 = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelectorForBluetoothDevice(BTdev));
                //DeviceInformationCollection DeviceInfoCollection2 = await DeviceInformation.FindAllAsync();
                //var asdf = (from n in DeviceInfoCollection2 select n.Name).Distinct();



                var numDevices = DeviceInfoCollection.Count();

                // By clearing the backing data, we are effectively clearing the ListBox
                _pairedDevices.Clear();

                if (numDevices == 0)
                {
                    //MessageDialog md = new MessageDialog("No paired devices found", "Title");
                    //await md.ShowAsync();
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                    // Found paired devices.
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        _pairedDevices.Add(new PairedDeviceInfo(deviceInfo));
                    }
                }
                PairedDevices.Source = _pairedDevices;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
예제 #8
0
        async void refreshRfcommDeviceService()
        {
            try
            {
                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                var numDevices = DeviceInfoCollection.Count();
                if (numDevices == 0)
                {
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
        private async Task StartTrackingAsync()
        {
            // Request permission to access bluetooth
            try
            {
                DeviceInformationCollection deviceInfoCollection =
                    await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                if (deviceInfoCollection.Count() > 0)
                {
                    DeviceInformation device = deviceInfoCollection[0];
                    await RfcommDeviceService.FromIdAsync(device.Id);
                }
            }
            catch (Exception) { }
            // Request permission to access location
            var accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:

                StartRecordBtn.IsEnabled = true;
                await BeginExtendedExecution();

                break;

            case GeolocationAccessStatus.Denied:
                Acr.UserDialogs.UserDialogs.Instance.Alert(
                    "Please ensure that geolocation is enabled and permissions are allowed for MyDriving to start a recording.",
                    "Geolocation Disabled", "OK");
                StartRecordBtn.IsEnabled = false;
                break;

            case GeolocationAccessStatus.Unspecified:
                Acr.UserDialogs.UserDialogs.Instance.Alert("Unspecified Error...", "Geolocation Disabled", "OK");
                StartRecordBtn.IsEnabled = false;
                break;
            }
        }
        /// <summary>
        /// 初始化蓝牙串口设备
        /// </summary>
        async void InitializeRfcommDeviceService()
        {
            try
            {
                //获取可用的蓝牙串口设备信息
                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                var numDevices = DeviceInfoCollection.Count();

                // By clearing the backing data, we are effectively clearing the ListBox
                _pairedDevices = new ObservableCollection <PairedDeviceInfo>();
                _pairedDevices.Clear();

                if (numDevices == 0)
                {
                    //MessageDialog md = new MessageDialog("No paired devices found", "Title");
                    //await md.ShowAsync();
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                    // Found paired devices.
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        // DeviceInformation deviceInformation = await DeviceInformation.CreateFromIdAsync(deviceInfo.Id);
                        var service = await RfcommDeviceService.FromIdAsync(deviceInfo.Id);

                        //var de = service.Device.DeviceInformation;
                        _pairedDevices.Add(new PairedDeviceInfo(service));
                    }
                }
                //ConnectDevices.ItemsSource = PairedDevices;
                MyCombobox.ItemsSource = PairedDevices;
                // MyCombobox.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
예제 #11
0
        async void InitializeRfcommDeviceService()
        {
            try
            {
                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));


                var numDevices = DeviceInfoCollection.Count();

                // By clearing the backing data, we are effectively clearing the ListBox
                _pairedDevices = new ObservableCollection <PairedDeviceInfo>();
                _pairedDevices.Clear();

                if (numDevices == 0)
                {
                    System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: No paired devices found.");
                }
                else
                {
                    // Found paired devices.
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        PairedDeviceInfo pdi = new PairedDeviceInfo(deviceInfo);
                        _pairedDevices.Add(pdi);
                        System.Diagnostics.Debug.WriteLine(pdi.ToString());
                        //find the correct OBD Sensor
                        if (pdi.ToString().Contains("OBDLink MX"))
                        {
                            ConnectDevice(pdi);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitializeRfcommDeviceService: " + ex.Message);
            }
        }
예제 #12
0
        private async Task <bool> _getWifiAdapter()
        {
            WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync();

            if (access != WiFiAccessStatus.Allowed)
            {
                throw new Exception("WiFiAccessStatus not allowed.");
            }
            else
            {
                DeviceInformationCollection adapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());

                if (adapterResults.Count() >= 1)
                {
                    _WiFiAdapter = await WiFiAdapter.FromIdAsync(adapterResults[0].Id);
                }
                else
                {
                    throw new Exception("WiFi adapter not found.");
                }
            }
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Get the available camera name
        /// </summary>
        public static string GetCameraName(DeviceInformation cameraInfo, DeviceInformationCollection allCameras)
        {
            bool isCameraNameUnique = allCameras.Count(c => c.Name == cameraInfo.Name) == 1;

            return(isCameraNameUnique ? cameraInfo.Name : string.Format("{0} [{1}]", cameraInfo.Name, cameraInfo.Id));
        }
예제 #14
0
        private async void Connect(object sender, RoutedEventArgs e)
        {
            ConnectButton.IsEnabled = false;
            if (IsConnected == false)
            {
                DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                var numDevices = DeviceInfoCollection.Count();
                if (numDevices == 0)
                {
                    MessageDialog md = new MessageDialog("No paired devices found!", "Warning");
                    await md.ShowAsync();

                    ConnectButton.IsEnabled = true;
                    return;
                }
                else
                {
                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        if (deviceInfo.Name == "ROBOT")
                        {
                            BTDevice = deviceInfo;
                        }
                    }
                }

                if (BTDevice == null)
                {
                    MessageDialog md = new MessageDialog("Robot car is not paired to your device!", "Warning");
                    await md.ShowAsync();

                    ConnectButton.IsEnabled = true;
                    return;
                }
                BTService = await RfcommDeviceService.FromIdAsync(BTDevice.Id);

                if (BTService == null)
                {
                    MessageDialog md = new MessageDialog("Access to the device is denied because the application was not granted access!", "Warning");
                    await md.ShowAsync();

                    ConnectButton.IsEnabled = true;
                    return;
                }

                lock (this) socket = new StreamSocket();

                try
                {
                    await socket.ConnectAsync(BTService.ConnectionHostName, BTService.ConnectionServiceName);

                    reader = new DataReader(socket.InputStream);
                    writer = new DataWriter(socket.OutputStream);

                    //writer.WriteString("OK\r");
                    //await writer.StoreAsync();

                    //uint count = await reader.LoadAsync(3);
                    //uint byteCount = reader.UnconsumedBufferLength;
                    //Debug.WriteLine(byteCount);

                    //string receivedData = reader.ReadString(byteCount);
                    //Debug.WriteLine(receivedData);

                    //if (receivedData == "OK\r") Debug.WriteLine("Minden franko");
                    IsConnected             = true;
                    ConnectButton.IsEnabled = true;
                    ConnectButton.Icon      = new SymbolIcon(Symbol.Cancel);
                    ConnectButton.Label     = "Disconnect";
                }
                catch
                {
                    Disconnect();
                    MessageDialog md = new MessageDialog("Uhh oh something went wrong!", "Warning");
                    md.ShowAsync();
                    ConnectButton.IsEnabled  = true;
                    AppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Minimal;
                    return;
                }
            }
            else
            {
                Disconnect();
                IsConnected              = false;
                ConnectButton.Icon       = new SymbolIcon(Symbol.Accept);
                ConnectButton.Label      = "Connect";
                ConnectButton.IsEnabled  = true;
                AppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Compact;
            }
        }
예제 #15
0
        public async Task <bool> Init(bool simulatormode = false)
        {
            running = true;
            //initialize _data
            data = new Dictionary <string, string> {
                { "vin", DefValue }
            };
            //VIN
            piDs = ObdShare.ObdUtil.GetPIDs();
            foreach (var v in piDs.Values)
            {
                data.Add(v, DefValue);
            }

            this.simulatormode = simulatormode;
            if (simulatormode)
            {
                PollObd();

                return(true);
            }

            DeviceInformationCollection deviceInfoCollection =
                await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

            var numDevices           = deviceInfoCollection.Count();
            DeviceInformation device = null;

            foreach (DeviceInformation info in deviceInfoCollection)
            {
                if (info.Name.ToLower().Contains("obd"))
                {
                    device = info;
                }
            }
            if (device == null)
            {
                return(false);
            }
            try
            {
                service = await RfcommDeviceService.FromIdAsync(device.Id);

                // Disposing the socket with close it and release all resources associated with the socket
                socket?.Dispose();

                socket = new StreamSocket();
                try
                {
                    // Note: If either parameter is null or empty, the call will throw an exception
                    await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);

                    connected = true;
                }
                catch (Exception ex)
                {
                    connected = false;
                    System.Diagnostics.Debug.WriteLine("Connect:" + ex.Message);
                }
                // If the connection was successful, the RemoteAddress field will be populated
                if (connected)
                {
                    string msg = String.Format("Connected to {0}!", socket.Information.RemoteAddress.DisplayName);
                    System.Diagnostics.Debug.WriteLine(msg);

                    dataWriterObject = new DataWriter(socket.OutputStream);
                    dataReaderObject = new DataReader(socket.InputStream);

                    //initialize the device
                    string s;
                    s = await SendAndReceive("ATZ\r");

                    s = await SendAndReceive("ATE0\r");

                    s = await SendAndReceive("ATL1\r");

                    s = await SendAndReceive("ATSP00\r");

                    PollObd();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Overall Connect: " + ex.Message);
                if (dataReaderObject != null)
                {
                    dataReaderObject.Dispose();
                    dataReaderObject = null;
                }
                if (dataWriterObject != null)
                {
                    dataWriterObject.Dispose();
                    dataWriterObject = null;
                }
                if (socket != null)
                {
                    socket.Dispose();
                    socket = null;
                }
                return(false);
            }
        }
예제 #16
0
        private async void ConnectClick(object sender, RoutedEventArgs e)
        {
            DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

            var numDevices = DeviceInfoCollection.Count();

            //Debug.WriteLine(numDevices);
            if (numDevices == 0)
            {
                MessageDialog md = new MessageDialog("No paired devices found!", "Title");
                await md.ShowAsync();

                return;
            }
            else
            {
                // Found paired devices.
                foreach (var deviceInfo in DeviceInfoCollection)
                {
                    //_pairedDevices.Add(new PairedDeviceInfo(deviceInfo));
                    //Debug.WriteLine(deviceInfo.Name);
                    if (deviceInfo.Name == "HC-06")
                    {
                        BTDevice = deviceInfo;
                    }
                }
            }

            if (BTDevice == null)
            {
                MessageDialog md = new MessageDialog("LED lamp is not paired to your device!", "Title");
                await md.ShowAsync();

                return;
            }
            BTService = await RfcommDeviceService.FromIdAsync(BTDevice.Id);

            if (BTService == null)
            {
                MessageDialog md = new MessageDialog("Access to the device is denied because the application was not granted access!", "Title");
                await md.ShowAsync();

                return;
            }

            lock (this)
            {
                socket = new StreamSocket();
            }
            //socket.Control.KeepAlive = true;
            //socket.Control.NoDelay = true;
            try
            {
                await socket.ConnectAsync(BTService.ConnectionHostName, BTService.ConnectionServiceName);

                reader = new DataReader(socket.InputStream);
                writer = new DataWriter(socket.OutputStream);

                writer.WriteString("OK\r");
                await writer.StoreAsync();

                uint count = await reader.LoadAsync(3);

                uint byteCount = reader.UnconsumedBufferLength;
                Debug.WriteLine(byteCount);
                //BufferText.Text = byteCount.ToString();
                //BufferBar.Value = byteCount;
                string receivedData = reader.ReadString(byteCount);
                Debug.WriteLine(receivedData);

                if (receivedData == "OK\r")
                {
                    Debug.WriteLine("Minden franko");
                }
            }
            catch
            {
                MessageDialog md = new MessageDialog("Uhh oh something went wrong!", "Title");
                md.ShowAsync();
                return;
            }
        }
예제 #17
0
        /// <summary>
        /// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, and starts preview
        /// </summary>
        /// <returns></returns>
        private async Task InitializeCameraAsync()
        {
            Debug.WriteLine("InitializeCameraAsync");

            if (_mediaCapture == null)
            {
                // Fujimaki Add カメラデバイスの選択処理
                DeviceInformationCollection cameraDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                DeviceInformation cameraDevice = null;
                for (int i = 0; i < cameraDevices.Count(); i++)
                {
                    if (cameraDevices.ElementAt(i).Name == _cameraDeviceNames[_cameraID])
                    {
                        cameraDevice = cameraDevices.ElementAt(i);
                        break;
                    }
                }
                // Fujimaki Add End カメラデバイスの選択処理

                if (cameraDevice == null)
                {
                    Debug.WriteLine("No camera device found!");
                    return;
                }

                // Create MediaCapture and its settings
                _mediaCapture = new MediaCapture();

                // Register for a notification when something goes wrong
                _mediaCapture.Failed += MediaCapture_Failed;

                var settings = new MediaCaptureInitializationSettings {
                    VideoDeviceId = cameraDevice.Id
                };

                // Initialize MediaCapture
                try
                {
                    await _mediaCapture.InitializeAsync(settings);

                    _isInitialized = true;
                }
                catch (UnauthorizedAccessException)
                {
                    Debug.WriteLine("The app was denied access to the camera");
                }
                catch (Exception excep)
                {
                    int a = 0;
                }

                // If initialization succeeded, start the preview
                if (_isInitialized)
                {
                    // Figure out where the camera is located
                    if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown)
                    {
                        // No information on the location of the camera, assume it's an external camera, not integrated on the device
                        _externalCamera = true;
                    }
                    else
                    {
                        // Camera is fixed on the device
                        _externalCamera = false;

                        // Only mirror the preview if the camera is on the front panel
                        _mirroringPreview = (cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
                    }

                    await SetResolution();
                    await StartPreviewAsync();

                    var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);

                    // Fall back to the local app storage if the Pictures Library is not available
                    _captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;
                }
            }
        }
예제 #18
0
        private async void InitAudio()

        {
            await PopulateDeviceList();

            //stopRecording.Visibility = Visibility.Collapsed;
            var audioLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Music);

            captureFolder = audioLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;


            DeviceInformationCollection j = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);



            var z = j.Count();

            if (j.Count == 0) //messagebox in all languages, no device.
            {
                NoMicrophone.Visibility = Visibility.Visible;
                return;
            }

            try
            {
                foreach (DeviceInformation q in j)
                {
                    ComboBoxItem comboBoxItem = new ComboBoxItem();
                    comboBoxItem.Content = q.Name;
                    comboBoxItem.Tag     = q;
                    Microphones.Items.Add(comboBoxItem);
                }
            }
            catch (Exception e)
            {
                BadDevice.Visibility = Visibility.Visible;
            }

            try
            {
                /*
                 * DeviceInformation gotCamera = (DeviceInformation)j.First();
                 * MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                 * settings.VideoDeviceId = gotCamera.Id;
                 * _mediaCapture = new MediaCapture();
                 *
                 * await _mediaCapture.InitializeAsync();
                 * _mediaCapture.Failed += _mediaCapture_Failed;
                 *
                 * _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
                 *
                 *
                 * GetTheVideo.Source = _mediaCapture;
                 *
                 * await _mediaCapture.StartPreviewAsync();
                 *
                 * PopulateSettingsComboBox();
                 */
            }
            catch (Exception e)
            {
                BadSetting.Visibility = Visibility.Visible;
            }
        }
        //This is taken right out of Essential Video Recorder, it records streaming video
        //and was the first video app I made.  This one is different in that it takes frames
        //and then renders them together.  EVR recorded straight video.

        private async void InitCamera()

        {
            stopCapture.Visibility = Visibility.Collapsed;
            var videosLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);

            captureFolder = videosLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;


            DeviceInformationCollection j = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);



            var z = j.Count();

            var Oz = j.OrderBy(x => x.Name);

            if (j.Count == 0)             //messagebox in all languages, no device.
            {
                NoCamera.Visibility = Visibility.Visible;
                return;
            }

            try
            {
                string[] dups           = new string[j.Count];
                int      WhichDevice    = 0;
                string   nameThatCamera = "";
                int      howManyCameras = 0;
                foreach (DeviceInformation q in Oz)
                {
                    nameThatCamera = q.Name;
                    if (WhichDevice > 0)
                    {
                        for (int v = 0; v < WhichDevice; v++)
                        {
                            if (nameThatCamera == dups[v])
                            {
                                howManyCameras++;
                            }
                        }
                        if (howManyCameras == 0)
                        {
                        }
                        else
                        {
                            howManyCameras++;
                            nameThatCamera = nameThatCamera + '-' + howManyCameras.ToString();
                        }
                        howManyCameras = 0;
                    }
                    dups[WhichDevice] = q.Name;
                    WhichDevice++;
                    ComboBoxItem comboBoxItem = new ComboBoxItem();
                    comboBoxItem.Content = nameThatCamera;

                    comboBoxItem.Tag = q;
                    CameraSource.Items.Add(comboBoxItem);
                }
            }
            catch (Exception e)
            {
                BadDevice.Visibility = Visibility.Visible;
            }

            try
            {
                DeviceInformation gotCamera = (DeviceInformation)Oz.First();
                MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                settings.VideoDeviceId = gotCamera.Id;
                _mediaCapture          = new MediaCapture();

                await _mediaCapture.InitializeAsync();

                _mediaCapture.Failed += _mediaCapture_Failed;

                _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;


                GetTheVideo.Source = _mediaCapture;

                CheckIfStreamsAreIdentical();

                MediaStreamType streamType;

                streamType = MediaStreamType.VideoRecord;
                PopulateStreamPropertiesUI(streamType, CameraSettings2);

                //added to camera and settings initial setting
                CameraSource.SelectedIndex    = 0;
                CameraSettings2.SelectedIndex = 0;
            }
            catch (Exception e)
            {
                BadSetting.Visibility = Visibility.Visible;
            }
        }
        /// <summary>
        /// Returns the device name. It is the same underlying name if only one camera exist with the same name, otherwise it is a combination
        /// of the underlying name and unique Id.
        /// </summary>
        internal static string GetDeviceName(DeviceInformation deviceInfo, DeviceInformationCollection allDevices)
        {
            bool isDeviceNameUnique = allDevices.Count(c => c.Name == deviceInfo.Name) == 1;

            return(isDeviceNameUnique ? deviceInfo.Name : string.Format("{0} [{1}]", deviceInfo.Name, deviceInfo.Id));
        }