Beispiel #1
0
    void Setup()
    {
        if (UsbDev != null)
        {
            return;
        }

        UsbDev = FindDevice();

        if (!UsbDev.SetConfiguration(1))
        {
            throw new M4ATXException("Failed to set device config");
        }

        if (!UsbDev.ClaimInterface(0))
        {
            throw new M4ATXException("Failed to claim interface #0");
        }

        if (!UsbDev.SetAltInterface(0))
        {
            throw new M4ATXException("Failed to set alternate interface to 0");
        }

        Writer = UsbDev.OpenEndpointWriter(WriteEndpointID.Ep01);
        Reader = UsbDev.OpenEndpointReader(ReadEndpointID.Ep01);
    }
        public override void Close()
        {
            try {
                write_lock.WaitOne ();

                if (ep_reader != null) {
                    // detach read event
                    ep_reader.DataReceivedEnabled = false;
                    ep_reader.DataReceived -= (read_usb);
                }

                ep_reader = null;
                ep_writer = null;

                if (IsOpen ()) {
                    // close devices
                    usb_device.Close ();
                    wholeUsbDevice.ReleaseInterface (1);
                    wholeUsbDevice.Close ();
                }

                // release devices
                usb_device = null;
                wholeUsbDevice = null;
                UsbDevice.Exit();
            } catch (Exception) {
                // Ignore everything
            } finally {
                write_lock.ReleaseMutex();
            }
        }
Beispiel #3
0
 internal DeviceCommand(DeviceCommand dev)
 {
     this.usb          = dev.UsbDevice;
     this.parentDevice = dev;
     logs     = new List <Log>();
     commands = new List <Command>();
 }
Beispiel #4
0
        public static void Close(UsbDevice usbDevice)
        {
            if (usbDevice != null)
            {
                if (usbDevice.IsOpen)
                {
                    // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                    // it exposes an IUsbDevice interface. If not (WinUSB) the
                    // 'wholeUsbDevice' variable will be null indicating this is
                    // an interface of a device; it does not require or support
                    // configuration and interface selection.
                    IUsbDevice wholeUsbDevice = usbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // Release interface
                        wholeUsbDevice.ReleaseInterface(1);
                    }

                    usbDevice.Close();
                }
                usbDevice = null;

                // Free usb resources
                UsbDevice.Exit();
            }
        }
Beispiel #5
0
        public void Dispose()
        {
            Registry   = null;
            IsDisposed = true;
            if (Device != null)
            {
                Writer.Abort();
                Writer.Dispose();
                Writer = null;
                if (Device.IsOpen)
                {
                    // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                    // it exposes an IUsbDevice interface. If not (WinUSB) the
                    // 'wholeUsbDevice' variable will be null indicating this is
                    // an interface of a device; it does not require or support
                    // configuration and interface selection.
                    IUsbDevice wholeUsbDevice = Device as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // Release interface #0.
                        wholeUsbDevice.ReleaseInterface(0);
                    }

                    Device.Close();
                }
                Device = null;

                // Free usb resources
                UsbDevice.Exit();
            }
        }
Beispiel #6
0
        public bool Open()
        {
            if (IsOpen)
            {
                return(false);
            }

            if (!_Device.Open())
            {
                return(false);
            }

            IUsbDevice whole = _Device as IUsbDevice;

            if (!ReferenceEquals(whole, null))
            {
                if (!whole.SetConfiguration(ConfigurationID) || !whole.ClaimInterface(InterfaceID))
                {
                    _Device.Close();
                    throw new PTPException("could not set USB device configuration and interface to " + ConfigurationID + " and " + InterfaceID + ", respectively");
                }
            }

            Writer = _Device.OpenEndpointWriter(WriterEndpointID);
            Reader = _Device.OpenEndpointReader(ReaderEndpointID);

            return(true);
        }
        /// <summary>
        /// Dynamic predicate find function. Pass this function into any method that has a <see cref="Predicate{UsbDevice}"/> parameter.
        /// </summary>
        /// <remarks>
        /// Override this member when inheriting the <see cref="UsbDeviceFinder"/> class to change/alter the matching behavior.
        /// </remarks>
        /// <param name="usbDevice">The UsbDevice to check.</param>
        /// <returns>True if the <see cref="UsbDevice"/> instance matches the <see cref="UsbDeviceFinder"/> properties.</returns>
        public virtual bool Check(IUsbDevice usbDevice)
        {
            try
            {
                if (this.Vid != null && usbDevice.Info.VendorId != this.Vid.Value)
                {
                    return(false);
                }

                if (this.Pid != null && usbDevice.Info.ProductId != this.Pid.Value)
                {
                    return(false);
                }

                if (this.Revision != null && usbDevice.Info.Usb != this.Revision.Value)
                {
                    return(false);
                }

                if (this.SerialNumber != null && usbDevice.Info.SerialNumber != this.SerialNumber)
                {
                    return(false);
                }

                return(true);
            }
            catch (LibUsb.UsbException ex) when(ex.ErrorCode == Error.NotFound)
            {
                // The device has probably disconnected while we were inspecting it. Continue.
                return(false);
            }
        }
Beispiel #8
0
        public MainWindow()
        {
            InitializeComponent();
            ErrorCode ec = ErrorCode.None;

            try
            {
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                if (MyUsbDevice == null)
                {
                    MessageBox.Show("Device Not Found.");
                }
                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }
                UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
                reader.DataReceived       += (OnRxEndPointData);
                reader.DataReceivedEnabled = true;
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #9
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                reader.DataReceivedEnabled = false;
                reader.DataReceived       -= (OnRxEndPointData);
                reader.Dispose();
                writer.Dispose();

                if (MyUsbDevice != null)
                {
                    if (MyUsbDevice.IsOpen)
                    {
                        IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            wholeUsbDevice.ReleaseInterface(0);
                        }
                        MyUsbDevice.Close();
                    }
                    MyUsbDevice = null;
                    UsbDevice.Exit();
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #10
0
        public HeliosDevice(IUsbDevice usbDevice)
        {
            this.usbDevice = usbDevice;

            interruptEndpointReader = usbDevice.OpenEndpointReader(ReadEndpointID.Ep03, 32, EndpointType.Interrupt);
            interruptEndpointWriter = usbDevice.OpenEndpointWriter(WriteEndpointID.Ep06, EndpointType.Interrupt);
            bulkEndpointWriter      = usbDevice.OpenEndpointWriter(WriteEndpointID.Ep02, EndpointType.Bulk);
        }
Beispiel #11
0
        /// <summary>
        /// Attempts to open a USB registry as a USB DFU device.
        /// </summary>
        /// <param name="registry">The input USB registry of a connected device</param>
        /// <param name="dfuDevice">The opened DFU device in case of success</param>
        /// <returns>True if the DFU device is successfully opened</returns>
        public static bool TryOpen(UsbRegistry registry, out Device dfuDevice)
        {
            dfuDevice = null;
            UsbDevice dev;
            byte      cfIndex = 0;
            byte      ifIndex = 0;

            if (!registry.Open(out dev))
            {
                return(false);
            }

            var confInfo = dev.Configs[cfIndex];

            // This is a "whole" USB device. Before it can be used,
            // the desired configuration and interface must be selected.
            IUsbDevice usbDevice = dev as IUsbDevice;

            if (usbDevice != null)
            {
                // Select config
                usbDevice.SetConfiguration(confInfo.Descriptor.ConfigID);
            }

            // find DFU interface
            for (ifIndex = 0; ifIndex < confInfo.InterfaceInfoList.Count; ifIndex++)
            {
                var iface = confInfo.InterfaceInfoList[ifIndex];

                if (!IsDfuInterface(iface))
                {
                    continue;
                }

                if (usbDevice != null)
                {
                    // Claim interface
                    usbDevice.ClaimInterface(iface.Descriptor.InterfaceID);
                }
                break;
            }

            try
            {
                if (ifIndex == confInfo.InterfaceInfoList.Count)
                {
                    throw new ArgumentException("The device doesn't have valid DFU interface");
                }
                dfuDevice = new Device(dev, cfIndex, ifIndex);
                return(true);
            }
            catch (Exception)
            {
                var d = dev as IDisposable;
                d.Dispose();
                return(false);
            }
        }
Beispiel #12
0
        public override void OpenDevice()
        {
            log.Info("QDLUsb trying to find device");
            UsbDevice.UsbErrorEvent += new EventHandler <UsbError>(UsbErrorEvent);
            UsbRegistry regDev = null;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                regDev = UsbDevice.AllWinUsbDevices.Find((reg) => reg.Vid == VID && reg.Pid == PID);
            }
            else
            {
                regDev = UsbDevice.AllDevices.Find((reg) => reg.Vid == VID && reg.Pid == PID);
            }
            if (regDev == null)
            {
                log.Error("No QDLUSB Devices found");
                throw new QDLDeviceNotFoundException("Unable to find device");
            }

            if (!regDev.Open(out device) || device == null)
            {
                log.Error("No QDLUSB Devices found");
                throw new QDLDeviceNotFoundException("Unable to open device");
            }

            if (UsbDevice.IsLinux)
            {
                log.Debug("Running on linux, detaching kernel driver");
                MonoUsbDevice monodev = device as MonoUsbDevice;
                if (!monodev.DetachKernelDriver())
                {
                    log.Error("Failed to detach kernel driver");
                    throw new Exception("Failed to detach kernel driver");
                }
            }

            IUsbDevice wholeUsbDevice = device as IUsbDevice;

            if (wholeUsbDevice != null)
            {
                wholeUsbDevice.SetConfiguration(1);
                wholeUsbDevice.ClaimInterface(0);
            }

            reader = device.OpenEndpointReader(ReadEndpointID.Ep01);
            writer = device.OpenEndpointWriter(WriteEndpointID.Ep01, EndpointType.Bulk);
            if (reader == null || writer == null)
            {
                device.Close();
                device = null;
                UsbDevice.Exit();
                log.Error("Failed to open endpoints");
                throw new Exception("Unable to open endpoints");
            }
            log.Info("Found QDLUSB device");
        }
Beispiel #13
0
        /// <summary>
        /// Close and open the device
        /// </summary>
        /// <param name="device">The device</param>
        private static void CloseAndOpen(IUsbDevice device)
        {
            if (device.IsOpen)
            {
                device.Close();
            }

            Initialize((UsbDevice)device);
        }
        public static void Connect(DeviceNameList dList)
        {
            try
            {
                if ((uDevice = UsbDevice.OpenUsbDevice(uDevFinder)) == null)
                {
                    throw new Exception("Device Not Found");
                }

                IUsbDevice iuDev = uDevice as IUsbDevice;
                if (!ReferenceEquals(iuDev, null))
                {
                    iuDev.SetConfiguration(1);
                    iuDev.ClaimInterface(0);
                }
                uDevice.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine("usbcom Connecting Proces : {0}", e);
                throw;
            }
            (new Thread(() => {
                while (uDevice.IsOpen)
                {
                    byte[] buf = new byte[64];
                    int bytesRead = 0;

                    using (var Reader = uDevice.OpenEndpointReader(ReadEndpointID.Ep01))
                    {
                        ErrorCode ec = ErrorCode.None;
                        ec = Reader.Read(buf, 2000, out bytesRead);

                        if (ec == ErrorCode.IoTimedOut)
                        {
                            continue;
                        }
                        if (ec == ErrorCode.IoCancelled)
                        {
                            return;
                        }
                        if (ec != 0)
                        {
                            throw new Exception("usbcom ReadCtrl Error : ErrorCode==" + ec.ToString() + "\n" + UsbDevice.LastErrorString);
                        }
                    }

                    if (bytesRead > 0)
                    {
                        (new Thread(() => DataGot?.Invoke(null, new DataGotEvArgs()
                        {
                            Data = buf
                        }))).Start();
                    }
                }
            })).Start();
        }
Beispiel #15
0
        public override void DeviceInitialize(IDevice device)
        {
            base.DeviceInitialize(device);

            volume = device as IVolume;
            if (volume == null || !volume.IsMounted || (usb_device = volume.ResolveRootUsbDevice()) == null)
            {
                throw new InvalidDeviceException();
            }

            ms_device = DeviceMapper.Map(this);
            try {
                if (ms_device.ShouldIgnoreDevice() || !ms_device.LoadDeviceConfiguration())
                {
                    ms_device = null;
                }
            } catch {
                ms_device = null;
            }

            if (!HasMediaCapabilities && ms_device == null)
            {
                throw new InvalidDeviceException();
            }

            // Ignore iPods, except ones with .is_audio_player files
            if (MediaCapabilities != null && MediaCapabilities.IsType("ipod"))
            {
                if (ms_device != null && ms_device.HasIsAudioPlayerFile)
                {
                    Log.Information(
                        "Mass Storage Support Loading iPod",
                        "The USB mass storage audio player support is loading an iPod because it has an .is_audio_player file. " +
                        "If you aren't running Rockbox or don't know what you're doing, things might not behave as expected."
                        );
                }
                else
                {
                    throw new InvalidDeviceException();
                }
            }

            Name        = ms_device == null ? volume.Name : ms_device.Name;
            mount_point = volume.MountPoint;

            Initialize();

            if (ms_device != null)
            {
                ms_device.SourceInitialize();
            }

            AddDapProperties();

            // TODO differentiate between Audio Players and normal Disks, and include the size, eg "2GB Audio Player"?
            //GenericName = Catalog.GetString ("Audio Player");
        }
Beispiel #16
0
    public bool make_idle(bool initial_abort)
    {
      int retries = 4;
      DFU_Status status;
      IUsbDevice thisDev = myUSBDevice as IUsbDevice;
      
      if (initial_abort)
        {
          abort();
        }

      while (retries > 0)
        {
          if (!get_status(out status))
            {
              clear_status();
              continue;
            }
          switch (status.State)
            {
            case DFUStateVals.STATE_DFU_IDLE:
              if( DFUStatusVals.DFU_STATUS_OK == status.Status ) {
                return(true);
              }

              /* We need the device to have the DFU_STATUS_OK status. */
              clear_status();
              break;

            case DFUStateVals.STATE_DFU_DOWNLOAD_SYNC:   /* abort -> idle */
            case DFUStateVals.STATE_DFU_DOWNLOAD_IDLE:   /* abort -> idle */
            case DFUStateVals.STATE_DFU_MANIFEST_SYNC:   /* abort -> idle */
            case DFUStateVals.STATE_DFU_UPLOAD_IDLE:     /* abort -> idle */
            case DFUStateVals.STATE_DFU_DOWNLOAD_BUSY:   /* abort -> error */
            case DFUStateVals.STATE_DFU_MANIFEST:        /* abort -> error */
              abort();
              break;

            case DFUStateVals.STATE_DFU_ERROR:
              clear_status();
              break;

            case DFUStateVals.STATE_APP_IDLE:
              detach( DFU_DETACH_TIMEOUT );
              break;

            case DFUStateVals.STATE_APP_DETACH:
            case DFUStateVals.STATE_DFU_MANIFEST_WAIT_RESET:
              //DEBUG( "Resetting the device\n" );
              thisDev.ResetDevice();
              return(false);
            }
          retries--;
        }
      return(false);
    }
Beispiel #17
0
        public void usbConnect() // The name is self-explanatory...
        {
            // Find and open the usb device.
            mUsbDevice = UsbDevice.OpenUsbDevice(mini2440Finder);
            if (mUsbDevice == null)
            {
                mUsbDevice = UsbDevice.OpenUsbDevice(mini6410Finder);
            }

            // If we fail to find or connect to the device
            if (mUsbDevice == null)
            {
                l_usbFound.Text = "Error";
                t_log.AppendText("\r\n" + "## Could not find or open device." + "\r\n"
                                 + "Please plug the device, I will detect it." + "\r\n");
                b_download.Enabled = false;
                b_upload.Enabled   = false;
            }
            // If the device is open and ready
            else
            {
                l_usbFound.Text = "Connected";
                if (mUsbDevice.UsbRegistryInfo.Pid == pid2440)
                {
                    t_log.AppendText("\r\n" + "## Mini2440 connected." + "\r\n");
                }
                if (mUsbDevice.UsbRegistryInfo.Pid == pid6410)
                {
                    t_log.AppendText("\r\n" + "## Mini6410 connected." + "\r\n");
                }
                b_download.Enabled = true;
                b_upload.Enabled   = true;
                mEpReader          = mUsbDevice.OpenEndpointReader((ReadEndpointID)(byte.Parse("1") | 0x80)); // = 81
                mEpWriter          = mUsbDevice.OpenEndpointWriter((WriteEndpointID)byte.Parse("3"));
                if (mEpWriter.EndpointInfo == null)                                                           // Try opening endpoint 4 if endpoint 3 is unavailable (i.e. after usb reset when downloading firmware)
                {
                    mEpWriter = mUsbDevice.OpenEndpointWriter((WriteEndpointID)byte.Parse("4"));
                }

                //mEpReader.Flush();
                mEpWriter.Flush();

                IUsbDevice wholeUsbDevice = mUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }
            }
        }
Beispiel #18
0
 public static Task ClearStatusAsync(this IUsbDevice usbDevice)
 => usbDevice.PerformControlTransferAsync(new SetupPacket
                                          (
                                              requestType: new UsbDeviceRequestType(
                                                  RequestDirection.In,
                                                  RequestType.Class,
                                                  RequestRecipient.Interface),
                                              request: DFU_CLEARSTATUS,
                                              length: 0
                                          ));
Beispiel #19
0
 public static Task <TransferResult> GetStatusAsync(this IUsbDevice usbDevice)
 => usbDevice.PerformControlTransferAsync(new SetupPacket
                                          (
                                              requestType: new UsbDeviceRequestType(
                                                  RequestDirection.In,
                                                  RequestType.Class,
                                                  RequestRecipient.Interface),
                                              request: DFU_GETSTATUS,
                                              length: GetStatusPacketLength
                                          ));
Beispiel #20
0
        public static int GetProductId(IUsbDevice device)
        {
            var raw = device as IRawDevice;
            int num = 0;

            if (raw != null && Int32.TryParse(raw.Device.UdevMetadata.GetPropertyString(UdevProductId), NumberStyles.HexNumber, null, out num))
            {
                return(num);
            }
            return(0);
        }
Beispiel #21
0
        public static int GetDeviceNumber(IUsbDevice device)
        {
            var raw = device as IRawDevice;
            int num = 0;

            if (raw != null && Int32.TryParse(raw.Device.UdevMetadata.GetPropertyString(UdevUsbDeviceNumber), out num))
            {
                return(num);
            }
            return(0);
        }
Beispiel #22
0
        public bool Connect()
        {
            _usbRegistry.Open(out _usbDevice);
            if (_usbDevice == null)
            {
                return(false);
            }

            // If this is a "whole" usb device (libusb-win32, linux libusb)
            // it will have an IUsbDevice interface. If not (WinUSB) the
            // variable will be null indicating this is an interface of a
            // device.
            IUsbDevice wholeUsbDevice = _usbDevice as IUsbDevice;

            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                if (!wholeUsbDevice.ClaimInterface(0))
                {
                    wholeUsbDevice.ReleaseInterface(0);
                    _usbDevice.Close();
                    return(false);
                }
            }
            if (_resolverInfo.V45Endpoints == true)
            {
                // Open EP1 for writing, used to send BCP commands/packets to the unit.
                _endpointWriter = _usbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);

                // Open EP2 for reading, used to send BCP replies to the USB host.
                _endpointReader = _usbDevice.OpenEndpointReader(ReadEndpointID.Ep02);

                // Open EP5 for reading, used to send “real time capture data” to the host.
                _realTimeEndpointReader = _usbDevice.OpenEndpointReader(ReadEndpointID.Ep05);
            }
            else
            {
                // Open EP2 for writing, used to send BCP commands/packets to the unit.
                _endpointWriter = _usbDevice.OpenEndpointWriter(WriteEndpointID.Ep02);

                // Open EP6 for reading, used to send BCP replies to the USB host.
                _endpointReader = _usbDevice.OpenEndpointReader(ReadEndpointID.Ep06);

                // Open EP8 for reading, used to send “real time capture data” to the host.
                _realTimeEndpointReader = _usbDevice.OpenEndpointReader(ReadEndpointID.Ep08);
            }
            return(true);
        }
Beispiel #23
0
        private void InitUSB(int VendorID, int ProductID)
        {
            dev = (IUsbDevice)UsbDevice.OpenUsbDevice(x => x.Vid == VendorID && x.Pid == ProductID);

            if (dev == null)
            {
                throw new NullReferenceException("Cannot find USB device for JZ4780. Check Vendor/Product IDs and that LibUSB-Win32 \".inf\" installed.");
            }

            dev.SetConfiguration(1);
        }
Beispiel #24
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            _printer = UsbDevice.OpenUsbDevice(_printerFinder);

            _printerUsbDevice = _printer as IUsbDevice;

            if (_printerUsbDevice != null)
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                _printerUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                _printerUsbDevice.ClaimInterface(0);
            }

            // open write endpoint 1.
            UsbEndpointWriter writer         = _printer.OpenEndpointWriter(WriteEndpointID.Ep02);
            List <byte>       writeBytesList = new List <byte>();

            writeBytesList.AddRange(Encoding.ASCII.GetBytes(txtTextToPrint.Text));
            writeBytesList.Add(0x0A);

            byte[] writeBuffer = writeBytesList.ToArray();

            int       bytesWritten;
            ErrorCode writeErrorCode = writer.Write(writeBuffer, 10000, out bytesWritten);

            // open read endpoint 1.
            //UsbEndpointReader reader = printer.OpenEndpointReader(ReadEndpointID.Ep01);

            //ErrorCode readErrorCode = ErrorCode.None;

            //byte[] readBuffer = new byte[1024];

            //while (readErrorCode == ErrorCode.None)
            //{
            //    int bytesRead;

            //    // If the device hasn't sent data in the last 100 milliseconds,
            //    // a timeout error (ec = IoTimedOut) will occur.
            //    readErrorCode = reader.Read(readBuffer, 10000, out bytesRead);

            //    if (bytesRead == 0)
            //    {
            //        break;
            //    }

            //    // Write that output to the console.
            //    MessageBox.Show(Encoding.ASCII.GetString(readBuffer, 0, bytesRead));
            //}
        }
Beispiel #25
0
        public UsbDevStream(IUsbDevice dev, WriteEndpointID writePipe, ReadEndpointID readPipe)
        {
            device    = dev;
            WritePipe = writePipe;
            ReadPipe  = readPipe;

            writer = device.OpenEndpointWriter(writePipe);
            reader = device.OpenEndpointReader(readPipe);

            Flush();
        }
Beispiel #26
0
 public static Task <TransferResult> SendDownloadRequestAsync(this IUsbDevice usbDevice)
 // buffer: set address pointer command (0x21), address pointer (0x08000000)
 => usbDevice.PerformControlTransferAsync(new SetupPacket
                                          (
                                              requestType: new UsbDeviceRequestType(
                                                  RequestDirection.Out,
                                                  RequestType.Class,
                                                  RequestRecipient.Interface),
                                              request: DFU_DNLOAD,
                                              length: (ushort)DownloadRequestBuffer.Length
                                          ), DownloadRequestBuffer);
        private void buttonRead_Click(object sender, EventArgs e)
        {
            dev = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x1915, 0x7B));
//            bool success = reg.Open(out dev);
            IUsbDevice wholeUsbDevice = dev as IUsbDevice;

            wholeUsbDevice.SetConfiguration(1);
            wholeUsbDevice.ClaimInterface(0);
            rdr = wholeUsbDevice.OpenEndpointReader((ReadEndpointID)0x81);
            rdr.Flush();
            Read();
        }
Beispiel #28
0
    void Reset()
    {
        if (UsbDev == null)
        {
            /* USB device not initilized, nothing to reset */
            return;
        }

        Log.WriteLine("Resetting M4ATX device");
        UsbDev.ResetDevice();
        UsbDev = null;
    }
Beispiel #29
0
            public static void open()
            {
                ErrorCode ec = ErrorCode.None;

                try
                {
                    MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                    if (MyUsbDevice == null)
                    {
                        throw new Exception("Device Not Found.");
                    }
                    IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        wholeUsbDevice.SetConfiguration(1);
                        wholeUsbDevice.ClaimInterface(0);
                    }

                    UsbEndpointWriter writer      = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
                    byte[]            bytesToSend = { 0x1b, 0x70, 0x00, 0x19, 0xff };

                    int bytesWritten;
                    ec = writer.Write(bytesToSend, 2000, out bytesWritten);
                    if (ec != ErrorCode.None)
                    {
                        throw new Exception(UsbDevice.LastErrorString);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
                }
                finally
                {
                    if (MyUsbDevice != null)
                    {
                        if (MyUsbDevice.IsOpen)
                        {
                            IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                            if (!ReferenceEquals(wholeUsbDevice, null))
                            {
                                // Release interface #0.
                                wholeUsbDevice.ReleaseInterface(0);
                            }

                            MyUsbDevice.Close();
                        }
                        MyUsbDevice = null;
                        UsbDevice.Exit();
                    }
                }
            }
Beispiel #30
0
 /// <summary>
 /// Cleans up a device, releasing interfaces and closing connection
 /// </summary>
 /// <param name="device">The device to close</param>
 private void Destroy(IUsbDevice device)
 {
     try
     {
         // Attempt to clean up device
         device.ReleaseInterface(device.Configs[0].Interfaces[0].Number);
         device.Close();
     }
     catch (Exception e)
     {
         _logger.LogWarning(e, "Attempted to clean up device, but failed.");
     }
 }
Beispiel #31
0
        public void Connect()
        {
            Context = new UsbContext();
            Device  = Context.Find(d => VID.Any(vid => d.VendorId == vid) &&
                                   PID.Any(pid => d.ProductId == pid)).Clone();

            if (Device is null)
            {
                throw new Exception("Device isn't connected!");
            }

            Device.Open();
        }
        public override void DeviceInitialize (IDevice device)
        {
            base.DeviceInitialize (device);

            volume = device as IVolume;
            if (volume == null || (usb_device = volume.ResolveRootUsbDevice ()) == null) {
                throw new InvalidDeviceException ();
            }

            ms_device = DeviceMapper.Map (this);
            try {
                if (ms_device.ShouldIgnoreDevice () || !ms_device.LoadDeviceConfiguration ()) {
                    ms_device = null;
                }
            } catch {
                ms_device = null;
            }

            if (!HasMediaCapabilities && ms_device == null) {
                throw new InvalidDeviceException ();
            }

            // Ignore iPods, except ones with .is_audio_player files
            if (MediaCapabilities != null && MediaCapabilities.IsType ("ipod")) {
                if (ms_device != null && ms_device.HasIsAudioPlayerFile) {
                    Log.Information (
                        "Mass Storage Support Loading iPod",
                        "The USB mass storage audio player support is loading an iPod because it has an .is_audio_player file. " +
                        "If you aren't running Rockbox or don't know what you're doing, things might not behave as expected."
                    );
                } else {
                    throw new InvalidDeviceException ();
                }
            }

            Name = ms_device == null ? volume.Name : ms_device.Name;
            mount_point = volume.MountPoint;

            Initialize ();

            if (ms_device != null) {
                ms_device.SourceInitialize ();
            }

            AddDapProperties ();

            // TODO differentiate between Audio Players and normal Disks, and include the size, eg "2GB Audio Player"?
            //GenericName = Catalog.GetString ("Audio Player");
        }
Beispiel #33
0
        public Form1()
        {
            InitializeComponent();
            // Hook the device notifier event
            UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;

            usb_command = new byte[64];
            try
            {
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                if (MyUsbDevice == null)
                {
                    //throw new Exception("Device Not Found.");
                    connected = false;
                }
                else
                {

                    Device_l.Text = "Device: Connected";
                    connected = true;

                    Scan_b.Enabled = true;

                    wholeUsbDevice = MyUsbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // This is a "whole" USB device. Before it can be used,
                        // the desired configuration and interface must be selected.

                        // Select config #1
                        wholeUsbDevice.SetConfiguration(1);

                        // Claim interface #0.
                        wholeUsbDevice.ClaimInterface(0);
                    }
                    //MessageBox.Show(ReadEndpointID.Ep04.ToString());
                    reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
                    writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
                    mode = 4;
                    backgroundWorker1.RunWorkerAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
            }
        }
Beispiel #34
0
 public static int GetProductId(IUsbDevice device)
 {
     var raw = device as IRawDevice;
     int num = 0;
     if (raw != null && Int32.TryParse (raw.Device.UdevMetadata.GetPropertyString (UdevProductId), NumberStyles.HexNumber, null, out num)) {
         return num;
     }
     return 0;
 }
Beispiel #35
0
        public void Dispose()
        {
            try
              {
            if (_refreshSlotsThread != null)
            {
              _refreshSlotsThread.Abort();
              _refreshSlotsThread = null;
            }

            if (_slots != null)
            {
              foreach (var slot in _slots.Values)
              {
            if (slot != null)
            {
              slot.DataReader.DataReceivedEnabled = false;
              slot.DataReader.DataReceived -= DataReader_DataReceived;
              slot.DataReader.Abort();
              slot.DataReader.Dispose();
              slot.HeadsetReader.DataReceivedEnabled = false;
              slot.HeadsetReader.DataReceived -= HeadsetReader_DataReceived;
              slot.HeadsetReader.Abort();
              slot.HeadsetReader.Dispose();
            }
              }
            }
            _slots = new Dictionary<int, ReceiverSlot>();

            if (_device != null)
            {
              if (_device.IsOpen)
            _device.Close();
              _device = null;
            }
              }
              catch
              {
            //Don't care...
              }
        }
        public void killReceiver()
        {
            // Loop through each Controller to clean it up
            for (int i = 0; i < 4; i++)
            {
                // Turns off the Xbox controllers
                if (receiverAttached)
                {
                    if (xboxControllers[i].controllerAttached)
                    {
                        // Clean up the controller's keep-alive threads
                        xboxControllers[i].killKeepAlive();

                        // Clean up the controller's mouse mode threads
                        xboxControllers[i].killMouseMode();

                        // Clean up the controller's button combo threads
                        xboxControllers[i].killButtonCombo();

                        // Clean up the controller
                        xboxControllers[i].killController();
                    }
                }

                // Cleans up the Wireless Receiver Data
                if (epWriters[i] != null)
                {
                    epWriters[i].Abort();
                    epWriters[i].Dispose();
                }

                if (epReaders[i] != null)
                {
                    epReaders[i].Abort();
                    epReaders[i].Dispose();
                }
            }

            // Clean up the Receiver
            if (wirelessReceiver != null)
            {
                if (receiverAttached)
                    wirelessReceiver.Close();
                wirelessReceiver = null;
            }
        }
Beispiel #37
0
        public void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            // A Device system-level event has occured

            //Console.SetCursorPosition(0, Console.CursorTop);
            //MessageBox.Show(e.Device.IdVendor.ToString());
            if (e.EventType == EventType.DeviceArrival && e.Device.IdVendor == 0x16C0 && e.Device.IdProduct == 0x05DD)
            {
                try
                {
                    MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                    if (MyUsbDevice == null)
                    {
                        //throw new Exception("Device Not Found.");
                        connected = false;
                    }
                    else
                    {

                        Device_l.Text = "Device: Connected";
                        connected = true;

                        Scan_b.Enabled = true;

                        wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            // This is a "whole" USB device. Before it can be used,
                            // the desired configuration and interface must be selected.

                            // Select config #1
                            wholeUsbDevice.SetConfiguration(1);

                            // Claim interface #0.
                            wholeUsbDevice.ClaimInterface(0);
                        }
                        //MessageBox.Show(ReadEndpointID.Ep04.ToString());
                        reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
                        writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
                        mode = 4;
                        backgroundWorker1.RunWorkerAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
                }
            }
            if (e.EventType == EventType.DeviceRemoveComplete && e.Device.IdVendor == 0x16C0 && e.Device.IdProduct == 0x05DD)
            {
                timer1.Enabled = false;
                connected = false;
                if (MyUsbDevice != null)
                {
                    if (MyUsbDevice.IsOpen)
                    {
                        // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                        // it exposes an IUsbDevice interface. If not (WinUSB) the
                        // 'wholeUsbDevice' variable will be null indicating this is
                        // an interface of a device; it does not require or support
                        // configuration and interface selection.
                        IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            // Release interface #0.
                            wholeUsbDevice.ReleaseInterface(0);
                        }

                        MyUsbDevice.Close();
                    }
                    MyUsbDevice = null;

                    // Free usb resources
                    UsbDevice.Exit();
                    Device_l.Text = "Device: Not Connected";
                    Scan_b.Enabled = false;
                    DumpRAM_b.Enabled = false;
                    DumpROM_b.Enabled = false;
                    WriteRAM_b.Enabled = false;
                    Banks_l.Text = "Banks: ";
                    MBC_l.Text = "MBC: ";
                    RAM_l.Text = "RAM Size: ";
                    Size_l.Text = "Size:";
                    Title_l.Text = "Title:";

                }
            }
               // Console.WriteLine(e.ToString()); // Dump the event info to output.

            //Console.WriteLine();
            //Console.Write("[Press any key to exit]");
        }
Beispiel #38
0
 public static int GetVendorId (IUsbDevice device)
 {
     var raw = device as IRawDevice;
     return raw == null ? 0 : int.Parse (raw.Device.UdevMetadata.GetPropertyString (UdevVendorId), NumberStyles.HexNumber);
 }
        // USB connection and adapter management
        public override void Open()
        {
            this.Close();

            try
            {
                caLibUsbAdapter.write_lock.WaitOne();

                usb_finder = new UsbDeviceFinder(this.vid, this.pid);
                Debug.Assert(this.usb_finder != null);

                // open device
                usb_device = UsbDevice.OpenUsbDevice(usb_finder);
                if (usb_device == null)
                {
                    throw new Exception("No compatible adapters found");
                }

                wholeUsbDevice = usb_device as IUsbDevice;
                if (!ReferenceEquals (wholeUsbDevice, null)) {
                    wholeUsbDevice.SetConfiguration(1);
                    wholeUsbDevice.ClaimInterface(1);
                } else {
                    throw new Exception("Failed to claim interface");
                }

                // open endpoints
                ep_reader = usb_device.OpenEndpointReader(this.read_ep_id);
                ep_writer = usb_device.OpenEndpointWriter(this.write_ep_id);
                if(ep_reader == null || ep_writer == null)
                {
                    throw new Exception("Failed to open endpoints");
                }

                // clear garbage from input
                this.ep_reader.ReadFlush();

                // attach read event
                ep_reader.DataReceived += (read_usb);
                ep_reader.DataReceivedEnabled = true;

            } catch (Exception e) {
                this.Close();
                throw e;
            } finally {
                caLibUsbAdapter.write_lock.ReleaseMutex();
            }
        }
Beispiel #40
0
        public void Stop()
        {
            lock (_lock)
            {
                IsOpen = false;
                EndPointId = ReadEndpointID.Ep01;
                CommunicationOk = false;
                if (_reader != null)
                {
                    _thread.Abort();
                    _thread.Join();
                    //_reader.DataReceivedEnabled = false;
                    //_reader.DataReceived -= OnReaderDataReceived;
                    _reader.ReadFlush();
                    _reader.Abort();
                    _reader = null;

                }
                if (_device != null)
                {
                    _device.ReleaseInterface(0);
                    _device.Close();
                    _device = null;
                    UsbDevice.Exit();
                }

            }
        }
        public bool Reset()
        {
            bool ret = true;

              Close();

              //Start message thread
              _messageThread = new Thread(new ThreadStart(_SendMessages));
              _messageThread.IsBackground = true;
              _messageThread.Start();

              //Find device
              _device = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(_VENDOR_ID, _PRODUCT_ID)) as IUsbDevice;

              if (_device != null)
              {
            //Set up the incoming and outgoing endpoints

            _reader = _device.OpenEndpointReader(LibUsbDotNet.Main.ReadEndpointID.Ep03);
            _reader.DataReceived += _reader_DataReceived;
            _reader.DataReceivedEnabled = true;

            lock (_writerLock)
            {
              _writer = _device.OpenEndpointWriter(LibUsbDotNet.Main.WriteEndpointID.Ep02);
            }
              }
              else
            ret = false;

              return ret;
        }
Beispiel #42
0
 public static int GetDeviceNumber(IUsbDevice device)
 {
     var raw = device as IRawDevice;
     int num = 0;
     if (raw != null && Int32.TryParse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbDeviceNumber), out num)) {
         return num;
     }
     return 0;
 }
Beispiel #43
0
        private void InitUSB(int VendorID, int ProductID)
        {
            dev = (IUsbDevice)UsbDevice.OpenUsbDevice(x => x.Vid == VendorID && x.Pid == ProductID);

            if (dev == null)
            {
                throw new NullReferenceException("Cannot find USB device for JZ4780. Check Vendor/Product IDs and that LibUSB-Win32 \".inf\" installed.");
            }

            dev.SetConfiguration(1);
        }
Beispiel #44
0
 public void Cleanup()
 {
     dev.ReleaseInterface(0);
     dev.Close();
     dev = null;
 }
Beispiel #45
0
 public static int GetDeviceNumber (IUsbDevice device)
 {
     var raw = device as IRawDevice;
     return raw ==  null ? 0 : int.Parse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbDeviceNumber));
 }
Beispiel #46
0
 public static int GetSpeed (IUsbDevice device)
 {
     throw new NotImplementedException ();
 }
Beispiel #47
0
        public void Start()
        {
            lock (_lock)
            {
                UsbRegDeviceList allLibUsbDevices = UsbDevice.AllLibUsbDevices;
                if (allLibUsbDevices.Count > 0)
                {
                    UsbDevice dev;
                    IsOpen = ((LibUsbRegistry)allLibUsbDevices.First()).Open(out dev);
                    _device = dev as IUsbDevice;
                    // Select config
                    bool configuration = _device.SetConfiguration(1);

                    // Claim interface
                    bool claimInterface = _device.ClaimInterface(0);
                    /*bool found = false;
                byte readerId = (byte) ReadEndpointID.Ep01;
                while (!found && (byte)readerId <= (byte)ReadEndpointID.Ep15)
                {
                    _reader = _device.OpenEndpointReader((ReadEndpointID)readerId);
                    byte[] buffer = new byte[1024];
                    int length;
                    ErrorCode ret = _reader.Read(buffer, 100, out length);
                    found = (ret != ErrorCode.Win32Error);
                    readerId++;
                }*/
                    EndPointId = GetEndpoint();
                    _reader = _device.OpenEndpointReader(EndPointId);
                    _thread.Start();
                    //_reader.DataReceivedEnabled = true;
                    //_reader.ReadBufferSize = 8;
                    //_reader.DataReceived += OnReaderDataReceived;
                }
            }
        }
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="T:System.Object"/>.
 /// </summary>
 public S5Pc100UsbConnection(IUsbDevice Device)
 {
     this.Device = Device;
 }
        private void _Init(int vendorId, int productId, int interfaceNumber)
        {
            _readers = new Dictionary<int, UsbEndpointReader>();
              _writers = new Dictionary<int, UsbEndpointWriter>();

              _forwardee = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(vendorId, productId)) as IUsbDevice;
              if (_forwardee == null) throw new InvalidOperationException("Device not found");

              _forwardee.ClaimInterface(interfaceNumber);
              _forwardee.SetConfiguration(1);
        }
Beispiel #50
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                if (MyUsbDevice == null)
                {
                    throw new Exception("Device Not Found.");
                    //connected = false;
                }
                else
                {
                    Device_l.Text = "Device: Connected";
                    //connected = true;

                    Scan_b.Enabled = true;

                    wholeUsbDevice = MyUsbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // This is a "whole" USB device. Before it can be used,
                        // the desired configuration and interface must be selected.

                        // Select config #1
                        wholeUsbDevice.SetConfiguration(1);

                        // Claim interface #0.
                        wholeUsbDevice.ClaimInterface(0);
                    }

                    reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep03);
                    writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep04);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
            }
        }
Beispiel #51
0
        private void _Init(bool throwErrors)
        {
            Dispose();

              _device = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(_VENDOR_ID, _PRODUCT_ID1)) as IUsbDevice;
              if (_device == null) _device = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(_VENDOR_ID, _PRODUCT_ID2)) as IUsbDevice;
              if (_device == null) _device = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(_VENDOR_ID, _PRODUCT_ID3)) as IUsbDevice;
              if (_device == null)
              {
            if (throwErrors)
              throw new InvalidOperationException("Wireless receiver not found");
              }
              else
              {
            _device.ClaimInterface(1);
            _device.SetConfiguration(1);

            _responses = new Dictionary<int, List<byte[]>>();
            var now = DateTime.Now;
            for (int i = 0; i < _NUMBER_OF_SLOTS; i++)
            {
              var slot = new ReceiverSlot();

              slot.DataWriter = _device.OpenEndpointWriter(_GetWriteEndpoint((i * 2) + 1));
              slot.DataReader = _device.OpenEndpointReader(_GetReadEndpoint((i * 2) + 1));
              slot.DataReader.DataReceived += DataReader_DataReceived;
              slot.DataReader.DataReceivedEnabled = true;
              slot.HeadsetWriter = _device.OpenEndpointWriter(_GetWriteEndpoint((i * 2) + 2));
              slot.HeadsetReader = _device.OpenEndpointReader(_GetReadEndpoint((i * 2) + 2));
              slot.HeadsetReader.DataReceived += HeadsetReader_DataReceived;
              slot.HeadsetReader.DataReceivedEnabled = true;

              _slots.Add(i + 1, slot);

              _RefreshSlot(i + 1);
            }

            _refreshSlotsThread = new Thread(new ThreadStart(_RefreshSlots));
            _refreshSlotsThread.IsBackground = true;
            _refreshSlotsThread.Start();
              }
        }
        public void connectReceiver()
        {
            // Connect to the Xbox Wireless Receiver and register the endpoint
            // readers/writers as necessary.
            try
            {
                // Open the Xbox Wireless Receiver as a USB device
                // VendorID 0x045e, ProductID 0x0719
                wirelessReceiver = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x045E, 0x0719)) as IUsbDevice;

                // If primary IDs not found attempt secondary IDs
                // VendorID 0x045e, Product ID 0x0291
                if (wirelessReceiver == null)
                    wirelessReceiver = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x045E, 0x0291)) as IUsbDevice;

                // If secondary IDs not found report the error
                if (wirelessReceiver == null)
                    parentWindow.Invoke(new logCallback(parentWindow.logMessage),
                        "ERROR: Wireless Receiver Not Found.");
                else
                {
                    // Set the Configuration, Claim the Interface
                    wirelessReceiver.ClaimInterface(1);
                    wirelessReceiver.SetConfiguration(1);

                    // Log if the Wireless Receiver was connected to successfully
                    if (wirelessReceiver.IsOpen)
                    {
                        receiverAttached = true;
                        parentWindow.Invoke(new logCallback(parentWindow.logMessage),
                            "Xbox 360 Wireless Receiver Connected.");

                        // Connect Bulk Endpoint Readers/Writers and register the receiving event handler
                        // Controller 1
                        epReaders[0] = wirelessReceiver.OpenEndpointReader(ReadEndpointID.Ep01);
                        epWriters[0] = wirelessReceiver.OpenEndpointWriter(WriteEndpointID.Ep01);
                        epReaders[0].DataReceived += new EventHandler<EndpointDataEventArgs>(xboxControllers[0].processDataPacket);
                        epReaders[0].DataReceivedEnabled = true;
                        xboxControllers[0].registerEndpointWriter(epWriters[0]);

                        // Controller 2
                        epReaders[1] = wirelessReceiver.OpenEndpointReader(ReadEndpointID.Ep03);
                        epWriters[1] = wirelessReceiver.OpenEndpointWriter(WriteEndpointID.Ep03);
                        epReaders[1].DataReceived += new EventHandler<EndpointDataEventArgs>(xboxControllers[1].processDataPacket);
                        epReaders[1].DataReceivedEnabled = true;
                        xboxControllers[1].registerEndpointWriter(epWriters[1]);

                        // Controller 3
                        epReaders[2] = wirelessReceiver.OpenEndpointReader(ReadEndpointID.Ep05);
                        epWriters[2] = wirelessReceiver.OpenEndpointWriter(WriteEndpointID.Ep05);
                        epReaders[2].DataReceived += new EventHandler<EndpointDataEventArgs>(xboxControllers[2].processDataPacket);
                        epReaders[2].DataReceivedEnabled = true;
                        xboxControllers[2].registerEndpointWriter(epWriters[2]);

                        // Controller 4
                        epReaders[3] = wirelessReceiver.OpenEndpointReader(ReadEndpointID.Ep07);
                        epWriters[3] = wirelessReceiver.OpenEndpointWriter(WriteEndpointID.Ep07);
                        epReaders[3].DataReceived += new EventHandler<EndpointDataEventArgs>(xboxControllers[3].processDataPacket);
                        epReaders[3].DataReceivedEnabled = true;
                        xboxControllers[3].registerEndpointWriter(epWriters[3]);

                        parentWindow.Invoke(new logCallback(parentWindow.logMessage),
                            "Searching for Controllers...Press the Guide Button Now.");
                    }
                }
            }
            catch
            {
                parentWindow.Invoke(new logCallback(parentWindow.logMessage),
                    "ERROR: Problem Connecting to Wireless Receiver.");
            }
        }
Beispiel #53
0
        public void Open()
        {
            if (_deviceReg.Open(out _device) == false)
            {
                throw new InvalidOperationException("Unable to open the dongle, was it removed?");
            }

            _writer = _device.OpenEndpointWriter(WriteEndpointID.Ep01, EndpointType.Bulk);
            _reader = _device.OpenEndpointReader(ReadEndpointID.Ep01, 32, EndpointType.Bulk);

            _iDevice = _device as IUsbDevice;

            if (_iDevice != null)
            {
                _iDevice.SetConfiguration(1);
                _iDevice.ClaimInterface(0);
            }

            Setup();
        }