private static async Task <bool> CheckMotorStatus(IAsyncMotor motor) { try { if ((await motor.SendCommandAsync(Command.GetAxisParameter, 1, CommandParam.Default, 0)).IsSuccess) { return(true); } } catch (TimeoutException) { // Ignored } catch (Exception) { return(false); } try { if (await motor.TrySwitchToBinary()) { return(true); } } catch (Exception) { return(false); } return(false); }
public async Task Test(int param) { await Task.WhenAll(_handler1.ReturnToOriginAsync(), _handler2.ReturnToOriginAsync()); var positions = await Task.WhenAll(_handler1.GetPositionAsync(), _handler2.GetPositionAsync()); CollectionAssert.AreEquivalent(new[] { 0, 0 }, positions); var responses = await Task.WhenAll( _handler1.SendCommandAsync(Command.MoveToPosition, param, CommandParam.MoveType.Absolute), _handler2.SendCommandAsync(Command.MoveToPosition, param, CommandParam.MoveType.Absolute)); CollectionAssert.AreEquivalent(new[] { true, true }, responses.Select(x => x.Status == ReturnStatus.Success)); await Task.WhenAll(_handler1.WaitForPositionReachedAsync(), _handler2.WaitForPositionReachedAsync()); positions = await Task.WhenAll(_handler1.GetPositionAsync(), _handler2.GetPositionAsync()); CollectionAssert.AreEquivalent(new[] { param, param }, positions); await Task.WhenAll(_handler1.ReturnToOriginAsync(), _handler2.ReturnToOriginAsync()); positions = await Task.WhenAll(_handler1.GetPositionAsync(), _handler2.GetPositionAsync()); CollectionAssert.AreEquivalent(new[] { 0, 0 }, positions); }
public async Task Test_Rotation() { // ReSharper disable once RedundantArgumentDefaultValue var reply = await _motor.SendCommandAsync(Command.MoveToPosition, 10000, CommandParam.MoveType.Absolute); Assert.AreEqual(ReturnStatus.Success, reply.Status); await Task.Delay(TimeSpan.FromMilliseconds(500)); reply = await _motor.SendCommandAsync(Command.GetAxisParameter, 1, CommandParam.Default); Assert.AreEqual(ReturnStatus.Success, reply.Status); Assert.AreEqual(10000, reply.ReturnValue); await _motor.ReturnToOriginAsync(CancellationToken.None); reply = await _motor.SendCommandAsync(Command.GetAxisParameter, 1, CommandParam.Default); Assert.AreEqual(ReturnStatus.Success, reply.Status); Assert.AreEqual(0, reply.ReturnValue); }