Ejemplo n.º 1
0
        public Uploader(string port, int baudrate)
        {
            self = this;

            if (port.StartsWith("/"))
                if (!File.Exists(port))
                    throw new Exception("No such device");

            this.port = new SerialPort(port, baudrate);
            this.port.ReadTimeout = 50;
            this.port.WriteTimeout = 50;

            try
            {
                Console.Write("open");
                if (port.StartsWith("/"))
                    if (!File.Exists(port))
                        throw new Exception("No such device");
                this.port.Open();
                this.port.Write("reboot -b\r");
                Console.WriteLine("..done");
            }
            catch (Exception ex)
            {
                try
                {
                    this.port.Close();
                }
                catch { }
                try
                {
                    this.Dispose();
                    GC.Collect();
                }
                catch { }
                throw ex;
            }
        }