Exemplo n.º 1
0
 private void AddItem(Brick connection, LinkType linktype)
 {
     Button button = new Button();
     button.FlatStyle = FlatStyle.Flat;
     button.FlatAppearance.BorderColor = SystemColors.Control;
     button.FlatAppearance.BorderSize = 0;
     button.FlatAppearance.MouseOverBackColor = SystemColors.ControlLightLight;
     button.FlatAppearance.MouseDownBackColor = SystemColors.HotTrack;
     button.AutoEllipsis = false;
     if (linktype == LinkType.USB) { button.Image = global::NXTLibTesterGUI.Properties.Resources.usb2; }
     if (linktype == LinkType.Bluetooth) { button.Image = global::NXTLibTesterGUI.Properties.Resources.bluetooth; }
     button.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
     button.Location = new System.Drawing.Point(3, 0);
     if (linktype == LinkType.USB) { button.Name = "USB"; }
     if (linktype == LinkType.Bluetooth) { button.Name = "BLU" + Utils.AddressByte2String(connection.brickinfo.address, true); }
     button.Size = new System.Drawing.Size(259, 20);
     button.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0);
     button.TabIndex = 1;
     button.Text = "       " + connection.brickinfo.name;
     button.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     button.MouseDown += Button_MouseDown;
     button.MouseClick += Item_Click;
     button.MouseUp += Button_MouseUp;
     List.Invoke(new MethodInvoker(delegate { List.Controls.Add(button); }));
 }
Exemplo n.º 2
0
 public CreateImage(Brick brick)
 {
     InitializeComponent();
     returnerror = null;
     mybrick = brick;
     ProgressPanel.Visible = false;
     PasswordPanel.Visible = true;
 }
Exemplo n.º 3
0
 public ImageBrick(Brick brick)
 {
     InitializeComponent();
     returnerror = null;
     mybrick = brick;
     ResizeRedraw = true;
     PrepareVault();
 }
Exemplo n.º 4
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!");
        }
Exemplo n.º 5
0
        private void Disconnect_Click(object sender, EventArgs e)
        {
            if (sender != null)
            {
                Button s = (Button)sender;
                if (s.Text == " Stop Now")
                {
                    searchthread.Abort();
                    s.Width = 93;
                    s.Enabled = false;
                    s.Text = " Disconnect";
                    SearchVia.Enabled = true;
                    Search.Enabled = true;
                    Time.Enabled = true;
                    List.Enabled = true;
                    WriteMessage("Aborted search!");
                    return;
                }
            }

            try
            {
                myBrick.Disconnect();
            }
            catch (NXTNotConnected)
            { }

            myBrick = new Brick();
            Disconnect.Enabled = false;
            List.Visible = true;
            SearchVia.Enabled = true;
            Time.Enabled = true;
            Search.Enabled = true;
            NXTPanel.Visible = false;
            CloseForm.Enabled = true;
            if (updatewaiting)
            {
                Status.Image = global::NXTLibTesterGUI.Properties.Resources.StatusAnnotations_Stop_16xLG_color;
                Status.Text = "       Update Waiting!  Please pair to a brick now!";
                this.TopMost = true;
                Application.DoEvents();
                this.TopMost = false;
            }
            else
            {
                Status.Image = global::NXTLibTesterGUI.Properties.Resources.StatusAnnotations_Help_and_inconclusive_16xLG_color;
                Status.Text = "       Please pair to a brick.";
            }
            Search.Image = global::NXTLibTesterGUI.Properties.Resources.StatusAnnotations_Play_32xLG_color;
            CheckUpdateStatus();
            Search.Text = " Search for NXT";
            WriteMessage("Disconnected successfully!");
        }
Exemplo n.º 6
0
 public abstract void Disconnect(Brick brick);
Exemplo n.º 7
0
 public abstract void Connect(Brick brick);
Exemplo n.º 8
0
        private void _search()
        {
            if (!IsInitialized) { throw new NXTLinkNotInitialized(); }
            _bricklist = new List<Brick>();
            List<Brick> bricks = new List<Brick>();
            lock (commLock)
            {
                BluetoothDeviceInfo[] peers = client.DiscoverDevicesInRange();

                foreach (BluetoothDeviceInfo info in peers)
                {
                    if (info.ClassOfDevice.Value != 2052) { continue; }

                    BluetoothEndPoint ep = new BluetoothEndPoint(info.DeviceAddress, NXT_GUID);
                    //BluetoothSecurity.SetPin(info.DeviceAddress, "1234");
                    BrickInfo _brick = new BrickInfo();
                    _brick.address = info.DeviceAddress.ToByteArray();
                    _brick.name = info.DeviceName;
                    Brick brick = new Brick(this, _brick);
                    bricks.Add(brick);
                }
            }
            _bricklist = bricks;
            return;
        }
Exemplo n.º 9
0
 /// <summary> 
 /// Disconnects from the NXT via Bluetooth.
 /// </summary>
 public override void Disconnect(Brick brick)
 {
     if (!IsConnected) { throw new NXTNotConnected(); }
     lock (commLock)
     {
         client.Close();
         //client.Dispose();
         client = null;
         client = new BluetoothClient();
     }
     return;
 }
Exemplo n.º 10
0
 /// <summary>
 /// <para>This method has no function for an USB connection.</para>
 /// </summary>
 public override void Disconnect(Brick brick)
 {
     return;
 }
Exemplo n.º 11
0
 /// <summary>
 /// <para>Useless when connecting via USB.</para>
 /// </summary>
 public override void Connect(Brick brick)
 {
     if (!IsConnected) { throw new NXTNotConnected(); }
 }
Exemplo n.º 12
0
        /// <summary>
        /// <para>Search for bricks connected via USB.</para>
        /// </summary>
        /// <returns>A list of brick information (returns max 1 brick!).</returns>
        public override List<Brick> Search()
        {
            List<Brick> list = new List<Brick>();
            if (IsConnected)
            {
                BrickInfo _brick = new BrickInfo();
                _brick.address = new byte[6] { 0, 0, 0, 0, 0, 0 };
                _brick.name = "NXT";

                GetDeviceInfoReply reply = GetDeviceInfo();
                _brick.address = reply.Address;
                _brick.name = reply.Name;
                Brick brick = new Brick(this, _brick);
                list.Add(brick);
            }
            else { throw new NXTNoBricksFound(); }
            return list;
        }
Exemplo n.º 13
-1
        /// <summary> 
        /// Connect to the device via Bluetooth.
        /// </summary>
        public override void Connect(Brick brick)
        {
            Initialize();
            if (!IsConnected)
            {
                lock (commLock)
                {
                    BluetoothAddress adr = new BluetoothAddress(brick.brickinfo.address);
                    BluetoothDeviceInfo device = new BluetoothDeviceInfo(adr);
                    BluetoothSecurity.PairRequest(adr, "1234");

                    client.Connect(adr, NXT_GUID);

                    //BluetoothSecurity.RevokePin(adr);
                    //BluetoothSecurity.RemoveDevice(adr);

                }
                if (!IsConnected) { throw new NXTNotConnected(); }
            }
            return;
        }