示例#1
0
        public void TestPortSerialization()
        {
            var currentSettingsDir = ComponentSettings.GetSettingsDirectory("Bench");

            // Try to invoke the ComponentSettings serializer/deserializer for connections
            // Important thing is that a TestPort is still a TestPort after serialization.
            ComponentSettings.SetSettingsProfile("Bench", "test1");
            InstrumentSettings.Current.ToList();
            TestPortInstrument Instr = new TestPortInstrument();

            InstrumentSettings.Current.Add(Instr);
            RfConnection conn = new RfConnection()
            {
                Port1 = Instr.Port1, Port2 = Instr.Port2
            };

            ConnectionSettings.Current.Clear();
            ConnectionSettings.Current.Add(conn);
            ComponentSettings.SaveAllCurrentSettings();
            ComponentSettings.SetSettingsProfile("Bench", "test2");
            InstrumentSettings.Current.ToList(); // make componentsettings reload.
            ComponentSettings.SetSettingsProfile("Bench", "test1");

            var instr2 = InstrumentSettings.Current.OfType <TestPortInstrument>().First();

            Assert.IsFalse(object.ReferenceEquals(instr2, Instr));
            Instr = instr2;
            conn  = ConnectionSettings.Current.OfType <RfConnection>().First(con => (con.Port1 is TestPort));

            // Now try to serialize a test plan with a Port inside it.
            try
            {
                TestPlan plan = new TestPlan {
                };
                plan.ChildTestSteps.Add(new TestPortStep()
                {
                    SelectedPort = Instr.Port1
                });
                TestPlan newplan;

                using (var str = new MemoryStream(1000))
                {
                    plan.Save(str);
                    str.Position = 0;
                    newplan      = TestPlan.Load(str, plan.Path);
                }
                TestPortStep step = (TestPortStep)newplan.ChildTestSteps.First();
                Assert.IsTrue(step.SelectedPort is TestPort);
            }
            finally
            {
                // Cleanup
                ConnectionSettings.Current.Remove(conn);
                InstrumentSettings.Current.Remove(Instr);
                ComponentSettings.SaveAllCurrentSettings();

                ComponentSettings.SetSettingsProfile("Bench", currentSettingsDir);
            }
        }
示例#2
0
        public void CableLossInterpolationTest()
        {
            // check linear (first order) interpolation:
            RfConnection con = new RfConnection();

            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 100, Loss = 2
            });
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 200, Loss = 4
            });
            double loss = con.GetInterpolatedCableLoss(150);

            Assert.AreEqual(3, loss);

            con = new RfConnection();
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 100, Loss = 0
            });
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 200, Loss = 4
            });
            loss = con.GetInterpolatedCableLoss(175);
            Assert.AreEqual(3, loss);

            // check extrapolation (zero order):
            con = new RfConnection();
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 100, Loss = 2
            });
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 200, Loss = 4
            });
            loss = con.GetInterpolatedCableLoss(300);
            Assert.AreEqual(4, loss);
            loss = con.GetInterpolatedCableLoss(50);
            Assert.AreEqual(2, loss);

            // check exact match
            con = new RfConnection();
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 100, Loss = 2
            });
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 200, Loss = 4
            });
            con.CableLoss.Add(new RfConnection.CableLossPoint {
                Frequency = 300, Loss = 5
            });
            loss = con.GetInterpolatedCableLoss(100);
            Assert.AreEqual(2, loss);
            loss = con.GetInterpolatedCableLoss(200);
            Assert.AreEqual(4, loss);
            loss = con.GetInterpolatedCableLoss(300);
            Assert.AreEqual(5, loss);
        }