Exemplo n.º 1
0
        //Timer TimerDetectBoard;
        public bool DetectBoard()
        {
            string[] Ports = SerialPort.GetPortNames();

            List<string> Found = new List<string>();

            Board = null;

            foreach (string Port in Ports)
            {
                try
                {
                    SerialPort sp = new SerialPort(Port, BaudRateBootloader, Parity.None, 8, StopBits.One);
                    sp.RtsEnable = false;
                    sp.DtrEnable = false;

                    sp.Open();
                    /*TimerDetectBoard = new Timer();
                    TimerDetectBoard.Interval = 500;
                    TimerDetectBoard.Start();
                    TimerDetectBoard.Tick += new EventHandler(t_Detect_Tick);*/

                    sp.Write(new byte[] { CMD_NOP }, 0, 1);
                    int reply = -1;

                    //while (TimerDetectBoard.Enabled)
                    //reply = sp.ReadByte();
                    Thread.Sleep(500);
                    if (sp.BytesToRead > 0)
                        reply = sp.ReadByte();

                    if (reply != -1 && reply == CMD_NOP_REPLY)
                    {
                        Found.Add(Port);
                    }
                    Thread.Sleep(1000);

                    sp.Close();
                }
                catch (Exception)
                {

                }
            }

            if (Found.Count > 1)
                MessageBox.Show("Detected more XBoards! Using the first one.");

            foreach (string Port in Found)
                MessageBox.Show("Detected XBoard on port " + Port);

            if (Found.Count > 0)
            {
                Comm = new SerialPort(Found[0], BaudRateBootloader, Parity.None, 8, StopBits.One);
                Comm.RtsEnable = false;
                Comm.DtrEnable = false;
                Comm.Open();
                Connected = true;

                LoadBoardInfo();

                return true;
            }

            return false;
        }
Exemplo n.º 2
0
        private void LoadBoardInfo()
        {
            BLMode();

            Comm.Write(new byte[] { CMD_GETID }, 0, 1);

            ReplyGETID reply = new ReplyGETID();
            reply.Load(Comm);

            Board = new BoardInfo();

            Board.BLVersion = reply.BootloaderVersion;
            Board.Board = (Boards)reply.Board;
            Board.BoardRevision = reply.BoardRevision;
            Board.FlashSize = reply.FlashSize;
            Board.PageSize = reply.PageSize;

            RegularMode();
        }
Exemplo n.º 3
0
        //Timer TimerDetectBoard;

        public bool DetectBoard()
        {
            string[] Ports = SerialPort.GetPortNames();

            List <string> Found = new List <string>();

            Board = null;

            foreach (string Port in Ports)
            {
                try
                {
                    SerialPort sp = new SerialPort(Port, BaudRateBootloader, Parity.None, 8, StopBits.One);
                    sp.RtsEnable = false;
                    sp.DtrEnable = false;

                    sp.Open();

                    /*TimerDetectBoard = new Timer();
                     * TimerDetectBoard.Interval = 500;
                     * TimerDetectBoard.Start();
                     * TimerDetectBoard.Tick += new EventHandler(t_Detect_Tick);*/

                    sp.Write(new byte[] { CMD_NOP }, 0, 1);
                    int reply = -1;

                    //while (TimerDetectBoard.Enabled)
                    //reply = sp.ReadByte();
                    Thread.Sleep(500);
                    if (sp.BytesToRead > 0)
                    {
                        reply = sp.ReadByte();
                    }

                    if (reply != -1 && reply == CMD_NOP_REPLY)
                    {
                        Found.Add(Port);
                    }
                    Thread.Sleep(1000);

                    sp.Close();
                }
                catch (Exception)
                {
                }
            }

            if (Found.Count > 1)
            {
                MessageBox.Show("Detected more XBoards! Using the first one.");
            }

            foreach (string Port in Found)
            {
                MessageBox.Show("Detected XBoard on port " + Port);
            }

            if (Found.Count > 0)
            {
                Comm           = new SerialPort(Found[0], BaudRateBootloader, Parity.None, 8, StopBits.One);
                Comm.RtsEnable = false;
                Comm.DtrEnable = false;
                Comm.Open();
                Connected = true;

                LoadBoardInfo();

                return(true);
            }

            return(false);
        }