Пример #1
0
        public SeekThermalPro(WinUSBEnumeratedDevice dev)
        {
            device = new WinUSBDevice(dev);

            // device setup sequence
            try
            {
                device.ControlTransferOut(0x41, 84, 0, 0, new byte[] { 0x01 });
            }
            catch
            {
                // Try deinit device and repeat.
                Deinit();
                device.ControlTransferOut(0x41, 84, 0, 0, new byte[] { 0x01 });
            }

            device.ControlTransferOut(0x41, 60, 0, 0, new byte[] { 0x00, 0x00 });

            byte[] data1 = device.ControlTransferIn(0xC1, 78, 0, 0, 4);

            byte[] data2 = device.ControlTransferIn(0xC1, 54, 0, 0, 12);

            // Analysis of 0x56 payload:
            // First byte seems to be half the size of the output data.
            // It seems like this command may be retriving some sensor data?
            device.ControlTransferOut(0x41, 86, 0, 0, new byte[] { 0x06, 0x00, 0x08, 0x00, 0x00, 0x00 });

            byte[] data3 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 12);

            device.ControlTransferOut(0x41, 85, 0, 0, new byte[] { 0x17, 0x00 });

            byte[] data4 = device.ControlTransferIn(0xC1, 78, 0, 0, 0x40);

            device.ControlTransferOut(0x41, 86, 0, 0, new byte[] { 0x0C, 0x00, 0x70, 0x00, 0x00, 0x00 });

            byte[] data5 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 2);

            device.ControlTransferOut(0x41, 86, 0, 0, new byte[] { 0x01, 0x00, 0x01, 0x06, 0x00, 0x00 });

            byte[] data6 = device.ControlTransferIn(0xC1, 88, 0, 0, 2);


            UInt16 addr;

            for (addr = 0; addr < 2560; addr += 32)
            {
                byte[] addrle_p = BitConverter.GetBytes(addr);
                device.ControlTransferOut(0x41, 86, 0, 0, new byte[] { 0x20, 0x00, addrle_p[0], addrle_p[1], 0x00, 0x00 });

                byte[] data7 = device.ControlTransferIn(0xC1, 88, 0, 0, 64);
            }

            device.ControlTransferOut(0x41, 85, 0, 0, new byte[] { 0x15, 0x00 });

            byte[] data8 = device.ControlTransferIn(0xC1, 78, 0, 0, 64);

            device.ControlTransferOut(0x41, 62, 0, 0, new byte[] { 0x08, 0x00 });

            device.ControlTransferOut(0x41, 60, 0, 0, new byte[] { 0x01, 0x00 });
        }
Пример #2
0
        public DFU(WinUSBEnumeratedDevice dev)
        {
            BaseDevice = new WinUSBDevice(dev);

            // Read DFU descriptors to fill in important details.
            FindDfuInterface();
        }
Пример #3
0
        const byte DataPipe = 0x01; // OUT 1

        public void Dispose()
        {
            if (BaseDevice != null)
            {
                BaseDevice.Dispose();
                BaseDevice = null;
            }
            GC.SuppressFinalize(this);
        }
Пример #4
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     foreach (WinUSBEnumeratedDevice dev in WinUSBDevice.EnumerateAllDevices())
     {
         if (dev.VendorID == 0x1d50 && dev.ProductID == 0x607A && dev.UsbInterface == 0)
         {
             yield return(dev);
         }
     }
 }
Пример #5
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     foreach (WinUSBEnumeratedDevice dev in WinUSBDevice.EnumerateAllDevices())
     {
         // Seek Thermal "iAP Interface" device - Use Zadig to install winusb driver on it.
         if (dev.VendorID == 0x289D && dev.ProductID == 0x0010 && dev.UsbInterface == 0)
         {
             yield return(dev);
         }
     }
 }
Пример #6
0
        public HackRF(WinUSBEnumeratedDevice dev)
        {
            Device = new WinUSBDevice(dev);

            // Set a bunch of sane defaults.
            SetSampleRate(10000000); // 10MHz
            SetFilterBandwidth(10000000);
            SetLnaGain(8);
            SetVgaGain(20);
            SetTxVgaGain(0);
        }
Пример #7
0
        public SeekThermal(WinUSBEnumeratedDevice dev)
        {
            device = new WinUSBDevice(dev);



            // device setup sequence
            try
            {
                device.ControlTransferOut(0x41, 0x54, 0, 0, new byte[] { 0x01 });
            }
            catch
            {
                // Try deinit device and repeat.
                Deinit();
                device.ControlTransferOut(0x41, 0x54, 0, 0, new byte[] { 0x01 });
            }

            device.ControlTransferOut(0x41, 0x3c, 0, 0, new byte[] { 0x00, 0x00 });

            byte[] data1 = device.ControlTransferIn(0xC1, 0x4e, 0, 0, 4);

            byte[] data2 = device.ControlTransferIn(0xC1, 0x36, 0, 0, 12);

            // Analysis of 0x56 payload:
            // First byte seems to be half the size of the output data.
            // It seems like this command may be retriving some sensor data?
            device.ControlTransferOut(0x41, 0x56, 0, 0, new byte[] { 0x20, 0x00, 0x30, 0x00, 0x00, 0x00 });

            byte[] data3 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 0x40);

            device.ControlTransferOut(0x41, 0x56, 0, 0, new byte[] { 0x20, 0x00, 0x50, 0x00, 0x00, 0x00 });

            byte[] data4 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 0x40);

            device.ControlTransferOut(0x41, 0x56, 0, 0, new byte[] { 0x0C, 0x00, 0x70, 0x00, 0x00, 0x00 });

            byte[] data5 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 0x18);

            device.ControlTransferOut(0x41, 0x56, 0, 0, new byte[] { 0x06, 0x00, 0x08, 0x00, 0x00, 0x00 });

            byte[] data6 = device.ControlTransferIn(0xC1, 0x58, 0, 0, 0x0c);


            device.ControlTransferOut(0x41, 0x3E, 0, 0, new byte[] { 0x08, 0x00 });

            byte[] data7 = device.ControlTransferIn(0xC1, 0x3D, 0, 0, 2);

            device.ControlTransferOut(0x41, 0x3E, 0, 0, new byte[] { 0x08, 0x00 });

            device.ControlTransferOut(0x41, 0x3C, 0, 0, new byte[] { 0x01, 0x00 });

            byte[] data8 = device.ControlTransferIn(0xC1, 0x3D, 0, 0, 2);
        }
Пример #8
0
 private void _Init(string[] devicePaths)
 {
     if (Mode == OperatingMode.HID && devicePaths.Length >= 2)
     {
         _hidDevice1 = new HidDevice(devicePaths.ElementAt(0));
         _hidDevice2 = new HidDevice(devicePaths.ElementAt(1));
     }
     else if (devicePaths.Length > 0)
     {
         _winUsbDevice = new WinUSBDevice(devicePaths.First());
     }
 }
Пример #9
0
        public RgbButton(WinUSBEnumeratedDevice dev)
        {
            BaseDevice = new WinUSBDevice(dev);

            ButtonColors  = new RGBColor[4];
            ButtonValues  = new int[4];
            ButtonPressed = new bool[4];

            BaseDevice.EnableBufferedRead(IN_PIPE);
            BaseDevice.BufferedReadNotifyPipe(IN_PIPE, NewDataCallback);
            EnableButtonData();
        }
Пример #10
0
        public HackRF(WinUSBEnumeratedDevice dev)
        {
            Device = new WinUSBDevice(dev);

            SetBufferSettings(512, 128); // 64MB of data
            ResetBuffers();

            // Set a bunch of sane defaults.
            SetSampleRate(10000000); // 10MHz
            SetFilterBandwidth(10000000);
            SetLnaGain(8);
            SetVgaGain(20);
            SetTxVgaGain(0);
        }
Пример #11
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     foreach (WinUSBEnumeratedDevice dev in WinUSBDevice.EnumerateAllDevices())
     {
         // HackRF One
         if (dev.VendorID == 0x1d50 && dev.ProductID == 0x6089 && dev.UsbInterface == 0)
         {
             yield return(dev);
         }
         // HackRF Jawbreaker
         if (dev.VendorID == 0x1d50 && dev.ProductID == 0x604b && dev.UsbInterface == 0)
         {
             yield return(dev);
         }
     }
 }
Пример #12
0
        private void _Close()
        {
            if (_hidDevice1 != null)
            {
                _hidDevice1.Close();
                _hidDevice1 = null;
            }

            if (_hidDevice2 != null)
            {
                _hidDevice2.Close();
                _hidDevice2 = null;
            }

            if (_winUsbDevice != null)
            {
                _winUsbDevice.Dispose();
                _winUsbDevice = null;
            }
        }
Пример #13
0
 public void Close()
 {
     BaseDevice.Close();
     BaseDevice = null;
 }
Пример #14
0
 public SignTest(WinUSBEnumeratedDevice deviceInfo)
 {
     Device = new WinUSBDevice(deviceInfo);
 }
Пример #15
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     return(WinUSBDevice.EnumerateDevices(new Guid("60d2a26c-1d22-4538-b7d5-337b2f07fff1")));
 }
Пример #16
0
        // Temporary test application to validate functionality as it's being built.
        static void Main(string[] args)
        {
            Guid   testGuid = new Guid("d2938a49-3191-4b25-ba33-e45f0828ced4");
            Random r        = new Random();

            WinUSBEnumeratedDevice[] allDevices = WinUSBDevice.EnumerateAllDevices().ToArray();
            foreach (WinUSBEnumeratedDevice devicePath in allDevices)
            {
                Console.Out.WriteLine(devicePath.ToString());
                try {
                    WinUSBDevice d = new WinUSBDevice(devicePath);
                    try {
                        DeviceDescriptor dev = d.GetDeviceDescriptor();
                        Console.Out.WriteLine(dev.ToString());
                        ConfigurationDescriptor cfg = d.GetConfigurationDescriptor();
                        Console.Out.WriteLine(cfg.ToString());
                    }
                    finally
                    {
                        d.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine("Exception while querying descriptors: {0}", ex);
                }
            }


            WinUSBEnumeratedDevice[] devices = WinUSBDevice.EnumerateDevices(testGuid).ToArray();
            foreach (WinUSBEnumeratedDevice devicePath in devices)
            {
                Console.Out.WriteLine(devicePath);

                WinUSBDevice test = new WinUSBDevice(devicePath);

                // Try a data test. Test board just has OUT 3 looped back into IN 3
                // Set pipe timeouts to avoid hanging forever.
                test.SetPipePolicy(0x03, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 100);
                test.SetPipePolicy(0x83, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 100);

                // Send some junk via OUT 3
                byte[] data = new byte[128];
                r.NextBytes(data);

                // Flush out any data that might have been here from a previous run...
                // Will take about as long as the transfer timeout.
                while (test.ReadPipe(0x83, 64).Length != 0)
                {
                    ;
                }


                test.WritePipe(0x03, data);

                // read it back.
                byte[] returnData = test.ReadExactPipe(0x83, data.Length);

                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] != returnData[i])
                    {
                        throw new Exception("Error validating data returned from the device!");
                    }
                }
                Console.Out.WriteLine("Passed basic transfer test");

                // Timeout test
                returnData = test.ReadPipe(0x83, 32);
                if (returnData.Length != 0)
                {
                    throw new Exception("Pipe didn't timeout, where did it get that data?");
                }
                Console.Out.WriteLine("Passed timeout test");

                test.Close();
                test.Close(); // checking that double close doesn't cause issues.
            }

            Console.Out.WriteLine("{0} device{1}", devices.Length, devices.Length == 1?"":"s");

            WinUSBEnumeratedDevice[] hackrfs = HackRF.Enumerate().ToArray();
            if (hackrfs.Length > 0)
            {
                Console.WriteLine("Connecting to hackrf device {0}", hackrfs[0].ToString());

                HackRF rf = new HackRF(hackrfs[0]);

                Console.WriteLine("Version String: {0}", rf.ReadVersion());

                // Do some benchmarking with the receive modes.
                rf.SetSampleRate(2000000);
                rf.ModeReceive();
                rf.SetFrequency(100000000); // 100 MHz
                rf.SetSampleRate(10000000);

                int      lastEaten      = 0;
                int      eaten          = rf.PacketsEaten;
                long     lastEatenBytes = 0;
                long     eatenBytes     = rf.BytesEaten;
                DateTime lastTime       = DateTime.Now;
                while (true)
                {
                    System.Threading.Thread.Sleep(2000);
                    DateTime newTime = DateTime.Now;
                    lastEaten      = eaten;
                    eaten          = rf.PacketsEaten;
                    lastEatenBytes = eatenBytes;
                    eatenBytes     = rf.BytesEaten;
                    double seconds = newTime.Subtract(lastTime).TotalSeconds;
                    double pps     = (eaten - lastEaten) / seconds;
                    double mbps    = ((eatenBytes - lastEatenBytes) / seconds) / 1000000;
                    lastTime = newTime;


                    Console.WriteLine("Receiving... {0}  {1:n2}pps {2:n4}MB/s", eaten, pps, mbps);
                    string[] histogramData;
                    lock (rf)
                    {
                        histogramData = rf.EatenHistogram.OrderByDescending(kv => kv.Value).Take(8).Select(kv => string.Format("{0}:{1}", kv.Key, kv.Value)).ToArray();
                    }
                    Console.WriteLine(string.Join(" ", histogramData));
                }
            }


            WinUSBEnumeratedDevice[] fadecandies = Fadecandy.Enumerate().ToArray();
            if (fadecandies.Length > 0)
            {
                Fadecandy fc = new Fadecandy(fadecandies[0]);

                RgbRing ring = new RgbRing(24);

                double t = 0;
                while (true)
                {
                    ring.Update(t);
                    Array.Copy(ring.Ring, fc.Pixels, 24);
                    fc.Pixels[64].G = Math.Sin(t) * 0.2 + 0.2;
                    fc.FlushRange(0, 65);

                    t += 0.01;
                    System.Threading.Thread.Sleep(10);
                }
            }


            WinUSBEnumeratedDevice[] rgbbuttons = RgbButton.Enumerate().ToArray();
            if (rgbbuttons.Length > 0)
            {
                RgbButton rb = new RgbButton(rgbbuttons[0]);

#if false
                { // Put device into programming mode.
                    rb.EnterProgrammingMode();
                    return;
                }
#endif

                double t = 0;
                while (true)
                {
                    rb.ButtonColors[0].G = Math.Sin(t) * 0.2 + 0.2;
                    rb.ButtonColors[1].R = Math.Sin(t) * 0.2 + 0.2;
                    rb.ButtonColors[2].G = 0.5 - rb.ButtonValues[0] / 256.0;
                    rb.ButtonColors[2].R = 0.5 - rb.ButtonValues[1] / 256.0;
                    rb.ButtonColors[2].B = 0.5 - rb.ButtonValues[3] / 256.0;
                    rb.ButtonColors[3].B = (rb.DataCount & 1023) / 2048.0;
                    rb.SendButtonColors();

                    t += 0.02;
                    System.Threading.Thread.Sleep(20);

                    Console.WriteLine("{0} {1} {2} {3}", rb.ButtonValues[0], rb.ButtonValues[1], rb.ButtonValues[2], rb.ButtonValues[3]);
                }
            }
        }
Пример #17
0
 public void Close()
 {
     Device.Close();
     Device = null;
 }
Пример #18
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     return(WinUSBDevice.EnumerateDevices(new Guid("8ac47a88-cc26-4aa9-887b-42ca8cf07a63")));
 }
Пример #19
0
 public Ubertooth(WinUSBEnumeratedDevice dev)
 {
     Device = new WinUSBDevice(dev);
 }
Пример #20
0
 public Fadecandy(WinUSBEnumeratedDevice dev)
 {
     BaseDevice = new WinUSBDevice(dev);
     Pixels     = new RGBColor[512];
     Initialize();
 }
Пример #21
0
 public static IEnumerable <WinUSBEnumeratedDevice> Enumerate()
 {
     return(WinUSBDevice.EnumerateDevices(new Guid("b86d3dd6-c9d8-4401-959b-efbbd9bf1f3c")));
 }