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(); })); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); _output = FindViewById<TextView>(Resource.Id.output); _ports = FindViewById<TextView>(Resource.Id.ports); FindViewById<Button>(Resource.Id.connect).Click += connect_Click; FindViewById<Button>(Resource.Id.disconnect).Click += disconnect_Click; FindViewById<Button>(Resource.Id.playTone).Click += playTone_Click; FindViewById<Button>(Resource.Id.getFwVersion).Click += getFwVersion_Click; FindViewById<Button>(Resource.Id.turnMotorAtPower).Click += turnMotorAtPower_Click; FindViewById<Button>(Resource.Id.turnMotorAtSpeed).Click += turnMotorAtSpeed_Click; FindViewById<Button>(Resource.Id.stepMotorAtPower).Click += stepMotorAtPower_Click; FindViewById<Button>(Resource.Id.stepMotorAtSpeed).Click += stepMotorAtSpeed_Click; FindViewById<Button>(Resource.Id.timeMotorAtPower).Click += timeMotorAtPower_Click; FindViewById<Button>(Resource.Id.timeMotorAtSpeed).Click += timeMotorAtSpeed_Click; FindViewById<Button>(Resource.Id.stopMotor).Click += stopMotor_Click; FindViewById<Button>(Resource.Id.setLed).Click += setLed_Click; FindViewById<Button>(Resource.Id.playSound).Click += playSound_Click; FindViewById<Button>(Resource.Id.draw).Click += draw_Click; FindViewById<Button>(Resource.Id.batchNoReply).Click += batchNoReply_Click; FindViewById<Button>(Resource.Id.batchReply).Click += batchReply_Click; _brick = new Brick(new BluetoothCommunication()); //_brick = new Brick(new NetworkCommunication("192.168.2.237")); _brick.BrickChanged += brick_BrickChanged; }
private async void Window_Loaded(object sender, RoutedEventArgs e) { _brick = new Brick(new BluetoothCommunication("COM6")); _brick.BrickChanged += _brick_BrickChanged; await _brick.ConnectAsync(); await _brick.DirectCommand.PlayToneAsync(100, 3, 300); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { // TODO: Update port value with the connected port on your machine _brick = new Brick(new BluetoothCommunication("COM6")); _brick.BrickChanged += _brick_BrickChanged; await _brick.ConnectAsync(); await _brick.DirectCommand.SetMotorPolarity(OutputPort.B | OutputPort.C, Polarity.Backward); await _brick.DirectCommand.StopMotorAsync(OutputPort.All, false); }
// Stuff that happens when the program is loaded private async void Grid_Loaded(object sender, RoutedEventArgs e) { //connect to brick via bluetooth _brick = new Brick(new BluetoothCommunication("COM3")); _brick.BrickChanged += _brick_BrickChanged; await _brick.ConnectAsync(); await _brick.DirectCommand.PlayToneAsync(50, 1000, 300); // Add comma seperated titles to list LogList.Add("buttonpressed,xcoordinate,ycoordinate"); }
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(); }
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; await _brick.ConnectAsync(); Output.Text = "Connected"; } catch(Exception ex) { MessageBox.Show("Failed to connect: " + ex); } }
static async Task Test() { _brick = new Brick(new UsbCommunication()); //_brick = new Brick(new BluetoothCommunication("COM5")); //_brick = new Brick(new NetworkCommunication("192.168.2.237")); _brick.BrickChanged += _brick_BrickChanged; System.Console.WriteLine("Connecting..."); await _brick.ConnectAsync(); System.Console.WriteLine("Connected...Turning motor..."); await _brick.DirectCommand.TurnMotorAtSpeedForTimeAsync(OutputPort.A, 0x50, 1000, false); System.Console.WriteLine("Motor turned...beeping..."); await _brick.DirectCommand.PlayToneAsync(0x50, 5000, 500); System.Console.WriteLine("Beeped...done!"); }
private async void TryToConnect(object sender, RoutedEventArgs e) { Overlay.Show("Connecting"); //ApplicationBar.IsVisible = false; ConnControl.Visibility = Visibility.Visible; var conType = CreateConnection(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 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(); //ApplicationBar.IsVisible = true; } catch (Exception) { new MessageDialog("Could not connect", "Error").ShowAsync(); } } else { MessageDialog dialog = new MessageDialog("Invalid connection type for this device", "Error"); await dialog.ShowAsync(); } Overlay.Hide(); }); }
internal Command(Brick brick) : this(CommandType.DirectNoReply) { _brick = brick; }
internal DirectCommand(Brick brick) { _brick = brick; }
public void Update(Brick brick) { _motorType = brick.Ports[BrickInputPort].Type; UpdateUx(); }
public RobotController(RobotData data) { _data = data; _brick = new Brick(new BluetoothCommunication()); _brick.BrickChanged += _brick_BrickChanged; }
/************************* * METHODS *************************/ /* * SetUpBrick prepares the Lego brick to send and reveive signals. */ private async void SetUpBrick() { //System.Console.WriteLine("\nIn SetUpBrick()"); _brick = new Brick(new BluetoothCommunication("COM4")); _brick.BrickChanged += _brick_BrickChanged; await _brick.ConnectAsync(); await _brick.DirectCommand.PlayToneAsync(100, 1000, 300); await _brick.DirectCommand.SetMotorPolarity(OutputPort.B | OutputPort.C, Polarity.Forward); await _brick.DirectCommand.StopMotorAsync(OutputPort.All, false); _brick.Ports[InputPort.One].SetMode(ColorMode.Reflective); //System.Console.WriteLine("Leaving SetUpBrick()\n"); }
private async void ConnectClick(object sender, RoutedEventArgs e) { if (!_connected) { _brick = new Brick(new BluetoothCommunication("COM3")); _brick.BrickChanged += _brick_BrickChanged; try { await _brick.ConnectAsync(); await _brick.DirectCommand.PlayToneAsync(5, 1000, 300); buttonConnect.Background = Brushes.LightGreen; _connected = true; stackControls.Visibility = Visibility.Visible; buttonConnect.Content = "Disconnect"; //setmode } catch (Exception) { buttonConnect.Background = Brushes.OrangeRed; MessageBox.Show("No connection :("); _connected = false; stackControls.Visibility = Visibility.Hidden; } } else { _brick.DirectCommand.PlayToneAsync(7, 200, 300); _brick.Disconnect(); buttonConnect.Background = Brushes.OrangeRed; buttonConnect.Content = "Reconnect"; _connected = false; stackControls.Visibility = Visibility.Hidden; } }
internal SystemCommand(Brick brick) { _brick = brick; }
internal Command(Brick brick) : this(CommandType.DirectReply) { _brick = brick; }