Esempio n. 1
0
        /// <summary>
        /// SendCommand
        /// Asynchronous task to write to GPS through UART
        /// </summary>
        /// <param name="cmdString"></param>
        /// <returns>async Task</returns>
        private async Task SendCommandAsync(string cmdString)
        {
            try
            {
                //Launch the WriteAsync task to perform the write
                Task <UInt32> storeAsyncTask;

                if (cmdString.Length != 0)
                {
                    // Load the text from the sendText input text box to the dataWriter object
                    DataWriterObject.WriteString(cmdString);

                    // Launch an async task to complete the write operation
                    storeAsyncTask = DataWriterObject.StoreAsync().AsTask();

                    UInt32 bytesWritten = await storeAsyncTask;
                    if (bytesWritten != cmdString.Length)
                    {
                        throw new Exception("Bytes written does not match command length");
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Error writing to GPS: {0}", ex.Message));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// SendCommand
        /// Asynchronous task to write to GPS through UART
        /// </summary>
        /// <param name="command"></param>
        /// <returns>async Task</returns>
        private async Task SendCommandAsync(byte[] command)
        {
            //Launch the storeAsync task to perform the write
            Task <UInt32> storeAsyncTask;

            if (command.Length != 0)
            {
                // Load the text from the sendText input text box to the dataWriter object
                DataWriterObject.WriteBytes(command);

                // Launch an async task to complete the write operation
                storeAsyncTask = DataWriterObject.StoreAsync().AsTask();

                UInt32 bytesWritten = await storeAsyncTask;
                if (bytesWritten != command.Length)
                {
                    throw new Exception("Bytes written does not match command length");
                }
            }
        }