예제 #1
0
    public static async Task Main(string[] args)
    {
        Console.WriteLine("Opening connection to Mindstorms EV3 brick using USB");

        //using (BluetoothCommunication communication = new BluetoothCommunication("COM0"))
        //using (NetworkCommunication communication = new NetworkCommunication("0.0.0.0"))
        using (UsbCommunication communication = new UsbCommunication())
            using (MindstormsClient <UsbCommunication> client = new MindstormsClient <UsbCommunication>(communication))
            {
                Console.WriteLine("Connecting");
                await client.ConnectAsync();

                Console.WriteLine("Direct command");
                await client.TurnMotorAtPowerForTimeAsync(OutputPort.A, 50, 3000u, false);

                System.Console.WriteLine("System command");
                await client.PlayToneAsync(50, 5000, 500);

                System.Console.WriteLine("Batch commands");
                var command = new Command();
                command.TurnMotorAtPowerForTime(OutputPort.A, 50, 2500, false);
                command.PlayTone(50, 1000, 5000);
                await client.SendCommandAsync(command);
            }

        System.Console.WriteLine("Done...");
    }
        /// <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;
            }
        }
예제 #3
0
        public static void Main(string[] _)
        {
            var comm =
                new UsbCommunication("EV3OLAV");
            var responseManager =
                new ResponseManager();
            var brick =
                new Brick(comm, responseManager);

            var obs =
                brick
                .Connect()
                .Select(x => x.Ports[InputPort.Three])
                .Do(port => Console.WriteLine($"Sensor in port 3: ({port.Name}, {port.Type}, {port.RawValue})"));

            var command =
                brick.CreateCommand(CommandType.DirectNoReply, 0, 0);

            command.StartMotor(OutputPort.A);
            command.TurnMotorAtPowerForTime(OutputPort.A, 75, 1000, false);

            var subscription =
                brick
                .SendCommand(command)
                .Do(__ => Console.WriteLine("Waiting for command to finish..."))
                .Subscribe();

            using (subscription)
                using (obs.Subscribe())
                {
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                returnType = new BluetoothCommunication(ConnControl.GetComportNumber());
                break;

            case ConnectionType.Usb:
                returnType = new UsbCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
예제 #6
0
        private ICommunication CreateConnection()
        {
            ICommunication returnType = null;

            switch (ConnControl.GetConnectionType())
            {
            case ConnectionType.Bluetooth:
                //returnType = new BluetoothCommunication(ConnControl.GetComportNumber());
                //break;
                throw new NotSupportedException("Bluetooth is not supported at the moment");

            case ConnectionType.Usb:
                returnType = new UsbCommunication();
                break;

            case ConnectionType.WiFi:
                returnType = new NetworkCommunication(ConnControl.GetIpAddress());
                break;
            }

            return(returnType);
        }
예제 #7
0
        /// <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);
        }