private unsafe void LockNLoad(ref int j, byte[][] cBufs, byte[][] xBufs, byte[][] oLaps, ISO_PKT_INFO[][] pktsInfo)
        {
            CyIsocEndPoint InEndpt = usbdevice.IsocInEndPt;


            cBufs[j] = new byte[CyConst.SINGLE_XFER_LEN + bulkendpoint.MaxPktSize + ((bulkendpoint.XferMode == XMODE.BUFFERED) ? buffersize : 0)];

            xBufs[j]    = new byte[buffersize];
            oLaps[j]    = new byte[20];
            pktsInfo[j] = new ISO_PKT_INFO[M280DEF.Packet_Xfer];

            fixed(byte *tL0 = oLaps[j], tc0 = cBufs[j], tb0 = xBufs[j])
            {
                OVERLAPPED *ovLapStatus = (OVERLAPPED *)tL0;

                ovLapStatus->hEvent = PInvoke.CreateEvent(0, 0, 0, 0);
                int len = buffersize;

                bulkendpoint.BeginDataXfer(ref cBufs[j], ref xBufs[j], ref len, ref oLaps[j]);
                j++;
                if (j < queuesize)
                {
                    LockNLoad(ref j, cBufs, xBufs, oLaps, pktsInfo);
                }
                else
                {
                    XferData(cBufs, xBufs, oLaps, pktsInfo);
                }
            }
        }
Пример #2
0
 public void ReadAsysnchonous()
 {
     if (InEndpoint.Attributes == 1)
     {
         CyIsocEndPoint isoc = InEndpoint as CyIsocEndPoint;
         // FinishDataXfer
         if (isoc.FinishDataXfer(ref cBufs, ref xBufs, ref BufSz, ref oLaps, ref pktsInfo))
         {
             LogHelper.GetLogger <USB>().Debug("isoc finish data xfer: ");
         }
         else
         {
             if (InEndpoint.FinishDataXfer(ref cBufs, ref xBufs, ref BufSz, ref oLaps))
             {
                 LogHelper.GetLogger <USB>().Debug("finish data xfer: ");
             }
         }
     }
 }
Пример #3
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;

            Successes = 0;
            Failures  = 0;

            XferBytes = 0;
            t1        = DateTime.Now;

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

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

                if (EndPoint.Attributes == 1)
                {
                    CyIsocEndPoint isoc = EndPoint as CyIsocEndPoint;
                    // FinishDataXfer
                    if (isoc.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k], ref pktsInfo[k]))
                    {
                        //XferBytes += len;
                        //Successes++;

                        ISO_PKT_INFO[] pkts = pktsInfo[k];

                        for (int j = 0; j < PPX; j++)
                        {
                            if (pkts[j].Status == 0)
                            {
                                XferBytes += pkts[j].Length;

                                Successes++;
                            }
                            else
                            {
                                Failures++;
                            }

                            pkts[j].Length = 0;
                        }
                    }
                    else
                    {
                        Failures++;
                    }
                }
                else
                {
                    // FinishDataXfer
                    if (EndPoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                    {
                        XferBytes += len;
                        Successes++;
                    }
                    else
                    {
                        Failures++;
                    }
                }

                // Re-submit this buffer into the queue
                len = BufSz;
                EndPoint.BeginDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]);

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

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

                    xferRate = (long)(XferBytes / elapsed.TotalMilliseconds);
                    xferRate = xferRate / (int)100 * (int)100;

                    // Call StatusUpdate() in the main thread
                    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(1);
                }
            } // End infinite loop
            // Let's recall all the queued buffer and abort the end point.
            EndPoint.Abort();
        }
Пример #4
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;

            index = QueueSz;

            Successes = 0;
            Failures  = 0;

            //   int XfersperWrite = 0;

            XferBytes = 0;
            t1        = DateTime.Now;
            //  byte temp[];

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

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

                if (EndPoint.Attributes == 1)
                {
                    CyIsocEndPoint isoc = EndPoint as CyIsocEndPoint;
                    // FinishDataXfer
                    if (isoc.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k], ref pktsInfo[k]))
                    {
                        //XferBytes += len;
                        //Successes++;

                        ISO_PKT_INFO[] pkts = pktsInfo[k];

                        for (int j = 0; j < PPX; j++)
                        {
                            if (pkts[j].Status == 0)
                            {
                                XferBytes += pkts[j].Length;

                                Successes++;
                            }
                            else
                            {
                                Failures++;
                            }

                            pkts[j].Length = 0;
                        }
                    }
                    else
                    {
                        Failures++;
                    }
                }
                else
                {
                    // FinishDataXfer
                    if (EndPoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                    {
                        XferBytes += len;
                        Successes++;
                        if (Save == true) //mady
                        {
                            if (Offset >= (80 * 1024 * 1024))
                            {
                                //Buffer.BlockCopy(temp, 0, fifo_1, 0, Offset);
                                Buffer.BlockCopy(temp, 0, fifo_1, 0, (80 * 1024 * 1024));
                                //Offset1 = Offset;
                                Offset1 = (80 * 1024 * 1024);
                                //Thread th_saveFile = new Thread(new ThreadStart(saveData));
                                Thread th_saveFile = new Thread(new ThreadStart(saveData));  //创建保存文件进程
                                th_saveFile.Start();
                                Offset = Offset - (80 * 1024 * 1024);
                            }
                            //                           else
                            {
                                int len_temp;
                                len_temp = len;
                                Buffer.BlockCopy(xBufs[k], 0, temp, Offset, len_temp); //mady : Backup the received data to Temp buffer
                                index++;                                               //mady
                                Offset += len_temp;
                            }
                        }
                    }
                    else
                    {
                        Failures++;
                    }
                }

                // Re-submit this buffer into the queue
                len = BufSz;
                EndPoint.BeginDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]);

                //if (Save == true) //mady
                //{
                //    Buffer.BlockCopy(xBufs[k], 0, temp, index * PPX * EndPoint.MaxPktSize, PPX * EndPoint.MaxPktSize);  //mady : Backup the received data to Temp buffer
                //    index++;  //mady

                //}

                k++;

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



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

                    xferRate = (long)(XferBytes / elapsed.TotalMilliseconds);
                    xferRate = xferRate / (int)100 * (int)100;

                    // Call StatusUpdate() in the main thread
                    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(1);
                } // End infinite loop
                  // Let's recall all the queued buffer and abort the end point.
            }
            EndPoint.Abort();
        }
Пример #5
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, 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();

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

                if (EndPoint.Attributes == 1)
                {
                    CyIsocEndPoint isoc = EndPoint as CyIsocEndPoint;
                    // FinishDataXfer
                    if (isoc.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k], ref pktsInfo[k]))
                    {
                        //XferBytes += len;
                        //Successes++;

                        ISO_PKT_INFO[] pkts = pktsInfo[k];

                        for (int j = 0; j < PPX; j++)
                        {
                            if (pkts[j].Status == 0)
                            {
                                XferBytes += pkts[j].Length;

                                Successes++;
                            }
                            else
                            {
                                Failures++;
                            }

                            pkts[j].Length = 0;
                        }
                    }
                    else
                    {
                        Failures++;
                    }
                }
                else
                {
                    // FinishDataXfer
                    if (EndPoint.FinishDataXfer(ref cBufs[k], ref xBufs[k], ref len, ref oLaps[k]))
                    {
                        XferBytes += len;
                        Successes++;
                    }
                    else
                    {
                        Failures++;
                    }
                }

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

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

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

                    xferRate = (long)(XferBytes / elapsed.TotalMilliseconds);
                    xferRate = xferRate / (int)100 * (int)100;

                    // 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.
            EndPoint.Abort();
        }