Exemplo n.º 1
0
        //The brick is the front-end of the library.  It contains a simplified version of functions in NXTLib.Protocol.
        //TODO: Add more functions to front-end
        //TODO: Add timer

        #region Connection and Timer
        public Brick(Protocol protocol, Protocol.BrickInfo brickinfo)
        {
            link           = protocol;
            this.brickinfo = brickinfo;

            if (link == null)
            {
                throw new NXTLinkNotSupported();
            }
            if (!link.IsSupported)
            {
                throw new NXTLinkNotSupported();
            }
        }
Exemplo n.º 2
0
        private void Item_Click(object sender, EventArgs e)
        {
            Button s = (Button)sender;

            s.Enabled = false;
            Brick brick = new Brick();

            if (s.Name.StartsWith("USB"))
            {
                USB usb = new USB();
                Protocol.BrickInfo info = new Protocol.BrickInfo();
                info.address = new byte[] { 0, 0, 0, 0, 0, 0 };
                info.name    = s.Text.Trim();
                brick        = new Brick(usb, info);
                myLinkType   = LinkType.USB;
            }
            if (s.Name.StartsWith("BLU"))
            {
                Bluetooth          blue = new Bluetooth();
                Protocol.BrickInfo info = new Protocol.BrickInfo();
                info.address = Utils.AddressString2Byte(s.Name.Substring(3), true);
                info.name    = s.Text.Trim();
                brick        = new Brick(blue, info);
                myLinkType   = LinkType.Bluetooth;
            }

            /*try
             * {
             *  brick.Connect();
             *  brick.Disconnect();
             * }
             * catch (Exception ex)
             * {
             *  WriteMessage("Error while connecting to brick:");
             *  WriteMessage(ex.Message);
             *  Disconnect_Click(null, null);
             *  return;
             * }*/
            myBrick = brick;

            Disconnect.Enabled = true;
            s.Enabled          = true;
            List.Controls.Clear();
            List.Visible      = false;
            SearchVia.Enabled = false;
            Search.Enabled    = true;
            Time.Enabled      = false;
            Search.Image      = global::NXTLibTesterGUI.Properties.Resources.StatusAnnotations_Complete_and_ok_32xLG_color;

            NXTPanel.Visible = true;
            NXT.Text         = "       Connected to " + myBrick.brickinfo.name;
            NXTConn.Text     = "Connection Type: " + myLinkType.ToString();
            if (myLinkType != LinkType.USB)
            {
                NXTAdd.Text = "Address: " + Utils.AddressByte2String(myBrick.brickinfo.address, true);
            }
            else
            {
                NXTAdd.Text = "";
            }

            CheckUpdateStatus();
            Search.Text = " Update Version Info";
            WriteMessage("Connection successful!");
        }