예제 #1
0
        public static async Task <USBDevice> SelectConfiguration(this USBDevice device, byte configuration)
        {
            var updatedDevice = await device.USB.JSRuntime.InvokeAsync <USBDevice>(SELECT_CONFIGURATION_METHOD, device, configuration);

            updatedDevice.AttachUSB(device.USB);
            return(updatedDevice);
        }
예제 #2
0
        public static async Task <USBDevice> ClaimInterface(this USBDevice device, byte interfaceNumber)
        {
            var updatedDevice = await device.USB.JSRuntime.InvokeAsync <USBDevice>(CLAIM_INTERFACE_METHOD, device, interfaceNumber);

            updatedDevice.AttachUSB(device.USB);
            return(updatedDevice);
        }
예제 #3
0
        public static async Task <USBDevice> Reset(this USBDevice device)
        {
            var updatedDevice = await device.USB.JSRuntime.InvokeAsync <USBDevice>(RESET_DEVICE_METHOD, device);

            updatedDevice.AttachUSB(device.USB);
            return(updatedDevice);
        }
예제 #4
0
        public async Task <USBDevice> RequestDevice(USBDeviceRequestOptions options = null)
        {
            var internalOptions = new _USBDeviceRequestOptions();

            if (options != null)
            {
                internalOptions.filters =
                    options.Filters.Select(f =>
                                           new _USBDeviceFilter
                {
                    classCode    = f.ClassCode,
                    productId    = f.ProductId,
                    protocolCode = f.ProtocolCode,
                    serialNumber = f.SerialNumber,
                    subClassCode = f.SubClassCode,
                    vendorId     = f.VendorId
                }).ToList();
            }
            else
            {
                internalOptions.filters = _emptyFilters;
            }

            USBDevice device = null;

            try
            {
                device = await JSRuntime.Current.InvokeAsync <USBDevice>(REQUEST_DEVICE_METHOD, internalOptions);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().Message);
            }
            return(device);
        }
예제 #5
0
        public static async Task <USBDevice> SelectAlternateInterface(this USBDevice device, byte interfaceNumber, byte alternateSetting)
        {
            var updatedDevice = await device.USB.JSRuntime.InvokeAsync <USBDevice>(SELECT_ALTERNATE_INTERFACE_METHOD, device, interfaceNumber, alternateSetting);

            updatedDevice.AttachUSB(device.USB);
            return(updatedDevice);
        }
예제 #6
0
        public static async Task <USBDevice> ClearHalt(this USBDevice device, string direction, byte endpointNumber)
        {
            var updatedDevice = await device.USB.JSRuntime.InvokeAsync <USBDevice>(CLEAR_HALT_METHOD, device, direction, endpointNumber);

            updatedDevice.AttachUSB(device.USB);
            return(updatedDevice);
        }
예제 #7
0
 public static Task <USBInTransferResult> TransferIn(this USBDevice device, USBEndpoint endpoint, long length)
 {
     if (endpoint == null)
     {
         throw new ArgumentNullException(nameof(endpoint));
     }
     return(device.TransferIn(endpoint.EndpointNumber, length));
 }
예제 #8
0
파일: USB.cs 프로젝트: vertonghenb/WebUSB
 public Task Disconnected(USBDevice device)
 {
     if (this.OnDisconnect != null &&
         this.OnDisconnect.GetInvocationList().Length > 0)
     {
         this.OnDisconnect.Invoke(device);
     }
     return(Task.CompletedTask);
 }
예제 #9
0
        public static Task <USBDevice> ClearHalt(this USBDevice device, USBEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            return(device.ClearHalt(endpoint.Direction, endpoint.EndpointNumber));
        }
예제 #10
0
        public static Task <USBDevice> SelectConfiguration(this USBDevice device, USBConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(device.SelectConfiguration(configuration.ConfigurationValue));
        }
예제 #11
0
        public static Task <USBDevice> ReleaseInterface(this USBDevice device, USBInterface usbInterface)
        {
            if (usbInterface == null)
            {
                throw new ArgumentNullException(nameof(usbInterface));
            }

            return(device.ReleaseInterface(usbInterface.InterfaceNumber));
        }
예제 #12
0
        public static Task <USBDevice> ReleaseBulkInterface(this USBDevice device)
        {
            var bulkInterface = device.Configuration.Interfaces.FirstOrDefault(i => i.Alternates.Any(a => a.Endpoints.Any(e => e.Type == USBEndpointType.Bulk)));

            if (bulkInterface == null)
            {
                throw new InvalidOperationException("This devices doesn't have a Bulk interface");
            }
            return(device.ReleaseInterface(bulkInterface.InterfaceNumber));
        }
예제 #13
0
        public static Task <USBDevice> SelectAlternateInterface(this USBDevice device, USBInterface usbInterface, USBAlternateInterface usbAlternateInterface)
        {
            if (usbInterface == null)
            {
                throw new ArgumentNullException(nameof(usbInterface));
            }
            if (usbAlternateInterface == null)
            {
                throw new ArgumentNullException(nameof(usbAlternateInterface));
            }

            return(device.SelectAlternateInterface(usbInterface.InterfaceNumber, usbAlternateInterface.AlternateSetting));
        }
예제 #14
0
 internal static void AttachUSB(this USBDevice device, USB usb) => device.USB = usb;
예제 #15
0
 public static Task <USBDevice> ClaimInterface(this USBDevice device, byte interfaceNumber)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(CLAIM_INTERFACE_METHOD, device, interfaceNumber));
 }
예제 #16
0
 public static Task <USBDevice> ClearHalt(this USBDevice device, string direction, byte endpointNumber)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(CLEAR_HALT_METHOD, device, direction, endpointNumber));
 }
예제 #17
0
 public static Task <USBInTransferResult> TransferIn(this USBDevice device, byte endpointNumber, long length)
 {
     return(JSRuntime.Current.InvokeAsync <USBInTransferResult>(TRANSFER_IN_METHOD, device, endpointNumber, length));
 }
예제 #18
0
 public static Task <USBDevice> SelectConfiguration(this USBDevice device, byte configuration)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(SELECT_CONFIGURATION_METHOD, device, configuration));
 }
예제 #19
0
 public static Task <USBDevice> Reset(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(RESET_DEVICE_METHOD, device);
예제 #20
0
 public static Task <USBOutTransferResult> TransferOut(this USBDevice device, USBEndpoint endpoint, byte[] data)
 {
     return(device.TransferOut(endpoint.EndpointNumber, data));
 }
예제 #21
0
 public static Task <USBOutTransferResult> TransferOut(this USBDevice device, byte endpointNumber, byte[] data)
 {
     return(JSRuntime.Current.InvokeAsync <USBOutTransferResult>(TRANSFER_OUT_METHOD, device, endpointNumber, data));
 }
예제 #22
0
 public static Task <USBDevice> ReleaseInterface(this USBDevice device, byte interfaceNumber)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(RELEASE_INTERFACE_METHOD, device, interfaceNumber));
 }
예제 #23
0
 public static Task <USBInTransferResult> ControlTransferIn(this USBDevice device, USBControlTransferParameters setup, long length)
 {
     return(JSRuntime.Current.InvokeAsync <USBInTransferResult>(CONTROL_TRANSFER_IN_METHOD, device, setup, length));
 }
예제 #24
0
 public static Task <USBDevice> Open(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(OPEN_DEVICE_METHOD, device);
예제 #25
0
 public static Task <USBDevice> Close(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(CLOSE_DEVICE_METHOD, device);
예제 #26
0
 public static Task <USBOutTransferResult> ControlTransferOut(this USBDevice device, USBControlTransferParameters setup, byte[] data)
 {
     return(JSRuntime.Current.InvokeAsync <USBOutTransferResult>(CONTROL_TRANSFER_OUT_METHOD, device, setup, data));
 }
예제 #27
0
 public static Task <USBDevice> SelectAlternateInterface(this USBDevice device, byte interfaceNumber, byte alternateSetting)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(SELECT_ALTERNATE_INTERFACE_METHOD, device, interfaceNumber, alternateSetting));
 }