Esempio n. 1
0
        public void SetupLuiConfig()
        {
            Config = new LuiConfig
            {
                ConfigFile = ConfigFile,
                LogFile    = "./log.txt",
                LogLevel   = "DEBUG"
            };

            gpibParameters1 = new GpibProviderParameters
            {
                TypeName    = "LuiHardware.gpib.NIGpibProvider",
                Name        = "NI PCI Card",
                BoardNumber = 0
            };

            gpibParameters2 = new GpibProviderParameters
            {
                TypeName = "LuiHardware.gpib.PrologixGpibProvider",
                Name     = "USB GPIB Controller",
                PortName = "COM1",
                Timeout  = 300
            };

            cameraParameters = new CameraParameters
            {
                TypeName    = "LuiHardware.camera.CameraTempControlled",
                Name        = "Andor USB CCD",
                Dir         = "./",
                Temperature = 20
            };

            ddgParameters = new DelayGeneratorParameters
            {
                TypeName     = "LuiHardware.ddg.DDG535",
                Name         = "Primary DDG",
                GpibAddress  = 15,
                GpibProvider = gpibParameters1
            };

            Config.AddParameters(gpibParameters1);
            Config.AddParameters(gpibParameters2);
            Config.AddParameters(cameraParameters);
            Config.AddParameters(ddgParameters);
        }
Esempio n. 2
0
        public void TestXmlSerialization()
        {
            //var serializer = new XmlSerializer(Config.GetType());
            //using (var writer = new StreamWriter(Config.ConfigFile))
            //{
            //    serializer.Serialize(writer, Config);
            //}
            Config.Save();

            //LuiConfig testConfig = null;
            //using (var reader = new StreamReader(ConfigFile))
            //{
            //    testConfig = (LuiConfig)serializer.Deserialize(reader);
            //}
            LuiConfig testConfig = LuiConfig.FromFile(ConfigFile);

            Assert.AreEqual(testConfig.ConfigFile, Config.ConfigFile);
            Assert.AreEqual(testConfig.LogFile, Config.LogFile);
            Assert.AreEqual(testConfig.LogLevel, Config.LogLevel);
            foreach (KeyValuePair <Type, Dictionary <LuiObjectParameters, ILuiObject> > kvp in Config.LuiObjectTableIndex)
            {
                IList <LuiObjectParameters> list = (IList <LuiObjectParameters>)kvp.Value.Keys.ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    Assert.AreEqual(list[i], ((IList <LuiObjectParameters>)testConfig.LuiObjectTableIndex[kvp.Key].Keys.ToList())[i]);
                }
            }

            GpibProviderParameters dependency     = null;
            GpibProviderParameters testParameters = null;

            foreach (var kvp in testConfig.LuiObjectTableIndex[ddgParameters.GetType()])
            {
                if (kvp.Key.Name == ddgParameters.Name)
                {
                    dependency = ((DelayGeneratorParameters)kvp.Key).GpibProvider;
                }
            }

            foreach (var kvp in testConfig.LuiObjectTableIndex[gpibParameters1.GetType()])
            {
                if (kvp.Key.Name == gpibParameters1.Name)
                {
                    testParameters = (GpibProviderParameters)kvp.Key;
                }
            }

            Assert.AreEqual(dependency, testParameters);
            Assert.IsTrue(
                testConfig.LuiObjectTableIndex[dependency.GetType()][dependency] ==
                testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters]
                );
            Assert.IsTrue(Object.ReferenceEquals(
                              testConfig.LuiObjectTableIndex[dependency.GetType()][dependency],
                              testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters]
                              ));

            var dummy = new DummyGpibProvider();

            testConfig.LuiObjectTableIndex[dependency.GetType()][dependency] = dummy;

            Assert.IsTrue(Object.ReferenceEquals(testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters], dummy));
        }