예제 #1
0
        private void TryToConnect(object sender, RoutedEventArgs e)
        {
            Overlay.Show("Connecting");

            ConnControl.Visibility = Visibility.Visible;

            var conType = CreateConnection();

            Dispatcher.Invoke(new Action(async () =>
            {
                if (conType != null)
                {
                    _brick = new Brick(conType, true);
                    _brick.BrickChanged += _brick_BrickChanged;
                    try
                    {
                        await _brick.ConnectAsync();
                        ConnControl.Visibility = Visibility.Collapsed;

                        ConnTypeRun.Text = ConnControl.GetConnectionType().ToString();

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not connect", "Error", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid connection type for this device", "Error", MessageBoxButton.OK);
                }

                Overlay.Hide();
            }));
        }
예제 #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     _brick = new Brick(new BluetoothCommunication("COM6"));
     _brick.BrickChanged += _brick_BrickChanged;
     _brick.ConnectAsync();
     _brick.DirectCommand.PlayToneAsync(10, 1000, 300);
 }
예제 #3
0
        public async Task Connect()
        {
            LegoBrick = new Brick(new BluetoothCommunication(), true);
            LegoBrick.BrickChanged += LegoBrick_BrickChanged;
            await LegoBrick.ConnectAsync();
            await LegoBrick.DirectCommand.PlayToneAsync(100, 40000, 300);

        }
        public void Update(Brick brick)
        {
            _sensorType = brick.Ports[BrickInputPort].Type;

            SensorDataStackPanel.Visibility = IsInvalidSensorOrWrongPort() ? Visibility.Collapsed : Visibility.Visible;
           
            RawRun.Text = brick.Ports[BrickInputPort].RawValue.ToString(CultureInfo.InvariantCulture);
            SiRun.Text = brick.Ports[BrickInputPort].SIValue.ToString(CultureInfo.InvariantCulture);
            PercentageRun.Text = brick.Ports[BrickInputPort].PercentValue.ToString(CultureInfo.InvariantCulture);

            UpdateUx();
        }
예제 #5
0
 private async void Connect_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         _brick = new Brick(new BluetoothCommunication((string)Ports.SelectedItem));
         //_brick = new Brick(new UsbCommunication());
         //_brick = new Brick(new NetworkCommunication("192.168.2.237"));
         _brick.BrickChanged += brick_BrickChanged;
         await _brick.ConnectAsync();
         Output.Text = "Connected";
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to connect: " + ex);
     }
 }
예제 #6
0
        private static async void StartLego()
        {
            _brick = new Brick(new BluetoothCommunication("COM6"));
            _brick.BrickChanged += _brick_BrickChanged;

            Console.WriteLine("Connecting...");
            try {
                await _brick.ConnectAsync();
            }
            catch
            {
                System.Console.WriteLine("Error...!!");
            }   
         
            
            await _brick.DirectCommand.PlayToneAsync(100, 40000, 300);

            System.Console.WriteLine("Connected...");
        }
예제 #7
0
        private async void Connect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _brick = new Brick(new BluetoothCommunication());
                //_brick = new Brick(new NetworkCommunication("192.168.2.237"));
                _brick.BrickChanged += brick_BrickChanged;

                //Conect
                await _brick.ConnectAsync();
                //Connected
                Output.Text = "Connected";
            }
            catch (Exception ex)
            {
                //Error message     
                MessageDialog msgdialog = new MessageDialog("Failed to connect: " + ex);
                await msgdialog.ShowAsync();
            }
        }
예제 #8
0
        static async Task Test()
        {
            //_brick = new Brick(new UsbCommunication());
            _brick = new Brick(new BluetoothCommunication("COM6"));
            //_brick = new Brick(new NetworkCommunication("192.168.2.237"));

            _brick.BrickChanged += _brick_BrickChanged;

            System.Console.WriteLine("Connecting...");
            await _brick.ConnectAsync();

            // volume (0-100), frequency, duration
            await _brick.DirectCommand.PlayToneAsync(100, 40000, 300);

            //System.Console.WriteLine("Connected...Turning motor...");

            

            ////mueve la rueda derecha
            //await _brick.DirectCommand.TurnMotorAtSpeedForTimeAsync(OutputPort.C, 0x50, 1000, false);

            //System.Console.WriteLine("Motor turned...beeping...");
            //await _brick.DirectCommand.PlayToneAsync(100, 50000, 500);

            //System.Console.WriteLine("Beeped...done!");

            System.Console.WriteLine("Getting result...");

            //Timer tmr = new Timer();           
            //tmr.Interval = 3000; // 6 second
            //tmr.Elapsed += Tmr_Elapsed;
            //tmr.Start(); // The countdown is launched!


           


        }
예제 #9
0
		internal Command(Brick brick) : this(CommandType.DirectNoReply)
		{
			_brick = brick;
		}
예제 #10
0
        public void Update(Brick brick)
        {
            _motorType = brick.Ports[BrickInputPort].Type;

            UpdateUx();
        }
예제 #11
0
		internal SystemCommand(Brick brick)
		{
			_brick = brick;
		}
예제 #12
0
		internal DirectCommand(Brick brick)
		{
			_brick = brick;
		}