public void I2CStreamCancelTest() { Console.WriteLine("Starting I2C stream cancel test..."); long firstCount; I2CPreamble pre = new I2CPreamble(); pre.DeviceAddress = 0xA0; pre.PreambleData.Add(0); pre.PreambleData.Add(0); pre.StartMask = 4; for (int trial = 0; trial < 5; trial++) { Console.WriteLine("Starting trial " + trial.ToString()); /* Start stream */ FX3.StartI2CStream(pre, 64, 1000000); firstCount = FX3.GetNumBuffersRead; System.Threading.Thread.Sleep(100); Assert.Greater(FX3.GetNumBuffersRead, firstCount, "ERROR: Expected to have read buffers"); /* Cancel stream (stop stream) */ FX3.StopStream(); System.Threading.Thread.Sleep(20); /* Test read functionality */ TestI2CFunctionality(); /* Start stream */ FX3.StartI2CStream(pre, 64, 1000000); firstCount = FX3.GetNumBuffersRead; System.Threading.Thread.Sleep(100); Assert.Greater(FX3.GetNumBuffersRead, firstCount, "ERROR: Expected to have read buffers"); /* Cancel stream (cancel stream) */ FX3.CancelStreamAsync(); System.Threading.Thread.Sleep(20); /* Test read functionality */ TestI2CFunctionality(); } }
public void ErrorLogRobustnessTest() { Console.WriteLine("Starting error log robustness test..."); List <FX3ErrorLog> initialLog, log; I2CPreamble preRead = new I2CPreamble(); preRead.DeviceAddress = 0xA0; preRead.PreambleData.Add(0); preRead.PreambleData.Add(0); preRead.PreambleData.Add(0xA1); preRead.StartMask = 4; I2CPreamble preWrite = new I2CPreamble(); preWrite.DeviceAddress = 0; preWrite.PreambleData.Add(0); preWrite.StartMask = 0; Console.WriteLine("Rebooting FX3..."); FX3.Disconnect(); System.Threading.Thread.Sleep(500); Connect(); Console.WriteLine("Getting initial error log..."); initialLog = FX3.GetErrorLog(); foreach (FX3ErrorLog entry in initialLog) { Console.WriteLine(entry.ToString()); } Console.WriteLine("Starting I2C Read..."); try { FX3.I2CReadBytes(preRead, 32, 1000); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Getting error log..."); log = FX3.GetErrorLog(); CheckLogEquality(initialLog, log, false); Console.WriteLine("Starting invalid I2C write..."); try { FX3.I2CWriteBytes(preWrite, new byte[] { 1, 2, 3, 4 }, 1000); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Getting error log..."); log = FX3.GetErrorLog(); CheckLogEquality(initialLog, log, true); initialLog.Clear(); foreach (FX3ErrorLog entry in log) { initialLog.Add(entry); } Console.WriteLine("Starting I2C stream..."); FX3.StartI2CStream(preRead, 64, 10); System.Threading.Thread.Sleep(2000); Console.WriteLine("Getting error log..."); log = FX3.GetErrorLog(); CheckLogEquality(initialLog, log, false); Console.WriteLine("Rebooting FX3..."); FX3.Disconnect(); System.Threading.Thread.Sleep(500); Connect(); Console.WriteLine("Getting error log..."); log = FX3.GetErrorLog(); CheckLogEquality(initialLog, log, false); Console.WriteLine("Starting I2C Read..."); try { FX3.I2CReadBytes(preRead, 32, 1000); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Generating new error log..."); GenerateErrorLog(); Console.WriteLine("Getting error log..."); log = FX3.GetErrorLog(); Assert.AreEqual(initialLog.Count + 1, log.Count, "ERROR: Invalid log count"); CheckLogEquality(initialLog, log, true); }