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);
        }
        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);
        }
        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);
        }
Exemple #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);
        }
        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);
        }
        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);
        }
Exemple #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));
 }
Exemple #8
0
 public Task Disconnected(USBDevice device)
 {
     if (this.OnDisconnect != null &&
         this.OnDisconnect.GetInvocationList().Length > 0)
     {
         this.OnDisconnect.Invoke(device);
     }
     return(Task.CompletedTask);
 }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #14
0
 internal static void AttachUSB(this USBDevice device, USB usb) => device.USB = usb;
Exemple #15
0
 public static Task <USBDevice> ClaimInterface(this USBDevice device, byte interfaceNumber)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(CLAIM_INTERFACE_METHOD, device, interfaceNumber));
 }
Exemple #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));
 }
Exemple #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));
 }
Exemple #18
0
 public static Task <USBDevice> SelectConfiguration(this USBDevice device, byte configuration)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(SELECT_CONFIGURATION_METHOD, device, configuration));
 }
Exemple #19
0
 public static Task <USBDevice> Reset(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(RESET_DEVICE_METHOD, device);
Exemple #20
0
 public static Task <USBOutTransferResult> TransferOut(this USBDevice device, USBEndpoint endpoint, byte[] data)
 {
     return(device.TransferOut(endpoint.EndpointNumber, data));
 }
Exemple #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));
 }
Exemple #22
0
 public static Task <USBDevice> ReleaseInterface(this USBDevice device, byte interfaceNumber)
 {
     return(JSRuntime.Current.InvokeAsync <USBDevice>(RELEASE_INTERFACE_METHOD, device, interfaceNumber));
 }
Exemple #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));
 }
Exemple #24
0
 public static Task <USBDevice> Open(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(OPEN_DEVICE_METHOD, device);
Exemple #25
0
 public static Task <USBDevice> Close(this USBDevice device) => JSRuntime.Current.InvokeAsync <USBDevice>(CLOSE_DEVICE_METHOD, device);
Exemple #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));
 }
Exemple #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));
 }