/// <summary> /// Verbindet mit dem Lego Brink, nach auswählen der Verbindung /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonVerbinden_Click(object sender, RoutedEventArgs e) { ComboBoxItem aComboBoxItem = comboBoxCommunication1.SelectedItem as ComboBoxItem; if (aComboBoxItem.Content.ToString() == "USB") { UsbCommunication aUsbCommunication = new UsbCommunication(); brick = new Brick(aUsbCommunication, true); } else { BluetoothCommunication aBluetoothCommunication1 = new BluetoothCommunication(comboBoxComPort1.SelectedValue.ToString()); brick = new Brick(aBluetoothCommunication1, true); } // --- try { aTask = brick.ConnectAsync(); lblStatusBarMessage1.Text = aTask.Status.ToString(); if (aTask.Status != TaskStatus.Faulted) { gridBottom1.Visibility = Visibility.Visible; } } catch (Exception ex) { lblStatusBarMessage1.Text = "Exception: " + ex.Message; } }
public void ItCreatesABrick() { var comm = new BluetoothCommunication("COM4"); var controller = new BrickController(comm); Assert.IsNotNull(controller.Brick); }
public void ItCanConnect() { var comm = new BluetoothCommunication("COM4"); var controller = new BrickController(comm); controller.Connect(); }
static async void MainAsync() { var conType = new BluetoothCommunication("COM5"); if (conType != null) { _brick = new Brick(conType, true); _brick.BrickChanged += _brick_BrickChanged; try { await _brick.ConnectAsync(); var output = OutputPort.A; await _brick.DirectCommand.TurnMotorAtPowerForTimeAsync(output, 50, 0, 2000, 0, false); Thread.Sleep(3000); _brick.Disconnect(); } catch (Exception ex) { Console.Write(ex.Message); _brick.Disconnect(); } } }
public async Task ConnectAsync() { _ev3Comm = new BluetoothCommunication(SelectedDevice); await _ev3Comm.ConnectAsync(); _ev3Comm.ReportReceived += BaseCommReportReceived; }
public async Task ItCanTurnMotor() { var comm = new BluetoothCommunication("COM4"); var controller = new BrickController(comm); controller.Connect(); await controller.TurnMotorAsync(OutputPort.C, 50, 1); }
private ICommunication CreateConnection() { ICommunication returnType = null; returnType = new BluetoothCommunication(DeviceId); //returnType = new UsbCommunication(); //returnType = new NetworkCommunication(ConnControl.GetIpAddress()); return(returnType); }
public void ItCanSendTankCommands() { var comm = new BluetoothCommunication("COM4"); var controller = new BrickController(comm); Console.WriteLine("Connecting..."); controller.Connect(); controller.TankMove(50, 50, 2); controller.TankMove(50, -50, 2); controller.TankMove(-50, -50, 2); }
private ICommunication CreateConnection() { ICommunication returnType = null; switch (ConnControl.GetConnectionType()) { case ConnectionType.Bluetooth: returnType = new BluetoothCommunication(); break; case ConnectionType.WiFi: returnType = new NetworkCommunication(ConnControl.GetIpAddress()); break; } return(returnType); }
private async void BoutonConnexion(object sender, RoutedEventArgs e) { String contenuCombo = mComboBoxTypeConnexion.SelectedItem.ToString(); ICommunication communication; String mode = null; // Trouver le mode de connexion switch (contenuCombo) { case BT: communication = new BluetoothCommunication(mTextBoxComport.Text); mode = BT; break; case USB: communication = new UsbCommunication(); mode = USB; break; default: communication = null; break; } // Connexion if (communication != null) { GestionRobot.getInstance().brick = new Brick(communication, true); try { await GestionRobot.getInstance().brick.ConnectAsync(); TextBlockStatus.Text = String.Format("Robot Lego : Connecté en : {0}", mode); Close(); } catch (Exception) { MessageBox.Show("Could not connect", "Error", MessageBoxButton.OK); } } else { MessageBox.Show("Invalid connection type for this device", "Error", MessageBoxButton.OK); } }
private async void BrickComport_SelectionChanged(object sender, SelectionChangedEventArgs e) { var comboBox = (ComboBox)sender; var brickIndex = Convert.ToInt32(comboBox.Tag); if ((string)comboBox.SelectedItem == "None") { return; } comboBox.IsEnabled = false; var connection = new BluetoothCommunication((string)comboBox.SelectedItem); var brick = new Brick(connection); try { await brick.ConnectAsync(); brick.BrickChanged += Brick_BrickChanged; BrickManager.Bricks[brickIndex].Brick = brick; BrickManager.Bricks[brickIndex].AimedColor = GetColors(brickIndex).ToArray(); await brick.DirectCommand.CleanUIAsync(); await brick.DirectCommand.SelectFontAsync(FontType.Large); await brick.DirectCommand.DrawTextAsync(Color.Foreground, 0, 20, "Brick " + (brickIndex + 1)); await brick.DirectCommand.DrawTextAsync(Color.Foreground, 0, 60, GetColors(brickIndex).First().ToString()); await brick.DirectCommand.UpdateUIAsync(); brick.Ports[InputPort.One].SetMode(ColorMode.Color); var image = GetImage(BrickManager.Bricks[brickIndex]); image.Effect = null; brick.BrickChanged += Brick_BrickChanged1; MessageBox.Show("Connection Successful!"); } catch (Exception ex) { MessageBox.Show("Connetion Failed!"); comboBox.IsEnabled = true; } }
static void Main() { var comm = new BluetoothCommunication("COM4"); var controller = new BrickController(comm); Task.Run(async() => { await controller.Connect(); for (var i = 0; i < 100; i++) { while (controller.UltrasonicRange > 10) { Console.WriteLine(controller.UltrasonicRange); controller.TankMove(50, 50, 0.5); } controller.TankMove(50, -50, 1); } }); }
/// <summary> /// Entry point. /// </summary> /// <param name="args">Command line args.</param> public static void Main(string[] args) { Console.WriteLine("Initializing FunkinCTRL..."); ICommunication ic; Console.WriteLine("Select communication method:\n-- For USB, press 0\n-- For Bluetooth, press 1"); switch (Console.ReadKey(true).KeyChar) { case '1': // TODO: Find a better implementation. Console.WriteLine("Enter the COM-port data."); ic = new BluetoothCommunication(Console.ReadLine()); break; case '0': ic = new UsbCommunication(); break; default: Console.WriteLine("Unrecognized input, selecting USB communication."); ic = new UsbCommunication(); break; } Console.WriteLine("Connecting to EV3 controller..."); b = new Brick(ic, true); TimeSpan ts = new TimeSpan(TimeSpan.TicksPerSecond / RequestFrequency); b.ConnectAsync(ts); Thread.Sleep(2000); b.BatchCommand.PlayTone(5, 440, 300); b.BatchCommand.SendCommandAsync(); b.ConnectAsync(ts); Thread.Sleep(1000); if (b.Ports[InputPort.D].Type != DeviceType.MMotor || b.Ports[InputPort.One].Type != DeviceType.Touch || b.Ports[InputPort.Four].Type != DeviceType.Infrared) { Console.WriteLine("Unable to connect to controller or controller layout is incorrect."); Console.ReadKey(true); Environment.Exit(-1); } Console.WriteLine("Setup complete. Press center button on your controller to continue."); while (!b.Buttons.Enter) { } while (!b.Buttons.Down) { Single touch = b.Ports[InputPort.One].SIValue; Single ir = b.Ports[InputPort.Four].SIValue; Single motor = b.Ports[InputPort.D].SIValue; String title = String.Format("FunkinCTRL -- Controls engaged // D -- {0}:{1}, #1 -- {2}:{3}, #4 -- {4}:{5} // Press DOWN button to exit loop.", b.Ports[InputPort.D].Type, motor, b.Ports[InputPort.One].Type, touch, b.Ports[InputPort.Four].Type, ir); Console.Title = title; ParseControllerInputs(touch, ir); EscapeKey.IsDown = b.Buttons.Up; EnterKey.IsDown = b.Buttons.Enter; } b.Disconnect(); Console.Error.WriteLine("Program ended."); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.myview); var btnForward = FindViewById <Button>(Resource.Id.myview_btnforward); var btnBackward = FindViewById <Button>(Resource.Id.myview_btnbackward); var btnLeft = FindViewById <Button>(Resource.Id.myview_btnleft); var btnRight = FindViewById <Button>(Resource.Id.myview_btnright); var btnGo = FindViewById <Button>(Resource.Id.myview_btngo); var btnStop = FindViewById <Button>(Resource.Id.myview_btnstop); // var communication = new BluetoothCommunication(@"PPAP09"); var brick = new Brick(communication); var command = new DirectCommand(brick); brick.ConnectAsync(); communication.ReportReceived += (object sender, ReportReceivedEventArgs e) => { WriteLine("Connected"); Connected = true; }; brick.Ports[InputPort.One].SetMode(ColorMode.ReflectiveRgb); brick.Ports[InputPort.One].PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { WriteLine(brick.Ports[InputPort.One].SIValue); }; btnForward.Click += async(sender, e) => { WriteLine("前"); IsForward = true; if (Connected) { // 兩輪向前 await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed); } }; btnBackward.Click += async(sender, e) => { WriteLine("後"); IsForward = false; if (Connected) { // 兩輪向後 await command.TurnMotorAtSpeedAsync(OutputPort.A, -Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, -Speed); } }; btnLeft.Click += async(sender, e) => { WriteLine("左"); if (Connected) { // 左輪向後,右輪向前 await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed); } }; btnRight.Click += async(sender, e) => { WriteLine("右"); if (Connected) { // 左輪向前,右輪向後 await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed); } }; btnGo.Click += async(sender, e) => { WriteLine("油門"); Speed += 5; if (Speed >= 50) { Speed = 50; } if (Connected) { if (IsForward) { await command.TurnMotorAtSpeedAsync(OutputPort.A, Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, Speed); } else { await command.TurnMotorAtSpeedAsync(OutputPort.A, -Speed); await command.TurnMotorAtSpeedAsync(OutputPort.B, -Speed); } } }; btnStop.Click += async(sender, e) => { WriteLine("煞車"); if (Connected) { // 兩輪停止 await command.StopMotorAsync(OutputPort.A, true); await command.StopMotorAsync(OutputPort.B, true); } }; Connected = false; IsForward = true; Speed = 20; }