Exemplo n.º 1
0
        private void raiseEvent(String state, int percent, String message = "")
        {
            if (percent > 100)
            {
                Console.Write(percent);
                percent = 100;
            }

            _percent = percent;

            if (OnStateChanged != null)
            {
                EventArgs_StateChanged e = new EventArgs_StateChanged();
                e.percent = percent;
                e.State   = state;
                e.message = message;
                OnStateChanged(this, e);
            }
        }
Exemplo n.º 2
0
        // thread start
        private void Thread_StartBootloader()
        {
            //Thread.Sleep(1000);
            raiseEvent("port scan", 5, "a");
            DateTime sTime = DateTime.Now;

            // 현재 포트 리스트 작성
            List <COMPortInfo> prePorts = update_ports();
            List <COMPortInfo> ports;

            //Thread.Sleep(1000);
            raiseEvent("reboot", 10, "b");
            _sp.Close();
            _sp.Open();
            //System.Threading.Thread.Sleep(100);
            //_sp.Close();
            bool isExist = false;

            DateTime stime = DateTime.Now;
            TimeSpan ts;
            bool     isNull = true;

            // 기존 포트 있을 동안 대기하기
            do
            {
                System.Threading.Thread.Sleep(200);
                ts = DateTime.Now - stime;

                if (ts.TotalSeconds >= 10)
                {
                    State = ESTATE.COMPLETE;
                    EventArgs_StateChanged e = new EventArgs_StateChanged();
                    e.message = "Port not found.";

                    Thread.Sleep(100);
                    OnError(this, e);
                    return;
                }

                isExist = false;
                foreach (COMPortInfo com in update_ports())
                {
                    isNull = false;
                    //Console.WriteLine(com.Name);
                    if (com.Name == _sp.PortName)
                    {
                        isExist = true;
                    }
                }
            } while (isExist || isNull);

            //Thread.Sleep(1000);
            raiseEvent("reboot", 15, "d");

            // 새로운 포트 찾기
            do
            {
                System.Threading.Thread.Sleep(10);
                ports = update_ports();
                _percent++;
            } while (ports.Count < prePorts.Count);

            //Thread.Sleep(1000);
            raiseEvent("finding", 20, "e");
            foreach (COMPortInfo com in ports)
            {
                _percent++;
                bool found = false;
                foreach (COMPortInfo preCom in prePorts)
                {
                    if (com.Name == preCom.Name)
                    {
                        found = true;
                        break;
                    }
                }

                // 추정 포트 찾음
                if (found == false)
                {
                    startAvrdude(com.Name);
                    return;
                }
            }
        }