Example #1
0
        private async void QueueListener_DoWork(object sender, DoWorkEventArgs e)
        {
            while (_worker != null && !_worker.CancellationPending)
            {
                try
                {
                    var result = await ServiceBusHelper.ReceiveAndDeleteMessage();

                    var json   = JsonObject.Parse(result);
                    var action = json.GetNamedString("action");

                    switch (action)
                    {
                    case "Stop":
                        _twoMotorsDriver.Stop();
                        _isMovingForward = false;
                        break;

                    case "MoveForward":
                        _twoMotorsDriver.MoveForward();
                        _isMovingForward = true;
                        break;

                    case "MoveBack":
                        _twoMotorsDriver.MoveBackward();
                        _isMovingForward = false;
                        break;

                    case "Turn":
                        var angle = int.Parse(json.GetNamedString("param"));

                        await _uln2003Driver.TurnAsync(angle, TurnDirection.Right);

                        //await _twoMotorsDriver.TurnRightAsync(angle);

                        _isMovingForward = false;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    await WriteLog(ex.Message);
                }
                await Task.Delay(1000);
            }
        }
Example #2
0
        private async void DoWork(object sender, DoWorkEventArgs e)
        {
            while (_worker != null && !_worker.CancellationPending)
            {
                var result = await ServiceBusHelper.ReceiveAndDeleteMessage();

                switch (result)
                {
                case "SMR":
                    await _uln2003Driver.TurnAsync(90, TurnDirection.Right);

                    break;

                case "SML":
                    await _uln2003Driver.TurnAsync(90, TurnDirection.Left);

                    break;

                case "F":
                    _twoMotorsDriver.MoveForward();
                    isMovingForward = true;
                    break;

                case "S":
                    _twoMotorsDriver.Stop();
                    isMovingForward = false;
                    break;

                case "R":
                    await _twoMotorsDriver.TurnRightAsync();

                    isMovingForward = false;
                    break;

                case "L":
                    await _twoMotorsDriver.TurnLeftAsync();

                    isMovingForward = false;
                    break;

                case "B":
                    _twoMotorsDriver.MoveBackward();
                    isMovingForward = false;
                    break;

                case "TR":
                    await _twoMotorsDriver.TurnRightAsync(45);

                    isMovingForward = false;
                    break;

                case "TL":
                    await _twoMotorsDriver.TurnLeftAsync(45);

                    isMovingForward = false;
                    break;

                case "BR":
                    await _twoMotorsDriver.TurnRightAsync(100);

                    isMovingForward = false;
                    break;

                case "BL":
                    await _twoMotorsDriver.TurnLeftAsync(100);

                    isMovingForward = false;
                    break;
                }

                await Task.Delay(1000);
            }
        }