2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.System.Usb
22 /// USB Control Endpoint class.
24 /// <since_tizen> 4 </since_tizen>
25 public class UsbControlEndpoint : UsbEndpoint
27 private readonly UsbDevice _device;
29 internal UsbControlEndpoint(UsbDevice device) : base(null, null)
35 /// Gets number of this endpoint.
37 /// <feature>http://tizen.org/feature/usb.host</feature>
38 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
39 /// <since_tizen> 4 </since_tizen>
49 /// Gets direction of this endpoint.
51 /// <feature>http://tizen.org/feature/usb.host</feature>
52 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
53 /// <since_tizen> 4 </since_tizen>
54 public new EndpointDirection Direction
58 return EndpointDirection.InOut;
63 /// Gets max packet size of given endpoint.
65 /// <feature>http://tizen.org/feature/usb.host</feature>
66 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
67 /// <since_tizen> 4 </since_tizen>
68 public new int MaxPacketSize
72 _device.ThrowIfDisposed();
73 return Interop.NativeGet<int>(_device._handle.GetMaxPacketSize0);
78 /// Performs a control transaction on endpoint zero for this device.
80 /// <param name="requestType">bmRequestType type field for the setup packet.</param>
81 /// <param name="request">bRequest field for the setup packet.</param>
82 /// <param name="value">wValue field for the setup packet.</param>
83 /// <param name="index">wIndex field for the setup packet.</param>
84 /// <param name="data">Suitably-sized data buffer for either input or output, (depending on direction bits within bmRequestType).</param>
85 /// <param name="length">wLength field for the setup packet. The data buffer should be at least this size.</param>
86 /// <param name="timeout">
87 /// Time (in milliseconds) that this function should wait for, before giving up due to no response being received
88 /// (for an unlimited timeout 0 value should be used).
90 /// <returns>Transferred Number of transferred bytes.</returns>
91 /// <feature>http://tizen.org/feature/usb.host</feature>
92 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
93 /// <exception cref="InvalidOperationException">Throws exception if device is disconnected or not opened for operation.</exception>
94 /// <exception cref="TimeoutException">Throws exception if transfer timed-out.</exception>
95 /// <since_tizen> 4 </since_tizen>
96 public int Transfer(byte requestType, byte request, ushort value, ushort index, byte[] data, ushort length, uint timeout)
98 _device.ThrowIfDisposed();
99 if (_device.IsOpened == false) throw new InvalidOperationException("Device must be opened for operation first");
102 var err = _device._handle.ControlTransfer(requestType, request, value, index, data, length, timeout, out transferred);
103 err.ThrowIfFailed("Failed during control transfer");