public T Find <T>(string name) where T : class { var typeName = typeof(T).Name; switch (typeName) { case nameof(MotionCardWrapper): return(MotionExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(IDiEx): return(DiExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(IDoEx): return(DoExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(IVioEx): return(VioExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(ICylinderEx): return(CylinderExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(IAxisEx): return(AxisExs.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(PlatformEx): return(Platforms.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(Station): return(Stations.FirstOrDefault(ex => ex.Value.Name == name).Value as T); case nameof(StationTask): return(Tasks.FirstOrDefault(ex => ex.Value.Name == name).Value as T); default: return(null); } }
public override void Load() { if (!Directory.Exists(@".\Config")) { Directory.CreateDirectory(@".\Config"); } //load all settings!!! try { Settings = DemoMachineSettings.Load(@".\Config\Settings.cfg"); } catch (Exception ex) { MessageBox.Show($"加载配置文件失败:{ex.Message}"); } if (Settings == null) { Settings = new DemoMachineSettings(); Settings.Save(@".\Config\Settings.cfg"); } //try //{ // Import(); //} //catch (Exception ex) //{ // MessageBox.Show($"导入设备参数失败:{ex.Message}"); //} //load drivers Motion1 = new MotionCardWrapper(new VirtualCard()); VIO = new MotionCardWrapper(new VirtualCard()); MotionExs.Add(1, Motion1); MotionExs.Add(2, VIO); //load di do axis DiExs.Add(1, new DiEx() { Driver = Motion1 }); DoExs.Add(1, new DoEx() { Driver = Motion1 }); CylinderExs.Add(1, new CylinderEx() { Driver1 = Motion1, Driver2 = Motion1 }); AxisExs.Add(1, new AxisEx() { Driver = Motion1 }); //load station task var station1 = new Station(1, "Station1", this); var testTask1 = new TestTask1(1, "Test1", station1); //bind signals if (!FrameworkManager.IsSimulate) { // todo : to add signal configs //estop DiEstop.Add(2, new DiEx() { Driver = Motion1 }); //start/stop/reset button DiStart.Add(1, new DiEx() { Driver = Motion1 }); DiStop.Add(1, new DiEx() { Driver = Motion1 }); DiReset.Add(1, new DiEx() { Driver = Motion1 }); //start/stop/reset button lamp DoLightGreen.Add(1, new DoEx() { Driver = Motion1 }); DoLightRed.Add(1, new DoEx() { Driver = Motion1 }); DoLightYellow.Add(1, new DoEx() { Driver = Motion1 }); //lamp DoLightGreen.Add(2, new DoEx() { Driver = Motion1 }); DoLightRed.Add(2, new DoEx() { Driver = Motion1 }); DoLightYellow.Add(2, new DoEx() { Driver = Motion1 }); DoBuzzer.Add(1, new DoEx() { Driver = Motion1 }); //station pause signals Stations[1].PauseSignals.Add(1, new DiEx() { Driver = Motion1 }); } }