Exemple #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                this.lblStatus.SetText("Connecting...");

                // Connecting to the NXT.
                this._nxt = new Nxt();
                this._nxt.Connect(this.cboPort.SelectedValue.ToString());

                this.lblStatus.Text = "Connected";

                this.UpdateStatus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        private void btnConnect_Click( object sender, EventArgs e )
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                this.lblStatus.SetText( "Connecting..." );

                // Connecting to the NXT.
                this._nxt = new Nxt();
                this._nxt.Connect( this.cboPort.SelectedValue.ToString() );

                this.lblStatus.Text = "Connected";

            }
            catch( Exception ex )
            {
                MessageBox.Show( ex.Message );
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        void kinect_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage Image = e.ImageFrame.Image;

            byte[] convertedFrame = convertDepthFrame(Image.Bits);
            image2.Source = BitmapSource.Create(Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedFrame, Image.Width * 4);
            byte[] depthFrame32 = new byte[320 * 240 * 4];
            try
            {
                //this.Title = HandLeftX + "," + HandLeftY;
                //if (HandLeftX == 0) { return; }
                cIx.Content = HandLeftX;
                cIy.Content = HandLeftY;

                //if (HandRightX == 0) { return; }
                cDx.Content = HandRightX;
                cDy.Content = HandRightY;

                //jaja no se que hice aqui, mas de rato lo acomodo el punto era q funcionara

                if (flagConexion)
                {
                    this._nxt = new Nxt();
                    this._nxt.Connect("COM7");
                    msjConexion.Text = "Lego Conectado!";

                    flagConexion = false;
                    Motor        = new Thread(new ThreadStart(detenerse));
                    Motor.Start();
                    Thread.Sleep(1000);
                }

                verificarLego();
            }
            catch { }
        }
        private void Connect(string port)
        {
            // change the cursor to waiting
            Cursor.Current = Cursors.WaitCursor;

            mainStatusStrip.BackColor = loadingColor;

            // change bottom label text
            connectionToolStripStatusLabel.Text = "Connecting...";

            // Connecting to the NXT.
            nxt = new Nxt();

            // check for null reference
            if (nxt != null)
            {
                try
                {
                    // Connecting via the selected serial port for communication
                    nxt.Connect(port);
                    // play a tone if there was a successfull connection
                    nxt.PlayTone(700, 200);
                    isConnected = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }

            UpdateStatusControls();

            connectionToolStripStatusLabel.Text = "Connected";

            mainStatusStrip.BackColor = connectedColor;

            Cursor.Current = Cursors.Default;
        }
        void Lego_Initialize()
        {
            if (flagConexion)
            {
                this._nxt = new Nxt();
                this._nxt.Connect("COM18");
                msjConexion.Text = "Lego Conectado!";

                flagConexion = false;
                //Motor = new Thread(new ThreadStart(detenerse));
                //Motor.Start();
                Thread.Sleep(1000);
            }
        }