示例#1
0
        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);
        }