コード例 #1
0
        internal BufferedPipeThread(WinUSBDevice dev, byte pipeId, int bufferCount, int bufferSize)
        {
            Device       = dev;
            DevicePipeId = pipeId;
            int maxTransferSize = (int)dev.GetPipePolicy(pipeId, WinUsbPipePolicy.MAXIMUM_TRANSFER_SIZE);

            if (bufferSize > maxTransferSize)
            {
                bufferSize = maxTransferSize;
            }

            Buffers    = new QueuedBuffer[bufferCount];
            ReadEvents = new ManualResetEvent[bufferCount + 1];
            for (int i = 0; i < bufferCount; i++)
            {
                Buffers[i]    = new QueuedBuffer(bufferSize);
                ReadEvents[i] = Buffers[i].Overlapped.WaitEvent;
            }
            StopEvent = new ManualResetEvent(false);
            ReadEvents[bufferCount] = StopEvent;

            PipeThread = new Thread(ThreadFunc);
            PipeThread.IsBackground = true;

            foreach (QueuedBuffer qb in Buffers)
            {
                Device.BeginReadPipe(pipeId, qb);
            }
            PipeThread.Start();
        }
コード例 #2
0
ファイル: RgbButton.cs プロジェクト: apextw/winusbdotnet
        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);
            EnableDisplayTimeout();
            EnableButtonData();
        }
コード例 #3
0
ファイル: HackRF.cs プロジェクト: apextw/winusbdotnet
        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);
        }
コード例 #4
0
        public BufferedPipeThread(WinUSBDevice dev, byte pipeId, int bufferCount, int bufferSize)
        {
            int maxTransferSize = (int)dev.GetPipePolicy(pipeId, WinUsbPipePolicy.MAXIMUM_TRANSFER_SIZE);

            if (bufferSize > maxTransferSize)
            {
                bufferSize = maxTransferSize;
            }

            BufferLock      = new object();
            PendingBuffers  = new Queue <QueuedBuffer>(bufferCount);
            ReceivedBuffers = new Queue <QueuedBuffer>(bufferCount);
            RequeuePending  = new Queue <QueuedBuffer>(bufferCount);
            BufferList      = new QueuedBuffer[bufferCount];
            for (int i = 0; i < bufferCount; i++)
            {
                BufferList[i] = new QueuedBuffer(bufferSize);
            }

            Device                    = dev;
            DevicePipeId              = pipeId;
            QueuedLength              = 0;
            ReceivedData              = new Queue <byte[]>();
            ReceiveTick               = new ManualResetEvent(false);
            PipeThread                = new Thread(ThreadFunc);
            PipeThread.IsBackground   = true;
            WorkerThread              = new Thread(WorkerThreadFunc);
            WorkerThread.IsBackground = true;
            ThreadNewData             = new AutoResetEvent(false);


            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 1000);

            // Start reading on all the buffers.
            foreach (QueuedBuffer qb in BufferList)
            {
                dev.BeginReadPipe(pipeId, qb);
                PendingBuffers.Enqueue(qb);
            }

            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.RAW_IO, 1);

            PipeThread.Start();
            WorkerThread.Start();
        }
コード例 #5
0
ファイル: WinUSBDevice.cs プロジェクト: nymda/SeekSharp
        public BufferedPipeThread(WinUSBDevice dev, byte pipeId, int bufferCount, int multiPacketCount)
        {
            int maxTransferSize = (int)dev.GetPipePolicy(pipeId, WinUsbPipePolicy.MAXIMUM_TRANSFER_SIZE);

            int pipeSize   = 512; // Todo: query pipe transfer size for 1:1 mapping to packets.
            int bufferSize = pipeSize * multiPacketCount;

            if (bufferSize > maxTransferSize)
            {
                bufferSize = maxTransferSize;
            }

            PendingBuffers = new Queue <QueuedBuffer>(bufferCount);
            BufferList     = new QueuedBuffer[bufferCount];
            for (int i = 0; i < bufferCount; i++)
            {
                BufferList[i] = new QueuedBuffer(bufferSize);
            }

            EventConcurrency        = new Semaphore(3, 3);
            Device                  = dev;
            DevicePipeId            = pipeId;
            QueuedLength            = 0;
            ReceivedData            = new Queue <byte[]>();
            ReceiveTick             = new ManualResetEvent(false);
            PipeThread              = new Thread(ThreadFunc);
            PipeThread.IsBackground = true;

            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 1000);

            // Start reading on all the buffers.
            foreach (QueuedBuffer qb in BufferList)
            {
                dev.BeginReadPipe(pipeId, qb);
                PendingBuffers.Enqueue(qb);
            }

            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.RAW_IO, 1);

            PipeThread.Start();
        }
コード例 #6
0
ファイル: Fadecandy.cs プロジェクト: apextw/winusbdotnet
 public void Close()
 {
     BaseDevice.Close();
     BaseDevice = null;
 }
コード例 #7
0
ファイル: Fadecandy.cs プロジェクト: apextw/winusbdotnet
        const byte DataPipe = 0x01; // OUT 1

        public void Dispose()
        {
            if (BaseDevice != null)
            {
                BaseDevice.Dispose();
                BaseDevice = null;
            }
            GC.SuppressFinalize(this);
        }
コード例 #8
0
ファイル: Fadecandy.cs プロジェクト: apextw/winusbdotnet
 public Fadecandy(WinUSBEnumeratedDevice dev)
 {
     BaseDevice = new WinUSBDevice(dev);
     Pixels = new RGBColor[512];
     Initialize();
 }
コード例 #9
0
ファイル: HackRF.cs プロジェクト: apextw/winusbdotnet
 public void Close()
 {
     Device.Close();
     Device = null;
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: apextw/winusbdotnet
        // 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());
            }


            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]);
                }


            }

        }
コード例 #11
0
ファイル: SeekThermal.cs プロジェクト: apextw/winusbdotnet
        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);



        }
コード例 #12
0
ファイル: Ubertooth.cs プロジェクト: apextw/winusbdotnet
        public Ubertooth(WinUSBEnumeratedDevice dev)
        {
            Device = new WinUSBDevice(dev);

        }
コード例 #13
0
ファイル: WinUSBDevice.cs プロジェクト: apextw/winusbdotnet
        public BufferedPipeThread(WinUSBDevice dev, byte pipeId, int bufferCount, int bufferSize)
        {


            int maxTransferSize = (int)dev.GetPipePolicy(pipeId, WinUsbPipePolicy.MAXIMUM_TRANSFER_SIZE);

            if (bufferSize > maxTransferSize) { bufferSize = maxTransferSize; }

            BufferLock = new object();
            PendingBuffers = new Queue<QueuedBuffer>(bufferCount);
            ReceivedBuffers = new Queue<QueuedBuffer>(bufferCount);
            RequeuePending = new Queue<QueuedBuffer>(bufferCount);
            BufferList = new QueuedBuffer[bufferCount];
            for (int i = 0; i < bufferCount;i++)
            {
                BufferList[i] = new QueuedBuffer(bufferSize);
            }

            Device = dev;
            DevicePipeId = pipeId;
            QueuedLength = 0;
            ReceivedData = new Queue<byte[]>();
            ReceiveTick = new ManualResetEvent(false);
            PipeThread = new Thread(ThreadFunc);
            PipeThread.IsBackground = true;
            WorkerThread = new Thread(WorkerThreadFunc);
            WorkerThread.IsBackground = true;
            ThreadNewData = new AutoResetEvent(false);


            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.PIPE_TRANSFER_TIMEOUT, 1000);

            // Start reading on all the buffers.
            foreach(QueuedBuffer qb in BufferList)
            {
                dev.BeginReadPipe(pipeId, qb);
                PendingBuffers.Enqueue(qb);
            }

            //dev.SetPipePolicy(pipeId, WinUsbPipePolicy.RAW_IO, 1);

            PipeThread.Start();
            WorkerThread.Start();
        }
コード例 #14
0
ファイル: SignTest.cs プロジェクト: sgstair/ledsign
 public SignTest(WinUSBEnumeratedDevice deviceInfo)
 {
     Device = new WinUSBDevice(deviceInfo);
 }