Exemplo n.º 1
0
        /*Summary
         * Called at the end of recursive method, LockNLoad().
         * XferData() implements the infinite transfer loop
         */
        public unsafe void XferData(byte[][] cBufs, byte[][] xBufs, byte[][] oLaps, ISO_PKT_INFO[][] pktsInfo)
        {
            int k       = 0;
            int len     = 0;
            int pDataBF = 0;

            Successes = 0;
            Failures  = 0;
            XferBytes = 0;

            for (; bRunning;)
            {
                // WaitForXfer
                fixed(byte *tmpOvlap = oLaps[k])
                {
                    OVERLAPPED *ovLapStatus = (OVERLAPPED *)tmpOvlap;

                    if (!inEndpoint.WaitForXfer(ovLapStatus->hEvent, 500))
                    {
                        inEndpoint.Abort();
                        PInvoke.WaitForSingleObject(ovLapStatus->hEvent, 500);
                    }
                }

                // FinishDataXfer
                if (inEndpoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                {
                    XferBytes += len;
                    Successes++;
                    Array.Copy(xBufs[k], 0, DataBuf[pDataBF], 0, len);
                    pDataBF++;
                }
                else
                {
                    Failures++;
                }
                k++;
                if (k == QueueSz)  // Finish
                {
                    k = 0;
                    Thread.Sleep(1);
                    if (Failures == 0)
                    {
                        // this.Invoke(Img_View);
                        Img_View();
                    }
                    else
                    {
                        // Scanner busy
                        //MessageBox.Show("Scanner Busy! Please Try again.");
                    }
                    bRunning = false;
                }
            }
        }
Exemplo n.º 2
0
        public unsafe void XferData(byte[][] cBufs, byte[][] xBufs, byte[][] oLaps, ISO_PKT_INFO[][] pktsInfo, GCHandle[] handleOverlap)
        {
            int k   = 0;
            int len = 0;

            Successes = 0;
            Failures  = 0;

            XferBytes = 0;
            t1        = DateTime.Now;
            long nIteration = 0;

            CyUSB.OVERLAPPED  ovData = new CyUSB.OVERLAPPED();
            DisplayPacketInfo dp     = new DisplayPacketInfo((int x, int y, double z) => UpdatePackageInfo(x, y, z));

            for (; bRunning;)
            {
                nIteration++;
                // WaitForXfer
                unsafe
                {
                    //fixed (byte* tmpOvlap = oLaps[k])
                    {
                        ovData = (CyUSB.OVERLAPPED)Marshal.PtrToStructure(handleOverlap[k].AddrOfPinnedObject(), typeof(CyUSB.OVERLAPPED));
                        if (!BulkInEndPoint.WaitForXfer(ovData.hEvent, 500))
                        {
                            BulkInEndPoint.Abort();
                            PInvoke.WaitForSingleObject(ovData.hEvent, 500);
                        }
                    }
                }

                // FinishDataXfer
                int FirstPackage;
                int LastPackage = 0;
                int PkgLength;
                if (BulkInEndPoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                {
                    XferBytes += len;
                    //if(xBufs[k] != null)
                    if (len != 0)
                    {
                        byte[] DataToFile = new byte[len];
                        Array.Copy(xBufs[k], DataToFile, len);
                        //AcqDataBuffer.SetData(DataToFile);
                        ThreadData.Add(DataToFile);
                        FirstPackage = DataToFile[0] + (DataToFile[1] << 8) + (DataToFile[2] << 16) + (DataToFile[3] << 24);
                        PkgLength    = DataToFile.Length;
                        LastPackage  = DataToFile[PkgLength - 4] + (DataToFile[PkgLength - 3] << 8) + (DataToFile[PkgLength - 2] << 16) + (DataToFile[PkgLength - 1] << 24);
                    }
                    Successes++;
                }
                else
                {
                    Failures++;
                }


                // Re-submit this buffer into the queue
                len = BufSz;
                if (BulkInEndPoint.BeginDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]) == false)
                {
                    Failures++;
                }

                Thread.Sleep(10);

                k++;
                if (k == QueueSz)  // Only update displayed stats once each time through the queue
                {
                    k = 0;

                    t2      = DateTime.Now;
                    elapsed = t2 - t1;

                    xferRate = XferBytes / elapsed.TotalMilliseconds;
                    xferRate = xferRate / (1000.0);
                    Dispatcher.Invoke(dp, (int)Successes, (int)Failures, (double)xferRate);
                    // Call StatusUpdate() in the main thread
                    //if (bRunning == true) this.Invoke(updateUI);

                    // For small QueueSz or PPX, the loop is too tight for UI thread to ever get service.
                    // Without this, app hangs in those scenarios.
                    Thread.Sleep(0);
                }
                Thread.Sleep(0);
            } // End infinite loop
            // Let's recall all the queued buffer and abort the end point.
            BulkInEndPoint.Abort();
            //AcqDataBuffer.SetDataDone();
            ThreadData.CompleteAdding();
        }
Exemplo n.º 3
0
        private unsafe void XferData(byte[][] cBufs, byte[][] xBufs, byte[][] oLaps)
        {
            int k   = 0;
            int len = 0;

            XferBytes = 0;
            sw.Restart();

            while (bRunning)
            {
                // WaitForXfer
                fixed(byte *tmpOvlap = oLaps[k])
                {
                    OVERLAPPED *ovLapStatus = (OVERLAPPED *)tmpOvlap;

                    if (!bulkInEndPoint.WaitForXfer(ovLapStatus->hEvent, 500))
                    {
                        bulkInEndPoint.Abort();
                        PInvoke.WaitForSingleObject(ovLapStatus->hEvent, CyConst.INFINITE);
                    }
                }

                // FinishDataXfer
                if (bulkInEndPoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                {
                    XferBytes += len;
                }


                k++;
                if (k == QueueSz)  // Only update displayed stats once each time through the queue
                {
                    k        = 0;
                    xferRate = (sw.ElapsedMilliseconds > 0) ? ((long)XferBytes / sw.ElapsedMilliseconds) : (long)XferBytes;
                    if (!continousMode)
                    {
                        sw.Stop();
                        bRunning = false;
                    }

                    /*if (continousMode)
                     * {
                     *  Array.Clear(resultBuffer, 0, BufSz * QueueSz);
                     * }*/
                    for (int i = 0; i < xBufs.Length; i++)
                    {
                        Array.Copy(xBufs[i], 0, resultBuffer, BufSz * i, BufSz);
                    }
                    resultLength = (long)XferBytes;

                    CaptureEventArgs args = new CaptureEventArgs();
                    args.BytesCaptures = resultLength;
                    args.IsError       = false;
                    syncContext.Post(e => CaptureCompleted?.Invoke(this, args), args);
                    if (continousMode)
                    {
                        Thread.Sleep(1);
                    }
                }

                if (continousMode)
                {
                    len = BufSz;
                    Array.Clear(xBufs[k], 0, BufSz);
                    bulkInEndPoint.BeginDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]);
                }
            } // End infinite loop
        }