public static bool GetConfig(string type, string setting, out ICommunicatorConfigure config) { config = default(ICommunicatorConfigure); if (type == "NI4882Communicatior" || type == "NIVisaCommunicatior") { var c = setting.FromJsonString <UserControlGPIBSetting.GPIBSetting>().ToConfigure(); if (type == "NI4882Communicatior") { ((GPIBConfigure)c).GPIBType = GPIBType.NI4882; } else { ((GPIBConfigure)c).GPIBType = GPIBType.NIVisa; } config = c; } else if (type == "SerialPortCommunicatior") { config = setting.FromJsonString <UserControlSerialPortSetting.SerialPortSetting>().ToConfigure(); } else if (type == "LANCommunicatior") { config = setting.FromJsonString <UserControlLANSetting.LANSetting>().ToConfigure(); } else { return(false); } return(true); }
/// <summary> /// 初始仪器 /// </summary> /// <returns></returns> public bool Initialize() { if (instrumentGroup.Count < 1 || instrumentGroup.Count != Configs.Count) { ErrorString = "系统未注册仪器"; return(false); } foreach (var item in Configs) { var type = item.Key; var data = item.Value; if (data.Instrument_Type == "None") { instrument[type] = null; continue; } var groupName = instrumentGroup[type]; ICommunicatorConfigure config = data.Instrument_Communicator_Config; IMeasurementSetting setting; if (item.Key == InstrumentType.PointOpticalSource && item.Value.Instrument_Type == "GeneralRouterOpticalSource01") { var router = new Incht.MeasurementSystem.Instruments.Router.UC.FSW1U1x16SMFCPCRouter(); router.Initialize(DefaultMeasurementSetting.Create(groupName, config)); //1525nm,1270nm,1550nm var wlSetting = new Dictionary <double, int[]>() { { 1525D, new int[] { 1, 1 } }, { 1270D, new int[] { 1, 2 } }, { 1550D, new int[] { 1, 3 } }, }; if (!string.IsNullOrEmpty(item.Value["Instrument_WaveLengthSetting"])) { wlSetting = item.Value["Instrument_WaveLengthSetting"].FromJsonString <Dictionary <double, int[]> >(); } setting = new GeneralRouterSetting() { CustomMeasurementName = "点光源", Router = router, WaveLengthSetting = wlSetting }; } else { setting = DefaultMeasurementSetting.Create(groupName, config); } instrument[type] = MeasurementManger.CreateMeasurementInstance(data.SystemID, data.GroupID, data.Instrument_Type, setting); if (instrument[type] == null) { ErrorString = $"初始仪器{groupName}失败"; return(false); } if (item.Key == InstrumentType.PointOpticalSource) { if (!string.IsNullOrEmpty(item.Value["Instrument_WaitTime"])) { waitTime = item.Value["Instrument_WaitTime"].CastTo(1000); } } else if (item.Key == InstrumentType.PolarizationController) { if (!string.IsNullOrEmpty(item.Value["Instrument_Rate"])) { pdlRate = item.Value["Instrument_Rate"].CastTo(1); } if (!string.IsNullOrEmpty(item.Value["Instrument_TestTime"])) { PDLTestTime = item.Value["Instrument_TestTime"].CastTo(3D); } } } return(true); }