if (inEndpoint != null && outEndpoint != null)
{
- if (!testUsbDevice.IsOpened) testUsbDevice.Open();
- Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state");
-
- testInterfaces.Value.Release();
- testConfig.Value.SetAsActive();
- testInterfaces.Value.Claim(true);
-
- // TEST CODE
- byte[] outBytes = Encoding.ASCII.GetBytes("HELLO");
- Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}");
- int sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 0);
- Helper.Log($"Check");
- Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}");
- Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}");
-
- byte[] inBytes = new byte[10];
- int receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 0);
- Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}");
-
- Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes");
- for (int i = 0; i < receivedBytes; ++i)
- Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}");
-
- Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}");
+ bool timed_out;
+ int retry = 5;
+
+ do
+ {
+ try {
+ if (!testUsbDevice.IsOpened) testUsbDevice.Open();
+ Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state");
+
+ testInterfaces.Value.Release();
+ testConfig.Value.SetAsActive();
+ testInterfaces.Value.Claim(true);
+
+ // TEST CODE
+ byte[] outBytes = Encoding.ASCII.GetBytes("HELLO");
+ Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}");
+ int sentBytes = 0;
+ int receivedBytes = 0;
+ byte[] inBytes = new byte[10];
+
+ timed_out = false;
+ sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 2000);
+ Helper.Log($"Check");
+ Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}");
+ Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}");
+ receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 2000);
+
+ Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}");
+ Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes");
+ for (int i = 0; i < receivedBytes; ++i)
+ Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}");
+
+ Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}");
+ }
+ catch (TimeoutException) {
+ Helper.Log("Transfer timed out");
+ timed_out = true;
+ Assert.IsTrue(retry-- > 0, "Transfer timed out too many times");
+ }
+ } while (timed_out);
}
testInterfaces.Value.Release();
if (inEndpoint != null && outEndpoint != null)
{
- if (!testUsbDevice.IsOpened) testUsbDevice.Open();
- Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state");
-
- testInterfaces.Value.Release();
- testConfig.Value.SetAsActive();
- testInterfaces.Value.Claim(true);
-
- // TEST CODE
- byte[] outBytes = Encoding.ASCII.GetBytes("HELLO");
- Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}");
- int sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 0);
- Helper.Log($"Check");
- Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}");
- Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}");
-
- byte[] inBytes = new byte[10];
- int receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 0);
- Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}");
-
- Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes");
- for (int i = 0; i < receivedBytes; ++i)
- Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}");
-
- Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}");
+ bool timed_out;
+ int retry = 5;
+
+ do
+ {
+ try {
+ if (!testUsbDevice.IsOpened) testUsbDevice.Open();
+ Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state");
+
+
+ testInterfaces.Value.Release();
+ testConfig.Value.SetAsActive();
+ testInterfaces.Value.Claim(true);
+
+ // TEST CODE
+ byte[] outBytes = Encoding.ASCII.GetBytes("HELLO");
+ Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}");
+ int sentBytes = 0;
+ int receivedBytes = 0;
+ byte[] inBytes = new byte[10];
+
+ timed_out = false;
+ sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 2000);
+ Helper.Log($"Check");
+ Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}");
+ Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}");
+ receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 2000);
+
+ Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}");
+ Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes");
+ for (int i = 0; i < receivedBytes; ++i)
+ Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}");
+
+ Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}");
+ }
+ catch (TimeoutException) {
+ Helper.Log("Transfer timed out");
+ timed_out = true;
+ Assert.IsTrue(retry-- > 0, "Transfer timed out too many times");
+ }
+ } while (timed_out);
}
testInterfaces.Value.Release();