Esempio n. 1
0
        private static double TestPointUniformity(ReferenceData referenceData, TestDataCollection testDataCollection, string testType, string temp, int port, string pSetting)
        {
            var pointTestData = testDataCollection.GetTestData(testType, "Point", "PointPDL");

            if (pointTestData == null)
            {
                throw new MeasuringException("没有计算Uniformity所需测试数据");
            }

            var wl = pSetting.CastTo(double.MaxValue);

            if (wl == double.MinValue)
            {
                throw new MeasuringException("波长设置错误");
            }

            var testData = pointTestData.GetTestData();

            if (!testData.ContainsKey(temp))
            {
                throw new MeasuringException("没有计算Uniformity所需测试数据");
            }
            var data = testData[temp];

            var setting = TestPortSetting.Get(port);
            var powers  = new List <double>();

            foreach (var item in data)
            {
                var ch = item.Key;
                if (ch < 1 || !item.Value.ContainsKey(wl))
                {
                    continue;
                }

                var chSetting = TestPortSetting.Get(ch);
                if (chSetting.DataID != setting.DataID)
                {
                    continue;
                }

                var testItem = item.Value[wl];
                if (testItem.IL == double.MinValue)
                {
                    continue;
                }

                powers.Add(testItem.IL);
            }

            var value = powers.Count < 1 ?
                        double.MinValue :
                        Math.Round(powers.Max() - powers.Min(), 3);

            return(value);
        }
Esempio n. 2
0
 public static bool GetPowerMeterModuleAndChannel(int port, out int module, out int channel)
 {
     if (port > 99)
     {
         var setting = TestPortSetting.Get(port);
         port = setting.ChannelID;
     }
     module = Math.DivRem(port, 10, out channel);
     return(true);
 }
Esempio n. 3
0
        public static string GetPortName(int port)
        {
            var setting = TestPortSetting.Get(port);

            if (setting.ChannelID == 0)
            {
                return("N/A");
            }

            var name = $"通道{setting.ChannelID}";

            return(name);
        }
Esempio n. 4
0
        /// <summary>
        /// 读取功率计功率
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public double GetMeterPower(int channel)
        {
            var power   = double.MinValue;
            var setting = TestPortSetting.Get(channel);
            var pm      = GetPowerMeter(setting.DeviceID);

            if (pm == null)
            {
                ErrorString = "功率计不存在或者未连接";
                return(power);
            }
            if (!CheckMeasurementConnect(pm))
            {
                return(power);
            }

            if (!ChangeRouter(setting.SwitchID))
            {
                return(power);
            }

            var mod = 0;
            var ch  = 0;

            GetPowerMeterModuleAndChannel(setting.ChannelID, out mod, out ch);
            var tryCount = 0;

            while (tryCount < 10) //10次读取
            {
                lock (locker)
                {
                    if (pm.GetPower(mod, ch, out power))
                    {
                        ErrorString = $"{pm.CustomMeasurementName}读取功率成功";
                    }
                    else
                    {
                        ErrorString = pm.ErrorString;
                    }
                }

                if (power != double.MinValue)
                {
                    break;
                }
                System.Threading.Thread.Sleep(50);
                tryCount++;
            }
            return(power);
        }
Esempio n. 5
0
        private List <double> GetMeterPowers(int channel, double time)
        {
            var powers = new List <double>();

            var setting = TestPortSetting.Get(channel);
            var pm      = MeasurementController.GetMeterIsMaxMin(setting.DeviceID);

            if (pm != null)
            {
                System.Threading.Thread.Sleep(10);
                TryAction(() => {
                    return(pm.SetPowerMaxMin(0, setting.ChannelID, 1));
                }, 10);
                var sw = System.Diagnostics.Stopwatch.StartNew();
                while (!IsStop)
                {
                    if (sw.ElapsedMilliseconds > time * 1000D)
                    {
                        sw.Stop();
                        break;
                    }
                    System.Threading.Thread.Sleep(10);
                }

                TryAction(() => {
                    return(pm.SetPowerMaxMin(0, setting.ChannelID, 0));
                }, 10);

                var pw = double.MinValue;
                TryAction(() => {
                    return(pm.GetMaxPower(0, setting.ChannelID, out pw) && pw != double.MinValue);
                }, 10);

                if (pw == 0D)
                {
                    return(new List <double>());
                }

                if (pw != double.MinValue)
                {
                    powers.Add(pw);
                }

                TryAction(() => {
                    return(pm.GetMinPower(0, setting.ChannelID, out pw) && pw != double.MinValue);
                }, 10);

                if (pw != double.MinValue)
                {
                    powers.Add(pw);
                }
            }
            else
            {
                var sw = System.Diagnostics.Stopwatch.StartNew();
                while (!IsStop)
                {
                    var power = MeasurementController.GetMeterPower(channel);
                    if (power == double.MinValue)
                    {
                        continue;
                    }

                    powers.Add(power);
                    if (sw.ElapsedMilliseconds > time * 1000D)
                    {
                        sw.Stop();
                        break;
                    }
                }
            }


            return(powers);
        }
        public void AddTestInfoRow(WorkInfoSpecItem specItem)
        {
            var row = testItem.NewRow();

            row["TestItemID"]   = specItem.SpecItemID;
            row["TestItemName"] = specItem.ItemName;

            foreach (var resultItem in BaseSettingsManager.Get <ResultSettings>().NeedSettingResult)
            {
                if (!specItem.ComputeSetting.ContainsKey(resultItem.ResultID))
                {
                    row[string.Format("TestItemCompute{0}", resultItem.ResultID)] = "N/A";
                }
                else
                {
                    var computeItem = specItem.ComputeSetting[resultItem.ResultID];
                    row[string.Format("TestItemCompute{0}", resultItem.ResultID)] = string.IsNullOrEmpty(computeItem.ComputeValue) ? "未设置" : OperatorManager.GetOperator(computeItem.ComputeSign).GetDisplayString(computeItem.ComputeValue);
                }
            }
            row["TestItemPortSetting"] = MeasurementController.GetPortName(specItem.PortSetting);
            if (string.IsNullOrEmpty("specItem.TestTemp") || !specItem.TestTemp.IsNumeric())
            {
                row["TestItemTemp"] = "";
            }
            else
            {
                row["TestItemTemp"] = $"{specItem.TestTemp}℃";
            }
            row["TestItemValue"]     = "";
            row["TestItemMaxValue"]  = "";
            row["TestItemMinValue"]  = "";
            row["TestItemLastValue"] = "-999";
            row["TestItemStatus"]    = -10;
            testItem.Rows.Add(row);

            var resultInfo = new ResultInfo()
            {
                TestInfoDataRow = row
            };

            testReslut[specItem.SpecItemID] = resultInfo;

            var dgvResult = default(DataGridView);

            if (!dgvResults.TryGetValue(specItem.TestTemp, out dgvResult))
            {
                return;
            }
            if (!specItem.TestSetting.IsDouble())
            {
                return;
            }

            var wl    = specItem.TestSetting.CastTo(1550D);
            var names = specItem.ItemName.Split(":");
            var name  = names.Length > 1 ? names[1] : names[0];

            names = name.Split("@");
            name  = names[0];

            var setting = TestPortSetting.Get(specItem.PortSetting);

            if (setting.ChannelID < 1 && name == "UL")
            {
                name = "IL";
            }

            if (!dgvResult.Columns.Contains(name))
            {
                dgvResult.Columns.Add(name, name);
                dgvResult.Columns[name].SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            foreach (DataGridViewRow dataRow in dgvResult.Rows)
            {
                if (dataRow.Cells["Wavelength"].Value.ToString() == wl.ToString("F3") &&
                    dataRow.Cells["Port"].Value.ToString() == specItem.PortSetting.ToString())
                {
                    resultInfo.ResultViewCell = dataRow.Cells[name];
                }
            }
        }
        public void SetSetting(string[] temps, List <double> wls, List <int> chs)
        {
            for (int i = 0; i < temps.Length; i++)
            {
                var temp = temps[i];

                if (string.IsNullOrEmpty(temp))
                {
                    continue;
                }

                var text    = $"{temp}℃";
                var tagPage = new TabPage()
                {
                    Name = Guid.NewGuid().ToString(),
                    Text = text
                };

                var dgvResult = new DataGridViewEx();
                dgvResults[temp]                      = dgvResult;
                dgvResult.AllowUserToAddRows          = false;
                dgvResult.AllowUserToDeleteRows       = false;
                dgvResult.AutoSizeColumnsMode         = DataGridViewAutoSizeColumnsMode.Fill;
                dgvResult.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                var dataGridViewCellStyle = new DataGridViewCellStyle();
                dataGridViewCellStyle.Alignment          = DataGridViewContentAlignment.MiddleLeft;
                dataGridViewCellStyle.BackColor          = SystemColors.Window;
                dataGridViewCellStyle.Font               = new Font("微软雅黑", 10.5F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134)));
                dataGridViewCellStyle.ForeColor          = SystemColors.ControlText;
                dataGridViewCellStyle.SelectionBackColor = SystemColors.Highlight;
                dataGridViewCellStyle.SelectionForeColor = SystemColors.HighlightText;
                dataGridViewCellStyle.WrapMode           = DataGridViewTriState.False;
                dgvResult.DefaultCellStyle               = dataGridViewCellStyle;
                dgvResult.Location           = new Point(322, 14);
                dgvResult.Name               = Guid.NewGuid().ToString();
                dgvResult.ReadOnly           = true;
                dgvResult.RowHeadersWidth    = 21;
                dgvResult.RowTemplate.Height = 27;
                dgvResult.SelectionMode      = DataGridViewSelectionMode.CellSelect;
                dgvResult.Size               = new Size(586, 161);
                dgvResult.Dock               = DockStyle.Fill;
                tagPage.Controls.Add(dgvResult);

                dgvResult.Columns.Add("Wavelength", "波长");
                dgvResult.Columns.Add("Port", "Port");
                dgvResult.Columns.Add("PortName", "端口");
                dgvResult.Columns[1].Visible  = false;
                dgvResult.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
                dgvResult.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
                dgvResult.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;

                var multPort = chs.Any(q => TestPortSetting.Get(q).DataID > 0);
                foreach (var wl in wls)
                {
                    foreach (var ch in chs)
                    {
                        var setting = TestPortSetting.Get(ch);
                        var port    = setting.ChannelID;
                        if (port < 1)
                        {
                            continue;
                        }

                        var name = $"Ch{port}";
                        if (multPort)
                        {
                            name = $"{setting.DataID + 1}-{setting.ChannelID}";
                        }

                        dgvResult.Rows.Add(wl.ToString("F3"), ch, name);
                    }
                    if (multPort)
                    {
                        dgvResult.Rows.Add(wl.ToString("F3"), 0, "1均一性");
                        dgvResult.Rows.Add(wl.ToString("F3"), 1000000, "2均一性");
                    }
                    else
                    {
                        dgvResult.Rows.Add(wl.ToString("F3"), 0, "均一性");
                    }
                }
                dgvResult.MergeColumnNames.Add("Wavelength");
                tabControl3.TabPages.Add(tagPage);
            }

            cbWavelength.Items.AddRange(wls.Select(q => q.ToString("F3")).ToArray());
            var source = new List <KeyValuePair <int, string> >();

            foreach (var channel in chs)
            {
                source.Add(new KeyValuePair <int, string>(channel, MeasurementController.GetPortName(channel)));
            }

            cbChannel.BindingDataSource(source);

            if (cbWavelength.Items.Count > 0)
            {
                cbWavelength.SelectedIndex = 0;
            }
            if (cbChannel.Items.Count > 0)
            {
                cbChannel.SelectedIndex = 0;
            }

            cbUnit.Text = "dBm";
        }
Esempio n. 8
0
        private static double TestPointCR(ReferenceData referenceData, TestDataCollection testDataCollection, string testType, string temp, int port, string pSetting)
        {
            var pointTestData = testDataCollection.GetTestData(testType, "Point", "PointPDL");

            if (pointTestData == null)
            {
                throw new MeasuringException("没有计算CR所需测试数据");
            }

            /*
             * var wl = pSetting.CastTo(double.MinValue);
             * if (wl == double.MinValue)
             *  throw new MeasuringException("波长设置错误");
             *
             * var item = pointTestData.GetDataItem(temp, port, wl);
             * if (item == null)
             * {
             *  throw new MeasuringException("没有计算CR所需测试数据");
             * }
             * var refpower = referenceData.GetReference(1, port, wl);
             * var power = item.Power + Windows.IniProfile<BusinessLogic.Setting.SystemSetting>.Instance.Profile.ExtraLosssCompensation;
             * var cr = MeasuringManager.Convert_dBm2mW(power - refpower.Power);
             * cr = Math.Round(cr * 100D, 2);
             */

            var wl = pSetting.CastTo(double.MaxValue);

            if (wl == double.MinValue)
            {
                throw new MeasuringException("波长设置错误");
            }

            var testData = pointTestData.GetTestData();

            if (!testData.ContainsKey(temp))
            {
                throw new MeasuringException("没有计算CL所需测试数据");
            }
            var data     = testData[temp];
            var inPower  = 0D;
            var allPower = 0D;

            var setting = TestPortSetting.Get(port);

            foreach (var item in data)
            {
                var ch = item.Key;
                if (ch < 1 || !item.Value.ContainsKey(wl))
                {
                    continue;
                }

                var chSetting = TestPortSetting.Get(ch);
                if (chSetting.DataID != setting.DataID)
                {
                    continue;
                }

                var testItem = item.Value[wl];
                if (testItem.Power == double.MinValue)
                {
                    continue;
                }

                var power = MeasuringManager.Convert_dBm2mW(testItem.IL);
                if (port == ch)
                {
                    inPower = power;
                }

                allPower += power;
            }
            var cr = allPower == 0D ? 0D : inPower / allPower;

            cr = Math.Round(cr * 100D, 2);
            return(cr);
        }
Esempio n. 9
0
        private static double TestPointEL(ReferenceData referenceData, TestDataCollection testDataCollection, string testType, string temp, int port, string pSetting)
        {
            var pointTestData = testDataCollection.GetTestData(testType, "Point", "PointPDL");

            if (pointTestData == null)
            {
                throw new MeasuringException("没有计算EL所需测试数据");
            }

            var wl = pSetting.CastTo(double.MaxValue);

            if (wl == double.MinValue)
            {
                throw new MeasuringException("波长设置错误");
            }

            var testData = pointTestData.GetTestData();

            if (!testData.ContainsKey(temp))
            {
                throw new MeasuringException("没有计算EL所需测试数据");
            }
            var data     = testData[temp];
            var allPower = 0D;
            var inPower  = 0D;
            var count    = 0;
            var setting  = TestPortSetting.Get(port);

            foreach (var item in data)
            {
                var ch = item.Key;
                if (ch < 1 || !item.Value.ContainsKey(wl))
                {
                    continue;
                }

                var chSetting = TestPortSetting.Get(ch);
                if (chSetting.DataID != setting.DataID)
                {
                    continue;
                }

                var testItem = item.Value[wl];
                if (testItem.Power == double.MinValue)
                {
                    continue;
                }

                var refpower = referenceData.GetReference(1, ch % TestPortSetting.DataDivide, wl);
                allPower += MeasuringManager.Convert_dBm2mW(testItem.Power);
                inPower  += refpower.Power;
                count++;
            }
            allPower = MeasuringManager.Convert_mW2dBm(allPower) + Windows.IniProfile <BusinessLogic.Setting.SystemSetting> .Instance.Profile.ExtraLosssCompensation;
            inPower  = inPower / count;

            var value = inPower == double.MinValue ?
                        double.MinValue :
                        Math.Abs(Math.Round(allPower - inPower, 3));

            return(value);
        }
Esempio n. 10
0
        private void GetPointTestData(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain)
        {
            if (!item.TestSetting.IsDouble())
            {
                return;
            }
            var wl = item.TestSetting.CastTo(1550D);

            if (item.PortSetting == 0)
            {
                return;
            }

            var type = "Point";

            if (!testAgain && testTask.ContainsTestData(type, temp, item.PortSetting, wl))
            {
                return;
            }

            currentChannel    = MeasurementController.GetSimultaneityPort(testTask.TestOrderID, item.PortSetting);
            currentWavelength = wl;
            testInfoCallback?.Invoke(currentWavelength, currentChannel, currentUnit);

            var pws = default(Dictionary <int, double>);

            if (!MeasurementController.RunPointTest(
                    false,
                    currentWavelength,
                    () =>
            {
                return(!IsStop);
            },
                    () =>
            {
                var setting = TestPortSetting.Get(currentChannel);
                pws = MeasurementController.GetMeterAllChannelPower(setting.DeviceID, setting.SwitchID);
            }))
            {
                throw new Exception(MeasurementController.ErrorString);
            }

            if (pws == null || pws.Count < 1)
            {
                throw new Exception($"读取功率失败,{MeasurementController.ErrorString}");
            }

            var items = MeasurementJob.SpecData.GetTestGroupWorkInfoSpecItems(systemGroup.TestGroupID);

            foreach (var testItem in items)
            {
                var pw = 0D;
                var c  = TestPortSetting.Get(testItem.PortSetting).ChannelID;
                if (!pws.TryGetValue(c, out pw))
                {
                    continue;
                }
                if (pw == double.MinValue)
                {
                    throw new Exception($"读取功率失败,{MeasurementController.ErrorString}");
                }
                AddPointTestData(testTask, type, temp, testItem.PortSetting, currentWavelength, pw);
            }
        }
Esempio n. 11
0
        private void GetManualPointPDLPointPDLTestData(IMeasurementTask testTask, string temp, TestSystemGroup systemGroup, WorkInfoSpecItem item, bool testAgain)
        {
            if (!item.TestSetting.IsDouble())
            {
                return;
            }
            var wl = item.TestSetting.CastTo(1550D);

            if (item.PortSetting == 0)
            {
                return;
            }

            var type = "PointPDL";

            if (!testAgain && testTask.ContainsTestData(type, temp, item.PortSetting, wl))
            {
                return;
            }

            currentChannel    = MeasurementController.GetSimultaneityPort(testTask.TestOrderID, item.PortSetting);
            currentWavelength = wl;
            testInfoCallback?.Invoke(currentWavelength, currentChannel, currentUnit);

            var pws = new Dictionary <int, List <double> >();

            if (!MeasurementController.ChangeWaveLength(currentWavelength))
            {
                throw new Exception($"切换波长失败,{MeasurementController.ErrorString}");
            }


            FormMessageBox.SetShow(null, "正在测试", "请摇动手摇偏振控制器,完成后点击[继续测试]进行测试", 0);

            var setting = TestPortSetting.Get(currentChannel);

            while (FormMessageBox.MessageBoxResult == 0)
            {
                if (IsStop)
                {
                    FormMessageBox.SetClose(2);
                    break;
                }
                var powers = MeasurementController.GetMeterAllChannelPower(setting.DeviceID, setting.SwitchID);
                if (powers.Count < 1)
                {
                    continue;
                }
                var max = new StringBuilder();
                var min = new StringBuilder();
                foreach (var pw in powers)
                {
                    if (!pws.ContainsKey(pw.Key))
                    {
                        pws[pw.Key] = new List <double>();
                    }
                    if (pw.Value != double.MinValue)
                    {
                        pws[pw.Key].Add(pw.Value);
                    }

                    var maxP = pws[pw.Key].Max();
                    var minP = pws[pw.Key].Min();
                    if (maxP == double.MinValue || minP == double.MinValue)
                    {
                        max.Append($"{pw.Key}: -\r\n");
                        min.Append("-\r\n");
                    }
                    else
                    {
                        max.Append($"{pw.Key}: {maxP:F3}\r\n");
                        min.Append($"{minP:F3}\r\n");
                    }
                }
                readingCallback?.Invoke(
                    "-",
                    max.ToString(),
                    min.ToString()
                    );
            }
            readingCallback?.Invoke("-", "-", "-");
            if (FormMessageBox.MessageBoxResult != 1)
            {
                IsStop = true;
                return;
            }

            if (pws == null || pws.Count < 1)
            {
                throw new Exception($"读取功率失败,{MeasurementController.ErrorString}");
            }
            var items = MeasurementJob.SpecData.GetTestGroupWorkInfoSpecItems(systemGroup.TestGroupID);

            foreach (var testItem in items)
            {
                var pw = default(List <double>);
                var c  = TestPortSetting.Get(testItem.PortSetting).ChannelID;
                if (!pws.TryGetValue(c, out pw))
                {
                    continue;
                }
                if (pw.Count < 2)
                {
                    throw new Exception($"读取功率失败,{MeasurementController.ErrorString}");
                }
                AddPointPDLTestData(testTask, type, temp, testItem.PortSetting, currentWavelength, pw);
            }
        }