public void Run(System.IO.Stream output, int count) { miBytesReceived = 0; BytesReceived = new byte[TEST_SIZE]; BytesToSend = new byte[TEST_SIZE]; Random rnd = new Random(); rnd.NextBytes(BytesToSend); byte[] _bTemp = new byte[64]; StreamWriter sw = new StreamWriter(output); sw.WriteLine("--- Test_BigReadWrite ---"); sw.Flush(); UsbDevice testDevice = PicTestDevice.TestDevice; if (testDevice != null) { Debug.Assert(testDevice.Open(), "Failed opening device."); int ret = 0; PicTestDevice.OpenAndConfigure(sw); byte bTestType = 0; Debug.Assert(PicTestDevice.GetTestType(ref bTestType)); UsbEndpointReader reader = testDevice.OpenBulkEndpointReader(ReadEndpoints.Ep01); UsbEndpointWriter writer = testDevice.OpenBulkEndpointWriter(WriteEndpoints.Ep01); if (bTestType != 3) { Debug.Assert(PicTestDevice.SetTestType(3, ref bTestType)); while (ret >= 0) { ret = reader.Read(_bTemp, 1000); if (ret == 1 && _bTemp[0] == 0x80) { break; } } } reader.DataReceived += new EventHandler <DataReceivedArgs>(reader_DataReceived); for (int iLoop = 0; iLoop < count; iLoop++) { miBytesReceived = 0; reader.DataReceivedEnabled = true; System.Windows.Forms.Application.DoEvents(); Debug.Assert(writer.Write(BytesToSend, Timeout.Infinite) == TEST_SIZE); while (ReceiveCount < TEST_SIZE) { System.Windows.Forms.Application.DoEvents(); Thread.Sleep(1000); } reader.DataReceivedEnabled = false; System.Windows.Forms.Application.DoEvents(); sw.WriteLine("SUCCESS:" + TEST_SIZE); sw.Flush(); } reader.DataReceived -= reader_DataReceived; reader.Dispose(); writer.Dispose(); PicTestDevice.CloseAndDeConfigure(sw); } }
public void Run(Stream output) { byte[] _bTemp = new byte[64]; StreamWriter sw = new StreamWriter(output); sw.WriteLine("--- Test_cancel_io ---"); UsbDevice testDevice = PicTestDevice.TestDevice; if (testDevice != null) { Debug.Assert(testDevice.Open(), "Failed opening device."); int ret; ret = testDevice.SetConfiguration(1); Debug.Assert(ret == 0); sw.WriteLine("SetConfiguration(1):" + ret); ret = testDevice.ClaimInterface(0); Debug.Assert(ret == 0); sw.WriteLine("ClaimInterface(0):" + ret); byte bTestType = 0; Debug.Assert(PicTestDevice.GetTestType(ref bTestType)); UsbEndpointReader reader = testDevice.OpenBulkEndpointReader(ReadEndpoints.Ep01); if (bTestType != 3) { Debug.Assert(PicTestDevice.SetTestType(3, ref bTestType)); while (ret >= 0) { ret = reader.Read(_bTemp, 1000); if (ret == 1 && _bTemp[0] == 0x80) { break; } } } reader.DataReceivedEnabled = true; Application.DoEvents(); Thread.Sleep(1000); Thread.Sleep(1000); reader.CancelIO(); Application.DoEvents(); reader.Dispose(); ret = testDevice.ReleaseInterface(0); Debug.Assert(ret == 0); sw.WriteLine("ReleaseInterface(0):" + ret); ret = testDevice.SetConfiguration(0); Debug.Assert(ret == 0); sw.WriteLine("SetConfiguration(0):" + ret); testDevice.Close(); sw.WriteLine("SUCCESS!"); } else { sw.WriteLine("Failed opening device."); } sw.WriteLine("------------------------------"); sw.Flush(); }