public void Reset() { MyControlPoint.Direction = CyConst.DIR_TO_DEVICE; MyControlPoint.ReqType = CyConst.REQ_VENDOR; MyControlPoint.ReqCode = 0xFF; MyControlPoint.Target = CyConst.TGT_DEVICE; MyControlPoint.Index = 0x00; MyControlPoint.Value = 0x00; int i = 0; byte[] Rst = new byte[i]; while (true) { if (MyControlPoint.XferData(ref Rst, ref i)) { break; } } MyInPoint.Abort(); MyInPoint.Reset(); MyInPoint.Abort(); MyOutPoint.Reset(); }
private static bool WaitForIO(System.IntPtr ovlapEvent, ref CyUSBEndPoint endpoint) { switch (PInvoke.WaitForSingleObject(ovlapEvent, endpoint.TimeOut)) { case 0: return(true); case 258: endpoint.Abort(); PInvoke.WaitForSingleObject(ovlapEvent, uint.MaxValue); break; } return(false); }
/*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(); }
/*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(); }
/*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(); }