private void InitialAdd()
        {
            IntPtr deviceProfilePtrPtr;
            var    ret = NativeMethods.GetDeviceList(context, out deviceProfilePtrPtr);

            if (ret > 0 || deviceProfilePtrPtr == IntPtr.Zero)
            {
                for (var i = 0; i < ret; i++)
                {
                    // calculate the offset pointer
                    var deviceProfilePtr =
                        Marshal.ReadIntPtr(new IntPtr(deviceProfilePtrPtr.ToInt64() + i * IntPtr.Size));

                    var desc = new LibUsbDeviceDescriptor();
                    NativeMethods.GetDeviceDescriptor(deviceProfilePtr, desc);

                    if (desc.idVendor == TreehopperUsb.Settings.Vid && desc.idProduct == TreehopperUsb.Settings.Pid)
                    {
                        var board = new TreehopperUsb(new LibUsbConnection(deviceProfilePtr));
                        Debug.WriteLine("Adding " + board);
                        Boards.Add(board);
                    }
                }
            }
        }
예제 #2
0
        public LibUsbConnection(IntPtr deviceProfile)
        {
            var desc = new LibUsbDeviceDescriptor();

            NativeMethods.GetDeviceDescriptor(deviceProfile, desc);
            this.deviceProfile = deviceProfile;

            Task.Run(OpenAsync).Wait();
            var sb = new StringBuilder();

            NativeMethods.GetStringDescriptor(deviceHandle, 2, sb, sb.Capacity + 1);
            Name = sb.ToString();
            NativeMethods.GetStringDescriptor(deviceHandle, 3, sb, sb.Capacity + 1);
            Serial = sb.ToString();
            Close();
            var hex = desc.bcdDevice;                                                                                                       // 0x0111 = 1.11

            Version    = (ushort)((hex & 0x0f) + (10 * ((hex >> 4) & 0x0f)) + (100 * ((hex >> 8) & 0x0f)) + (1000 * ((hex >> 12) & 0x0f))); // convert 0x1234 to 1234
            DevicePath = deviceProfile.ToString();
        }
예제 #3
0
 public static extern int GetDeviceDescriptor([In] IntPtr deviceProfileHandle,
                                              [Out] LibUsbDeviceDescriptor deviceDescriptor);