Ejemplo n.º 1
0
 public static ExtendetFileInfo ToFileInfo(this StorageFile d)
 {
     Windows.Foundation.IAsyncOperation <Windows.Storage.FileProperties.BasicProperties> T = d.GetBasicPropertiesAsync();
     T.AsTask().Wait();
     Windows.Storage.FileProperties.BasicProperties att = T.GetResults();
     return(new ExtendetFileInfo(d.Path, att.DateModified.DateTime, (long)att.Size));
 }
Ejemplo n.º 2
0
        public string Scan(string DevicePID)
        {
            string selector = HidDevice.GetDeviceSelector(usagePage, usageID, vid, pid);

            Windows.Foundation.IAsyncOperation <DeviceInformationCollection> task = DeviceInformation.FindAllAsync(selector);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            DeviceInformationCollection devices = task.GetResults();

            if (devices.Count > 0)
            {
                return(devices[0].Id);
            }
            return("");
        }
Ejemplo n.º 3
0
        private void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            Windows.Foundation.IAsyncOperation <BluetoothLEDevice> task = BluetoothLEDevice.FromIdAsync(args.Id);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            Device d = new Device(task.GetResults());

            discoveredDevices.Add(d);
            MainThread.BeginInvokeOnMainThread(() =>
            {
                DeviceDiscovered(this, new DeviceDiscoveredEventArgs()
                {
                    Device = d
                });
            });
        }
Ejemplo n.º 4
0
        public void Load(string devicePath)
        {
            string selector = HidDevice.GetDeviceSelector(usagePage, usageID, vid, pid);

            Windows.Foundation.IAsyncOperation <DeviceInformationCollection> task = DeviceInformation.FindAllAsync(selector);
            while (task.Status == Windows.Foundation.AsyncStatus.Started)
            {
                Thread.Sleep(50);
            }
            DeviceInformationCollection devices = task.GetResults();

            foreach (DeviceInformation device in devices)
            {
                if (device.Id == devicePath)
                {
                    FoundDevice(device);
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the results from querying the Cloud Error Message (CEM) service and prints it to the screen
        /// </summary>
        public async void GetHRESULT(Windows.Foundation.IAsyncOperation <Windows.Foundation.Diagnostics.ErrorDetails> info, AsyncStatus status)
        {
            retrievalTick.Change(System.Threading.Timeout.Infinite, 1000);
            try
            {
                // Write verbose information to the debug stream if there's a debugger attached
                var result = info.GetResults();
                System.Diagnostics.Debug.WriteLine("Got the HRESULT");
                System.Diagnostics.Debug.WriteLine("URI: " + result.HelpUri);
                System.Diagnostics.Debug.WriteLine("Description: " + result.Description);
                System.Diagnostics.Debug.WriteLine("Long Description: " + result.LongDescription);

                // Update the output box on the main thread
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (string.IsNullOrEmpty(result.Description))
                    {
                        boundText.Text = "Sorry, no result found\n" + boundText.Text;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Pushing error code");
                        string textToReport = "Retrieved error code in " + retrievalWatch.ElapsedMilliseconds + "ms" +
                                              "\nError Code: " + errorCodeBeingLookedUp +
                                              "\nError Code: 0x" + errorCodeBeingLookedUp.ToString("X8") +
                                              "\nError Message: " + result.Description;
                        System.Diagnostics.Debug.WriteLine(textToReport);
                        boundText.Text = textToReport + boundText.Text;
                    }
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("There was a problem getting the HRESULT");
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            // Done looking up an error code so allow the next lookup to occur
            currentlyLookingUpCode = false;
        }
Ejemplo n.º 6
0
 public override void DiscoverServices()
 {
     Windows.Foundation.IAsyncOperation <Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceServicesResult> task = nativeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
     while (task.Status == Windows.Foundation.AsyncStatus.Started)
     {
         Thread.Sleep(50);
     }
     Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceServicesResult result = task.GetResults();
     this._services.Clear();
     if (result.Status == Windows.Devices.Bluetooth.GenericAttributeProfile.GattCommunicationStatus.Success)
     {
         foreach (var item in result.Services)
         {
             Debug.WriteLine("Device.Discovered Service: " + item.DeviceId);
             this._services.Add(new Service(item));
         }
         ServicesDiscovered?.Invoke(this, new EventArgs());
     }
     else
     {
     }
 }
        //LISTEN FOR NEXT RECEIVE
        private async Task <int> Listen()
        {
            const int NUMBER_OF_BYTES_TO_RECEIVE = 1;           //<<<<<SET THE NUMBER OF BYTES YOU WANT TO WAIT FOR

            byte[]      ReceiveData;
            UInt32      bytesRead;
            MidiMessage ChannelMessage = new MidiMessage();

            //MidiMessage GlobalMessage = new MidiMessage();

            try
            {
                if (UartPort != null)
                {
                    while (true)
                    {
                        //###### WINDOWS IoT MEMORY LEAK BUG 2017-03 - USING CancellationToken WITH LoadAsync() CAUSES A BAD MEMORY LEAK.  WORKAROUND IS
                        //TO BUILD RELEASE WITHOUT USING THE .NET NATIVE TOOLCHAIN OR TO NOT USE A CancellationToken IN THE CALL #####
                        //bytesRead = await DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE).AsTask(ReadCancellationTokenSource.Token);	//Wait until buffer is full

                        Windows.Foundation.IAsyncOperation <uint> taskLoad = DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE);
                        taskLoad.AsTask().Wait();
                        bytesRead = taskLoad.GetResults();

                        //bytesRead = await DataReaderObject.LoadAsync(NUMBER_OF_BYTES_TO_RECEIVE).AsTask();  //Wait until buffer is full


                        if ((ReadCancellationTokenSource.Token.IsCancellationRequested) || (UartPort == null))
                        {
                            break;
                        }

                        if (bytesRead > 0)
                        {
                            ReceiveData = new byte[NUMBER_OF_BYTES_TO_RECEIVE];

                            DataReaderObject.ReadBytes(ReceiveData);

                            foreach (byte Data in ReceiveData)
                            {
                                //-------------------------------
                                //-------------------------------
                                //----- RECEIVED NEXT BYTE ------
                                //-------------------------------
                                //-------------------------------

                                if (Data >= 0x80 && Data <= 0xEF) //new Channel Message
                                {
                                    if (ChannelMessage.IsSet1)    //We already have data in this object
                                    {
                                        //there is data in the current message
                                        RouteMessage(ChannelMessage);
                                        ChannelMessage = new MidiMessage(Data);
                                    }
                                    else     //No data in the message
                                    {
                                        ChannelMessage.Status = Data;
                                        if (MidiMessage.ByteCount(ChannelMessage.MessageClass) == 0)
                                        {
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                }
                                else //not a status byte
                                {
                                    if (ChannelMessage.Status != 0 && !ChannelMessage.IsSet1)
                                    {
                                        ChannelMessage.Data1 = Data;
                                        if (MidiMessage.ByteCount(ChannelMessage.MessageClass) == 1)
                                        {
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                    else //Data1 is full
                                    {
                                        if (ChannelMessage.Status != 0 && !ChannelMessage.IsSet2)
                                        {
                                            ChannelMessage.Data2 = Data;
                                            RouteMessage(ChannelMessage);
                                            ChannelMessage = new MidiMessage();
                                        }
                                    }
                                }
                            }


                            /*if (Data > 0xF0 ) //SysEx message (Global)
                             * {
                             *  //Throw away data until we get to F7
                             * }*/
                        }
                    } //while
                }     //check the port
            } catch (Exception e)
            {
                //We will get here often if the USB serial cable is removed so reset ready for a new connection (otherwise a never ending error occurs)
                if (ReadCancellationTokenSource != null)
                {
                    ReadCancellationTokenSource.Cancel();
                }
                System.Diagnostics.Debug.WriteLine("UART ReadAsync Exception: {0}", e.Message);
            }
            return(await Task.FromResult(0));
        }
        public static async void StartListening(string exampleText = "", bool readBackEnabled = false, bool showConfirmation = false, bool showUI = true)
        {
            if (cortanaRecognizerState == CortanaRecognizerState.Listening)
            {
                return;
            }
            cortanaRecognizerState = CortanaRecognizerState.Listening;

            Debug.WriteLine("Entering: StartListening()");

            speechRecognizer = new SpeechRecognizer();
            speechRecognizer.StateChanged += speechRecognizer_StateChanged;
            speechRecognizer.RecognitionQualityDegrading += speechRecognizer_RecognitionQualityDegrading;

            // Set special commands
            if (showUI)
            {
                speechRecognizer.UIOptions.ExampleText       = exampleText;
                speechRecognizer.UIOptions.IsReadBackEnabled = readBackEnabled;
                speechRecognizer.UIOptions.ShowConfirmation  = showConfirmation;
            }

            Debug.WriteLine("Speech Recognizer Set");
            SpeechRecognitionResult speechRecognitionResult = null;

            Debug.WriteLine("Setting States");
            try {
                await speechRecognizer.CompileConstraintsAsync();

                if (showUI)
                {
                    speechResultTask = speechRecognizer.RecognizeWithUIAsync();
                }
                else
                {
                    speechResultTask = speechRecognizer.RecognizeAsync();
                }

                Debug.WriteLine("Beginning Recognition");

                //Continuously loop until we are completed
                while (speechResultTask.Status == Windows.Foundation.AsyncStatus.Started)
                {
                }
                if (speechResultTask.Status == Windows.Foundation.AsyncStatus.Completed)
                {
                    speechRecognitionResult = speechResultTask.GetResults();
                }
            }
            catch (Exception) { }

            Debug.WriteLine("Recognition Recieved");

            cortanaRecognizerState = CortanaRecognizerState.NotListening;
            speechRecognizer       = null;
            speechResultTask       = null;

            if (speechRecognitionResult != null)
            {
                if (CortanaVoiceRecognitionResult != null)
                {
                    CortanaVoiceRecognitionResult(null, new VoiceRecognitionResultEventArgs(APIResponse.Successful, speechRecognitionResult));
                }
            }
            else
            {
                if (CortanaVoiceRecognitionResult != null)
                {
                    CortanaVoiceRecognitionResult(null, new VoiceRecognitionResultEventArgs(APIResponse.Failed));
                }
            }

            Debug.WriteLine("Exiting StartRecognition()");
            return;
        }