Example #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));
            }
        }
Example #2
0
 /// <summary>
 /// DisconnectFromUART
 /// Disconnects from the UART
 /// </summary>
 public void DisconnectFromUART()
 {
     if (null != DataReaderObject)
     {
         DataReaderObject.Dispose();
     }
     if (null != DataWriterObject)
     {
         DataWriterObject.Dispose();
     }
     if (null != SerialPort)
     {
         SerialPort.Dispose();
         SerialPort = null;
     }
 }
Example #3
0
 /// <summary>
 /// DisconnectFromUART
 /// Disconnects from the UART
 /// </summary>
 public void DisconnectFromUART()
 {
     StopReading();
     if (null != DataReaderObject)
     {
         //DataReaderObject.DetachStream();
         //DataReaderObject.DetachBuffer();
         DataReaderObject.Dispose();
     }
     if (null != DataWriterObject)
     {
         DataWriterObject.Dispose();
     }
     if (null != SerialPort)
     {
         SerialPort.Dispose();
         SerialPort = null;
     }
 }
Example #4
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");
                }
            }
        }