Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            IMeasurementSetting    setting;
            ICommunicatorConfigure config;
            var data  = GetData();
            var itype = data["Instrument_Type"];
            var ctype = data["Instrument_Communicator_Type"];
            var cdata = data["Instrument_Communicator_Setting"];

            if (!InstrumentConfig.GetConfig(ctype, cdata, out config))
            {
                AppFramework.Context.ShowError($"连接类型错误");
                return;
            }

            if (_group == "PointOpticalSource" && itype == "GeneralRouterOpticalSource01")
            {
                var router = new Incht.MeasurementSystem.Instruments.Router.UC.FSW1U1x16SMFCPCRouter();
                router.Initialize(DefaultMeasurementSetting.Create(ctype, config));

                var wlSetting = new Dictionary <double, int[]>();

                setting = new GeneralRouterSetting()
                {
                    CustomMeasurementName = "点光源",
                    Router            = router,
                    WaveLengthSetting = wlSetting
                };
            }
            else if (_group == "PolarizationController" && itype == "PCU100") //PCU100
            {
                var deviceName = (this.Parent.Controls.Find("tbDeviceName", true).FirstOrDefault() as TextBox).Text;
                setting = PCU100Setting.Create("PCU100", deviceName, config);
            }
            else
            {
                setting = DefaultMeasurementSetting.Create(ctype, config);
            }

            var measurement = MeasurementManger.CreateMeasurementInstance(
                _system, _group, itype, setting);

            if (measurement == null)
            {
                panel4.BackColor = Color.Red;
                AppFramework.Context.ShowConfirm($"初始仪器失败");
                return;
            }

            if (!measurement.Connect())
            {
                panel4.BackColor = Color.Red;
                AppFramework.Context.ShowConfirm($"连接仪器失败:{measurement.ErrorString}");
                measurement = null;
                return;
            }
            measurement.Disconnect();
            measurement      = null;
            panel4.BackColor = Color.LimeGreen;
        }
        /// <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);
        }