Exemple #1
2
        public void Connect()
        {
            if (_terminate)
                throw new InvalidOperationException("Corsair K95 has already been terminated.");

            if (_device != null)
                throw new InvalidOperationException("Corsair K95 is already connected.");

            try
            {
                USBDeviceInfo[] details = USBDevice.GetDevices(_deviceInterfaceGuid);
                /*foreach (var deviceDetails in details)
                {
                    using (USBDevice device = new USBDevice(deviceDetails))
                    {
                        PrintInfo(device);
                    }
                }*/

                _device = new USBDevice(details[0]);
                _bgWorker.RunWorkerAsync(_device);

                Thread.Sleep(1000);
            }
            catch (Exception e)
            {
                Trace.WriteLine("K95: Connect Exception: " + e.ToString());
                _device = null;
                throw;
            }
        }
Exemple #2
0
        internal WinusbAppiDev(USBDeviceInfo di)
        {
            // TODO: Отлавливать исключения WinUsbNet
            try
            {
                Device = new USBDevice(di);
                DevicePath = di.DevicePath;

                ReadPipe = Device.Pipes.First(p => p.IsIn);
                ReadPipe.Policy.PipeTransferTimeout = 100;
                ReadPipe.Policy.AutoClearStall = true;
                ReadPipe.Flush();

                WritePipe = Device.Pipes.First(p => p.IsOut);
                WritePipe.Policy.PipeTransferTimeout = 100;

                lock (OpenedDevicesLocker)
                {
                    OpenedDevices.Add(this);
                }
            }
            catch (USBException e)
            {
                throw new AppiConnectoinException(e);
            }
        }
Exemple #3
0
 public void open()
 {
     try
     {
         // open_path(this.device_info["path"]);
         // this.device.OpenDevice(DeviceMode.NonOverlapped, DeviceMode.NonOverlapped, ShareMode.Exclusive);
         var usbInterface = new MadWizard.WinUSBNet.USBDevice(this.device_info).Interfaces.First(
             usbIf =>
             usbIf.BaseClass == USBBaseClass.VendorSpecific &&
             usbIf.Protocol == 0
             );
         this.deviceOut = usbInterface.Pipes.First(p => p.IsOut);
         this.deviceIn  = usbInterface.Pipes.First(p => p.IsIn);
     }
     catch                                             // (IOError)
     {
         throw new Exception("Unable to open device"); //DAPAccessIntf.DeviceError
     }
 }
 public SmartScopeUsbInterfaceWinUsb(USBDevice usbDevice)
 {
     Destroyed = false;
     device = usbDevice;
     serial = usbDevice.Descriptor.SerialNumber;
     foreach (USBPipe p in device.Pipes)
     {
         p.Abort();
         USBPipePolicy pol = p.Policy;
         pol.PipeTransferTimeout = USB_TIMEOUT;
         if (p.IsIn)
         {
             p.Flush();
             pol.AllowPartialReads = true;
             pol.IgnoreShortPackets = false;
         }
     }
     USBPipe[] pipes = device.Pipes.ToArray();
     dataEndpoint = pipes[0];
     commandWriteEndpoint = pipes[1];
     commandReadEndpoint = pipes[2];
     LabNation.Common.Logger.Debug("Created new WinUSB ScopeUsbInterface");
 }
Exemple #5
0
 private void BgWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     // Cleanup the USB device connection and free all resources
     if (_device != null)
     {
         _device.Dispose();
         _device = null;
     }
 }
Exemple #6
0
        private static void PrintInfo(USBDevice device)
        {
            Console.WriteLine("Device: {0}", device.Descriptor.FullName);
            Console.WriteLine("Pipes: {0}", device.Pipes?.Count());
            Console.WriteLine("Control Pipe Timeout: {0}", device.ControlPipeTimeout);

            foreach (USBInterface iface in device.Interfaces)
            {
                Console.WriteLine("Interface - id:{0}, protocol:{1}, class:{2}, subclass:{3}",
                  iface.Number, iface.Protocol, iface.ClassValue, iface.SubClass);

                Console.WriteLine("Pipes: {0}", iface.Pipes?.Count());
                if (iface.Pipes != null)
                {
                    foreach (USBPipe pipe in iface.Pipes)
                    {
                        Console.WriteLine("Pipe - Address:{0}, isIn:{1}, isOut:{2}, maxPacketSize:{3}", pipe.Address, pipe.IsIn, pipe.IsOut, pipe.MaximumPacketSize);
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Prints out detailed device information for all K95 devices connected.
        /// </summary>
        public void PrintDevices()
        {
            var devices = USBDevice.GetDevices(_deviceInterfaceGuid);
            if (devices.Length <= 0)
            {
                Console.WriteLine("No devices found for GUID: "+_deviceInterfaceGuid );
                return;
            }

            foreach (var deviceDetails in devices)
            {
                using (USBDevice device = new USBDevice(deviceDetails))
                {
                    PrintInfo(device);
                }
            }
        }
Exemple #8
0
        internal USBPipe(USBDevice device, API.WINUSB_PIPE_INFORMATION pipeInfo)
        {
            _pipeInfo = pipeInfo;
            _device = device;

            // Policy is not set until interface is attached
            _policy = null;
        }
        public void Connect()
        {
            if (_terminate)
                throw new InvalidOperationException("XboxBigButtonDevice has already been terminated.");

            if ( _device != null)
                throw new InvalidOperationException("XboxBigButtonDevice is already connected.");

            try
            {
                _device = USBDevice.GetSingleDevice(_deviceInterfaceGuid);
                _bgWorker.RunWorkerAsync(_device);
            }
            catch (Exception e)
            {
                Trace.WriteLine("XBB: Connect Exception: "+e.ToString());
                _device = null;
                throw;
            }
        }
Exemple #10
0
        internal USBInterface(USBDevice device, int interfaceIndex, API.USB_INTERFACE_DESCRIPTOR rawDesc, USBPipeCollection pipes)
        {
            // Set raw class identifiers
            ClassValue = rawDesc.bInterfaceClass;
            SubClass = rawDesc.bInterfaceSubClass;
            Protocol = rawDesc.bInterfaceProtocol;

            Number = rawDesc.bInterfaceNumber;
            InterfaceIndex = interfaceIndex;

            // If interface class is of a known type (USBBaseClass enum), use this
            // for the InterfaceClass property.
            BaseClass = USBBaseClass.Unknown;
            if (Enum.IsDefined(typeof(USBBaseClass), (int)rawDesc.bInterfaceClass))
            {
                BaseClass = (USBBaseClass)(int)rawDesc.bInterfaceClass;
            }
           

            Device = device;
            Pipes = pipes;

            // Handle pipes
            foreach (USBPipe pipe in pipes)
            {
                // Attach pipe to this interface
                pipe.AttachInterface(this);

                // If first in or out pipe, set InPipe and OutPipe
                if (pipe.IsIn && InPipe == null)
                    InPipe = pipe;
                if (pipe.IsOut && OutPipe == null)
                    OutPipe = pipe;

            }
        
        }
 internal USBPipePolicy(USBDevice device, int interfaceIndex, byte pipeID)
 {
     _pipeID = pipeID;
     _interfaceIndex = interfaceIndex;
     _device = device;
 }