public override async Task SubscribeToUpdatesAsyncInternal(ButtplugDeviceReadOptions aOptions)
 {
     if (!_indexedChars.ContainsKey(aOptions.Endpoint))
     {
         throw new ButtplugDeviceException(BpLogger, $"Endpoint {aOptions.Endpoint} does not exist on device {Name}.");
     }
     await SubscribeToUpdatesAsync(_indexedChars[aOptions.Endpoint]).ConfigureAwait(false);
 }
예제 #2
0
        public override Task <byte[]> ReadValueAsyncInternal(ButtplugDeviceReadOptions aOptions,
                                                             CancellationToken aToken = default(CancellationToken))
        {
            // todo This doesn't test endpoints!
            var value = ExpectedRead[ExpectedRead.Keys.ToArray()[0]].ElementAt(0);

            ExpectedRead[ExpectedRead.Keys.ToArray()[0]].RemoveAt(0);
            return(Task.FromResult(value));
        }
        public override async Task <byte[]> ReadValueAsyncInternal(ButtplugDeviceReadOptions aOptions,
                                                                   CancellationToken aToken = default(CancellationToken))
        {
            if (!_indexedChars.ContainsKey(aOptions.Endpoint))
            {
                throw new ButtplugDeviceException(BpLogger,
                                                  "ReadValue using indexed characteristics called with invalid index");
            }

            return(await ReadValueAsync(_indexedChars[aOptions.Endpoint], aToken).ConfigureAwait(false));
        }
예제 #4
0
        public override async Task <byte[]> ReadValueAsyncInternal(ButtplugDeviceReadOptions aOptions,
                                                                   CancellationToken aToken = default(CancellationToken))
        {
            // Both Hid and Serial only have one incoming endpoint.
            if (aOptions.Endpoint != Endpoints.Rx)
            {
                throw new ButtplugDeviceException(BpLogger, "HidDevice doesn't support any read endpoint except the default.");
            }

            var arr  = new byte[64];
            var read = await _stream.ReadAsync(arr, 0, arr.Length, aToken).ConfigureAwait(false);

            return(arr);
        }
        public override async Task <byte[]> ReadValueAsyncInternal(ButtplugDeviceReadOptions aOptions,
                                                                   CancellationToken aToken = default(CancellationToken))
        {
            if (!_device.CanRead)
            {
                return(new byte[] { });
            }

            var oldTimeout = 0;

            if (aOptions.Timeout < int.MaxValue)
            {
                oldTimeout          = _device.ReadTimeout;
                _device.ReadTimeout = (int)aOptions.Timeout;
            }

            //var bytesToRead = _device.Length;
            var input      = new byte[aOptions.ReadLength];
            var readLength = 0;

            try
            {
                while (readLength < aOptions.ReadLength)
                {
                    readLength += await _device.ReadAsync(input, readLength, (int)aOptions.ReadLength - readLength);
                }
            }
            finally
            {
                if (aOptions.Timeout < int.MaxValue)
                {
                    _device.ReadTimeout = oldTimeout;
                }
            }

            return(input);
        }
 public override Task SubscribeToUpdatesAsyncInternal(ButtplugDeviceReadOptions aOptions)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public override Task SubscribeToUpdatesAsyncInternal(ButtplugDeviceReadOptions aOptions)
 {
     return(Task.CompletedTask);
 }
 public override Task <byte[]> ReadValueAsyncInternal(ButtplugDeviceReadOptions aOptions,
                                                      CancellationToken aToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }