Exemple #1
0
        private void bStopStreaming_Click(object sender, EventArgs e)
        {
            bool qResult;

            tbLog.AppendText(String.Format("********** Stopping stream **********\n", qusbError));

            // Stop the timer
            timer.Stop();

            // Stop the data stream
            qResult = qusb.StopStream(streamID, false);
            if (!qResult)
            {
                qusbError = qusb.LastError();
                tbLog.AppendText(String.Format("BulkDataStopStream failed with error {0}\n", qusbError));
            }

            // Close the module
            qResult = qusb.Close();
            if (!qResult)
            {
                Console.WriteLine("QuickUSB Error: {0}", qusb.LastError());
                return;
            }

            // Reset variables
            streaming = false;

            // Reset buttons
            bStartStreaming.Enabled = true;
            bStopStreaming.Enabled  = false;
        }
Exemple #2
0
        // QuickUSB Asynchronous Imaging Example
        void Acquire()
        {
            int k = 0;

            if (!aquiring)
            {
                return;
            }

            // Wait for the transaction to complete (The completion routine will be called)
            do
            {
                qResult = qusb.BulkWait(BulkStream[k], false);
                if (!qResult)
                {
                    qusbError = qusb.LastError();
                    if (qusbError == QuickUsb.Error.Timeout)
                    {
                        // While we wait for this request to complete, we could be performing some
                        // background tasks
                        timer1.Enabled = false;
                        Application.DoEvents();
                        timer1.Enabled = true;
                    }
                }
            } while (!qResult && qusb.LastError() == QuickUsb.Error.Timeout);

            if (!qResult)
            {
                qusbError = qusb.LastError();
                return;
            }
            // Calculate FPS
            QueryPerformanceCounter(out tEnd);
            tElapsed = (double)(tEnd - tStart) / (double)(freq);
            tStart   = tEnd;
            toolStripStatusLabel1.Text = String.Format("FPS: {0:0.0}", 1.0 / tElapsed);

            // Blit data to screen
            BitmapData bData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            MoveMemory(bData.Scan0, BufferArray[0], FrameByteSize);
            image.UnlockBits(bData);
            pbFrame.Invalidate();

            // Issue a new transaction
            qResult = qusb.ReadBulkDataAsync(
                BufferArray[0],
                FrameByteSize,
                BulkStream[0],
                cbDelegate,
                IntPtr.Zero);

            if (!qResult)
            {
                toolStripStatusLabel1.Text = "Error: Unable to issue data read";
                qusb.Close();
                return;
            }
        }
Exemple #3
0
        public void LastErrorTest()
        {
            QuickUsb target = new QuickUsb("QUSB-0");

            QuickUsb.Error expected = QuickUsb.Error.NoError;
            QuickUsb.Error actual;
            actual = target.LastError();
            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        private void bStartStreaming_Click(object sender, EventArgs e)
        {
            bool qResult;

            qusb = qusbControl.SelectedModule;

            tbLog.AppendText(String.Format("********** Starting stream **********\n", qusbError));

            // Open the module
            qResult = qusb.Open();
            if (!qResult)
            {
                tbLog.AppendText(String.Format("Unable to open module\n", qusbError));
                return;
            }

            // Start the data stream
            if (UserAllocatedBuffers)
            {
                // Start streaming data to our user allocated data buffers
                qResult = qusb.ReadBulkDataStartStream(BufferArray, NumBuffers, BufferByteSize, cbDelegate, IntPtr.Zero, out streamID, NumThreads, ThreadConcurrency);
            }
            else
            {
                // Start streaming data to data buffers that will be allocated interally by the Streaming API
                qResult = qusb.ReadBulkDataStartStream(IntPtr.Zero, NumBuffers, BufferByteSize, cbDelegate, IntPtr.Zero, out streamID, NumThreads, ThreadConcurrency);
            }

            // Check for an error starting the stream
            if (!qResult)
            {
                qusbError = qusb.LastError();
                qusb.Close();
                tbLog.AppendText(String.Format("ReadBulkDataStartStream failed with error {0}\n", qusbError));
                return;
            }

            // Reset buttons
            bStartStreaming.Enabled = false;
            bStopStreaming.Enabled  = true;

            // Reset variables
            TotalKiloBytes = 0;
            ErrorCount     = 0;
            streaming      = true;

            // Start throughput timer
            QueryPerformanceFrequency(out freq);
            QueryPerformanceCounter(out tStart);

            // Start timer
            timer.Start();
        }
Exemple #5
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (numPendingRequests != 0)
            {
                // If we are not multithreading the stream in this example, we must
                // allow time for processing requests.  Processing requests simply
                // means checking if a request has completed, execute its completion
                // routine, and re-issue the requests.  QuickUsb.ProcessStream will
                // return when either any request has completed or the specified time
                // has elapsed.
                if (NumThreads == 0)
                {
                    // Check if the next request has completed
                    bool qResult = qusb.BulkWait(bulkStream[nextRequestToProcess], true); // Don't block
                    if (!qResult)
                    {
                        qusbError = qusb.LastError();
                        if (qusbError != QuickUsb.Error.NotCompleted)
                        {
                            Console.WriteLine("ProcessStream failed with error {0}", qusbError);
                        }
                    }
                }
            }
            else
            {
                // All the requests have completed
                bIssueRead.Enabled  = true;
                bIssueWrite.Enabled = true;
                timer.Stop();

                // Close the module now that we're done with it
                qusb.Close();
            }

            // Report our data throughput
            dataRate.Text = String.Format("Data Rate: {0:0.0} MB/s Overall, {1:0.0} MB/s Instantaneously", overallRate, instRate);

            // Dump data to log
            lock (log)
            {
                tbLog.AppendText(log.ToString());
                log = new StringBuilder();
            }
        }
Exemple #6
0
        private void timer_Tick(object sender, EventArgs e)
        {
            // If we are not multithreading the stream in this example, we must
            // allow time for processing requests.  Processing requests simply
            // means checking if a request has completed, execute its completion
            // routine, and re-issue the requests.  QuickUsb.ProcessStream will
            // return when either any request has completed or the specified time
            // has elapsed.
            if (NumThreads == 0)
            {
                bool qResult = qusb.ProcessStream(streamID, 50);
                if (!qResult)
                {
                    qusbError = qusb.LastError();
                    Console.WriteLine("ProcessStream failed with error {0}", qusbError);
                }
            }

            // Time data rates
            QueryPerformanceCounter(out tEnd);
            double tElapsed     = (double)(tEnd - tStart) / (double)(freq);
            double tElapsedInst = (double)(tEnd - tLast) / (double)(freq);

            double overallRate = (TotalKiloBytes / 1024.0) / tElapsed;
            double instRate    = (InstKiloBytes / 1024.0) / tElapsedInst;

            InstKiloBytes = 0;
            tLast         = tEnd;

            // Report our data throughput
            dataRate.Text = String.Format("Data Rate: {0:0.0} MB/s Overall, {1:0.0} MB/s Instantaneously", overallRate, instRate);

            // Dump data to log
            lock (log)
            {
                tbLog.AppendText(log.ToString());
                log = new StringBuilder();
            }
        }
Exemple #7
0
        private void bIssueWrite_Click(object sender, EventArgs e)
        {
            bool qResult;

            qusb = qusbControl.SelectedModule;

            tbLog.AppendText(String.Format("********** Issuing {0} async writes **********\n", NumRequests));

            // Open the module
            qResult = qusb.Open();
            if (!qResult)
            {
                tbLog.AppendText(String.Format("Unable to open module\n", qusbError));
                return;
            }

            // Reset buttons
            bIssueRead.Enabled  = false;
            bIssueWrite.Enabled = true;

            // Reset variables
            TotalKiloBytes       = 0;
            ErrorCount           = 0;
            numPendingRequests   = 0;
            nextRequestToProcess = 0;

            // Set num threads and thread concurrency
            qResult = qusb.SetNumAsyncThreads(NumThreads, ThreadConcurrency);
            if (!qResult)
            {
                qusbError = qusb.LastError();
                tbLog.AppendText(String.Format("SetNumAsyncThreads failed with error {0}\n", qusbError));

                bIssueRead.Enabled  = false;
                bIssueWrite.Enabled = false;

                qusb.Close();
                return;
            }

            // Start throughput timer
            QueryPerformanceFrequency(out freq);
            QueryPerformanceCounter(out tStart);

            // Start streaming data to our user allocated data buffers
            for (int k = 0; k < NumRequests; ++k)
            {
                qResult = qusb.WriteBulkDataAsync(BufferArray[k], BufferByteSize, bulkStream[k], cbDelegate, IntPtr.Zero);

                // Check for an error issuing the request
                if (!qResult)
                {
                    qusbError = qusb.LastError();
                    tbLog.AppendText(String.Format("WriteBulkDataAsync failed with error {0}\n", qusbError));
                }
                else
                {
                    ++numPendingRequests;
                }
            }

            // Start timer
            timer.Start();
        }