예제 #1
0
 /// <summary>
 /// Send a BREAK.
 /// </summary>
 public void SendBreak()
 {
     if (_serialPort != null && _serialPort.IsAvailable())
     {
         Task.Run(() => _serialPort.SendBreak());
     }
     else
     {
         DisplayConnectionError();
     }
 }
예제 #2
0
        /// <summary>
        /// Connect the serial port.
        /// </summary>
        private void Connect()
        {
            // If still connected, disconnect
            if (_serialPort != null)
            {
                Disconnect();
            }

            // Connect and begin receiving data
            _serialPort = new AdcpSerialPort(_serialOption);
            _serialPort.Connect();
            _serialPort.ReceiveRawSerialDataEvent += _serialPort_ReceiveRawSerialDataEvent;

            if (_serialPort.IsAvailable())
            {
                DisplaySerialPortStatusMsg(string.Format("Connected to ADCP on {0} - {1}", _serialOption.Port, _serialOption.BaudRate));
            }
        }
예제 #3
0
        /// <summary>
        /// Get a list of all the entries from the
        /// maintence log.  This will connect to the ADCP.
        /// Download the file.  Read whats in the file
        /// and store it to the list.
        ///
        /// If the serial port conneciton given is not
        /// connected, it will not attempt to get the file.
        /// If the serial port is in any mode but ADCP, it will
        /// not attempt to get the file.
        ///
        /// If you want to download the file and store it to a specific
        /// location, set the dir.  If you do not want to store the file,
        /// leave it null.
        /// </summary>
        /// <param name="adcp">Adcp serial port.</param>
        /// <param name="dir">Directory to store the log.  If NULL is given, the file will be stored to the temp path.</param>
        /// <returns>A list of all the MaitenceEntry in the file.</returns>
        public List <MaintenceEntry> GetMaintenceLog(AdcpSerialPort adcp, string dir = null)
        {
            var list = new List <MaintenceEntry>();

            // If no directory was given, write the file
            // to a temp location
            if (dir == null)
            {
                dir = System.IO.Path.GetTempPath();
            }

            if (adcp.Mode == AdcpSerialPort.AdcpSerialModes.ADCP && adcp.IsAvailable())
            {
                // Get the log file
                string maintLog = DownloadLog(dir, adcp);

                // Decode the log file of all its content
                list = DecodeLog(maintLog);

                // The list will be null if the file is empty
                // Then create an empty list so NULL will not be returned
                if (list == null)
                {
                    list = new List <MaintenceEntry>();
                }

                // If the list was empty, then the log downloaded
                // was empty or bad.  Delete the file
                if (list.Count == 0)
                {
                    try
                    {
                        File.Delete(dir + @"\" + MAINT_FILE_NAME);
                    }
                    catch (Exception e)
                    {
                        log.Error(string.Format("Error deleting maintence file {0}", dir + @"\" + MAINT_FILE_NAME), e);
                    }
                }
            }


            return(list);
        }