小编C#封装一些控件

发布于:2025-09-11 ⋅ 阅读:(16) ⋅ 点赞:(0)

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CurControl
{
    public partial class ucPolarity : UserControl
    {
        public ucPolarity()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.UserPaint, true);
        }
        //开状态颜色
        private Color outputColor1 = Color.Green;
        public Color LeftColor
        {
            get { return outputColor1; }
            set { outputColor1 = value; Invalidate(); }
        }
        //开状态颜色
        private Color outputColor2 = Color.Green;
        public Color RightColor
        {
            get { return outputColor2; }
            set { outputColor2 = value; Invalidate(); }
        }
        private string m_text1 = "output-";

        [Description("文本值,当选中或没有选中时显示,必须是长度为2的数组"), Category("自定义")]
        public string LeftText
        {
            get { return m_text1; }
            set
            {
                m_text1 = value;
                Refresh();
            }
        }
        private string m_text2 = "output+";

        [Description("文本值,当选中或没有选中时显示,必须是长度为2的数组"), Category("自定义")]
        public string RightText
        {
            get { return m_text2; }
            set
            {
                m_text2 = value;
                Refresh();
            }
        }
        private string m_text3 = "s-";

        [Description("文本值,当选中或没有选中时显示,必须是长度为2的数组"), Category("自定义")]
        public string TopText
        {
            get { return m_text3; }
            set
            {
                m_text3 = value;
                Refresh();
            }
        }
        private string m_text4 = "s+";

        [Description("文本值,当选中或没有选中时显示,必须是长度为2的数组"), Category("自定义")]
        public string DownText
        {
            get { return m_text4; }
            set
            {
                m_text4 = value;
                Refresh();
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            using (Pen pen = new Pen(Color.Bisque))
            using(Brush brush=new SolidBrush(Color.Bisque))
            {
                Graphics g = pe.Graphics;
                //设置呈现质量
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //框框
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 5, this.Height / 4), new PointF(this.Width / 12 * 9, this.Height / 4));
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 5, this.Height / 4 * 3), new PointF(this.Width / 12 * 9, this.Height / 4 * 3));
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 9, this.Height / 4), new PointF(this.Width / 12 * 9, this.Height / 4 * 3));
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 4, this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 3), new PointF(this.Width / 12 * 4, this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 3 * 2));
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 4, this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 3), new PointF(this.Width / 12 * 5, this.Height / 4));
                g.DrawLine(new Pen(Color.Black, 2), new PointF(this.Width / 12 * 4, this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 3 * 2), new PointF(this.Width / 12 * 5, this.Height / 4 * 3));
                //output1文字
                Color fillColor1 = outputColor1;
                Color fillColor2 = outputColor2;
                System.Drawing.SizeF sizeF = g.MeasureString(m_text1.Replace(" ", "A"), Font);
                int intTextY = (this.Height - (int)sizeF.Height) / 2 + 2;
                g.DrawString(m_text1, Font, new SolidBrush(fillColor1), new Point(this.Width / 12 * 4 - Convert.ToInt32(sizeF.Width) - 2, intTextY));
                //output1
                int xCenter = this.Width / 12 * 5 + this.Width / 20;
                int yCenter = this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 2;
                int radius = (this.Height / 4 * 3 - this.Height / 4) / 2;
                g.DrawArc(new Pen(fillColor1, 3), xCenter - radius / 2, yCenter - radius / 2, radius, radius, 5, 80);
                g.DrawArc(new Pen(fillColor1, 3), xCenter - radius / 2, yCenter - radius / 2, radius, radius, 95, 80);
                g.DrawArc(new Pen(fillColor1, 3), xCenter - radius / 2, yCenter - radius / 2, radius, radius, 185, 80);
                g.DrawArc(new Pen(fillColor1, 3), xCenter - radius / 2, yCenter - radius / 2, radius, radius, 275, 80);
                //output2文字
                System.Drawing.SizeF sizeF2 = g.MeasureString(m_text2.Replace(" ", "A"), Font);
                int intTextY2 = (this.Height - (int)sizeF2.Height) / 2 + 2;
                g.DrawString(m_text2, Font, new SolidBrush(fillColor2), new Point(this.Width / 12 * 9 + 2, intTextY2));
                //output2
                int xCenter2 = this.Width / 12 * 7 + this.Width / 20;
                int yCenter2 = this.Height / 4 + (this.Height / 4 * 3 - this.Height / 4) / 2;
                int radius2 = (this.Height / 4 * 3 - this.Height / 4) / 2;
                g.DrawArc(new Pen(fillColor2, 3), xCenter2 - radius2 / 2, yCenter2 - radius2 / 2, radius2, radius2, 5, 80);
                g.DrawArc(new Pen(fillColor2, 3), xCenter2 - radius2 / 2, yCenter2 - radius2 / 2, radius2, radius2, 95, 80);
                g.DrawArc(new Pen(fillColor2, 3), xCenter2 - radius2 / 2, yCenter2 - radius2 / 2, radius2, radius2, 185, 80);
                g.DrawArc(new Pen(fillColor2, 3), xCenter2 - radius2 / 2, yCenter2 - radius2 / 2, radius2, radius2, 275, 80);
                //s+文字
                System.Drawing.SizeF sizeF3 = g.MeasureString(m_text3.Replace(" ", "A"), Font);
                g.DrawString(m_text3, Font, new SolidBrush(fillColor1), new Point((xCenter + xCenter2) / 2 - 6, this.Height / 4 - Convert.ToInt32(sizeF.Height) - 2));
                //s1
                int xCenter3 = (xCenter + xCenter2) / 2;
                int yCenter3 = yCenter2 - radius2 / 2;//this.Height / 10 * 6;
                g.FillEllipse(new SolidBrush(fillColor1), new Rectangle(xCenter3 - 2, yCenter3 - 2, 4, 4));
                //s-文字
                System.Drawing.SizeF sizeF4 = g.MeasureString(m_text4.Replace(" ", "A"), Font);
                g.DrawString(m_text4, Font, new SolidBrush(fillColor2), new Point((xCenter + xCenter2) / 2 - 6, this.Height / 4 * 3 + 2));
                //s2
                int xCenter4 = (xCenter + xCenter2) / 2;
                int yCenter4 = yCenter2 + radius2 / 2;//this.Height / 10 * 6;
                g.FillEllipse(new SolidBrush(fillColor2), new Rectangle(xCenter4 - 2, yCenter4 - 2, 4, 4));
                //g.Dispose();
            }
        }
    }
}

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinClient.Business;
using WinClient.Common;
using WinClient.Helper;
using WinClient.Model;
using WinClient.PXIeUp;

namespace WinClient.Menu
{
    public partial class frmUpdateVersion : Form
    {
        List<int> checkednums = new List<int>();//选中的板卡号
        List<ProgressBar> listbar = new List<ProgressBar>();
        List<Label> listbLabels = new List<Label>();
        List<TextBox> listtTextBoxs = new List<TextBox>();
        private string FilePath;        //文件地址
        private Task<bool>[] tasks;
        private int UpgradeType = 0;        //升级类型
        int fileLength = 0;     //文件总长度
        private byte[][] chunkbytes;
        UpgradeHelper upgradeHelper = new UpgradeHelper();
        private Point LeftDown;
        public Dictionary<int, string> dicDeviceType = new Dictionary<int, string>
        {
            { 0,"通讯"}, {1,"业务" }
        };
        public frmUpdateVersion()
        {
            InitializeComponent();
            upgradeHelper.HoverBackColor(this.picFrmClose, Color.Red);
        }

        private void frmUpdateVersion_Load(object sender, EventArgs e)
        {
            //根据识别出的LCR板卡 初始化页面控件
            foreach (int i in Global.PxieAddr.Keys)
            {
                Panel panel = new Panel()
                {
                    Tag = i.ToString(),
                    ForeColor = Color.Black,
                    AutoSize = false,
                    Size = new System.Drawing.Size(700, 45),
                    BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle,
                    Margin = new System.Windows.Forms.Padding(1)
                };
                CheckBox cb = new CheckBox()
                {
                    Tag = i.ToString(),
                    ForeColor = Color.Black,
                    Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
                    AutoSize = false,
                    Size = new System.Drawing.Size(58, 24),
                    Padding = new System.Windows.Forms.Padding(4, 0, 0, 0),
                    Text = "板卡" + i.ToString()
                };
                panel.Controls.Add(cb);
                ProgressBar progressBar = new ProgressBar()
                {
                    Tag = i.ToString(),
                    ForeColor = Color.Black,
                    AutoSize = false,
                    Size = new System.Drawing.Size(260, 23),
                    Location = new System.Drawing.Point(60, 1),
                    MarqueeAnimationSpeed = 100,
                    Maximum = 100,
                    Minimum = 0,
                    Step = 10
                };
                panel.Controls.Add(progressBar);
                Label label = new Label()
                {
                    Tag = i.ToString(),
                    ForeColor = Color.Black,
                    Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
                    AutoSize = false,
                    Size = new System.Drawing.Size(38, 24),
                    Padding = new System.Windows.Forms.Padding(1, 5, 1, 1),
                    Text = "0%",
                    Location = new System.Drawing.Point(325, 0)
                };
                panel.Controls.Add(label);
                TextBox textBox = new TextBox()
                {
                    Tag = i.ToString(),
                    ForeColor = Color.Black,
                    Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
                    AutoSize = false,
                    Size = new System.Drawing.Size(690, 15),
                    Margin = new System.Windows.Forms.Padding(5, 0, 0, 0),
                    Padding = new System.Windows.Forms.Padding(4, 0, 0, 0),
                    Text = "板卡" + i.ToString() + ",当前版本号为:"+ GetIDN(i),
                    Location = new System.Drawing.Point(4, 26),
                    ReadOnly = true,
                    BorderStyle = System.Windows.Forms.BorderStyle.None,
                    BackColor = Color.White
                };
                panel.Controls.Add(textBox);
                flowLayoutPanel1.Controls.Add(panel);
            }
        }
        /// <summary>
        /// 选择或取消全部
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ckbAll_CheckedChanged(object sender, EventArgs e)
        {
            foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls)
            {
                System.Windows.Forms.Control control2 = control.Controls[0];//0是CheckBox
                if (control2 is CheckBox)
                {
                    if (ckbAll.Checked)
                    {
                        ((CheckBox)control2).Checked = true;
                    }
                    else
                    {
                        ((CheckBox)control2).Checked = false;
                    }
                }
            }
        }
        /// <summary>
        /// 获取选中的板卡号
        /// </summary>
        /// <param name="checkedcontrol"></param>
        /// <returns></returns>
        private int GetCheckBoardNo(string checkedcontrol)
        {
            int no = Convert.ToInt32(checkedcontrol.Substring(2, 1));
            return no;
        }
        /// <summary>
        /// 初始化控件列表
        /// </summary>
        private void ClearCOntrolList()
        {
            //File.WriteAllText(Application.StartupPath + "\\Updatedata2.txt", string.Empty);
            //File.WriteAllText(Application.StartupPath + "\\Updatedata3.txt", string.Empty);
            checkednums.Clear();
            foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls)
            {
                System.Windows.Forms.Control control2 = control.Controls[0];//0是CheckBox
                if (control2 is CheckBox)
                {
                    if (((CheckBox)control2).Checked)
                    {
                        int a = GetCheckBoardNo(control2.Text);
                        checkednums.Add(a);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (listbar.Count > 0)
            {
                foreach (ProgressBar progressBar in listbar)
                {
                    progressBar.Value = 0;
                }
            }
            listbar.Clear();
            if (listbLabels.Count > 0)
            {
                foreach (Label label in listbLabels)
                {
                    label.Text = "0%";
                }
            }
            listbLabels.Clear();
            if (listtTextBoxs.Count > 0)
            {
                foreach (TextBox textBox in listtTextBoxs)
                {
                    textBox.Text = string.Empty;
                }
            }
            listtTextBoxs.Clear();
            foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls)
            {
                System.Windows.Forms.Control control2 = control.Controls[1];//1是ProgressBar
                if (control2 is ProgressBar && checkednums.FindAll(x => x == Convert.ToInt32(control2.Tag)).Count > 0)
                {
                    listbar.Add((ProgressBar)control2);
                }
                System.Windows.Forms.Control control3 = control.Controls[2];//2是Label
                if (control3 is Label && checkednums.FindAll(x => x == Convert.ToInt32(control3.Tag)).Count > 0)
                {
                    listbLabels.Add((Label)control3);
                }
                System.Windows.Forms.Control control4 = control.Controls[3];//3是TextBox
                if (control4 is TextBox && checkednums.FindAll(x => x == Convert.ToInt32(control4.Tag)).Count > 0)
                {
                    listtTextBoxs.Add((TextBox)control4);
                }
            }
        }
        /// <summary>
        /// 开始升级逻辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnUpdateVersion_Click(object sender, EventArgs e)
        {
            try
            {
                ClearCOntrolList();
                if (Global.PxieAddr.Count == 0)
                {
                    MessageBox.Show("当前未识别到LCR的板卡信息");
                    return;
                }
                if (listbar.Count == 0)
                {
                    MessageBox.Show("当前未勾选LCR板卡");
                    return;
                }
                if (string.IsNullOrEmpty(FilePath))
                {
                    MessageBox.Show("当前未选择升级文件");
                    return;
                }
                UpgradeType = cb_UpType.SelectedIndex;
                EnableControl(false);
                fileLength = 0;     //文件总长度
                                    //获取文件长度
                using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
                {
                    fileLength = (int)fs.Length;
                }
                string msg = string.Empty;
                bool getfilestatus=GetFileByte(ref msg);
                if (!getfilestatus)
                {
                    MessageBox.Show(msg);
                    return;
                }
                tasks = new Task<bool>[checkednums.Count];
                int i = 0;
                foreach (int j in checkednums)
                {
                    UpdateVersion(i, j);
                    i++;
                }
                bool[] results = await Task.WhenAll(tasks);
                await Task.WhenAll(tasks).ContinueWith((task) =>
                {
                    int b = 0;
                    foreach (int a in checkednums)
                    {
                        if (results[b])
                        {
                            foreach (TextBox textBox in listtTextBoxs)
                            {
                                if (Convert.ToInt32(textBox.Tag) == a)
                                {
                                    this.Invoke(new Action(() =>
                                    {
                                        textBox.Text = "板卡" + textBox.Tag + "升级成功,请对设备重新上电后再进行使用";
                                    }));
                                }
                            }
                        }
                        else
                        {
                            foreach (TextBox textBox in listtTextBoxs)
                            {
                                if (Convert.ToInt32(textBox.Tag) == a)
                                {
                                    this.Invoke(new Action(() =>
                                    {
                                        textBox.Text = "板卡" + textBox.Tag + "升级失败,请重新启动设备再次升级或联系相关人员查看";
                                    }));
                                }
                            }
                        }
                        b++;
                    }
                    EnableControlInvoke(true);
                });
            }
            catch (Exception ex)
            {
                EnableControlInvoke(true);
                LogManager.LogNetManagment.LogNet.WriteError(ex.Message);
            }
            
        }
        /// <summary>
        /// 升级逻辑
        /// </summary>
        /// <param name="index"></param>
        /// <param name="checknum"></param>
        private void UpdateVersion(int index, int checknum)
        {
            tasks[index] = Task.Run(() =>
            {
                string errMsg = string.Empty;
                //发送开始升级命令
                //Console.WriteLine("发送开始命令"+UpgradeType);
                LogManager.LogNetManagment.LogNet.WriteInfo($"发送开始命令checknum{checknum}_{UpgradeType}");
                bool result = DeviceBll.Single.dicpxieUpgradeFuncs[checknum].StartUpgrade(UpgradeType, ref errMsg);
                if (!result)
                {
                    MessageBox.Show(errMsg);
                    EnableControlInvoke(true);
                    return false;
                }
                //发送文件大小信息	
                //Console.WriteLine("发送文件大小"+ fileLength);
                LogManager.LogNetManagment.LogNet.WriteInfo($"发送文件大小checknum{checknum}_{fileLength}");
                result = DeviceBll.Single.dicpxieUpgradeFuncs[checknum].SendFileLength(fileLength, ref errMsg);
                if (!result)
                {
                    MessageBox.Show(errMsg);
                    EnableControlInvoke(true);
                    return false;
                }
                //开始升级,每次读取2048字节文件流数据
                for (int i = 0; i < chunkbytes.Length; i++)
                {
                    //string strdata = string.Join(" ", chunkbytes[i]);
                    //LogManager.LogNetManagment.LogNet.WriteInfo($"文件流数据checknum{checknum}_{i}_{strdata}");
                    //if (checknum == 2)
                    //{
                    //    File.AppendAllText(Application.StartupPath + "\\Updatedata2.txt", $"checknum{checknum}_{i}_{strdata}\r\n");
                    //}
                    //else if (checknum == 3)
                    //{
                    //    File.AppendAllText(Application.StartupPath + "\\Updatedata3.txt", $"checknum{checknum}_{i}_{strdata}\r\n");
                    //}
                    uint sendOverSign;
                    if (i == chunkbytes.Length - 1)
                    {
                        sendOverSign = 1;
                    }
                    else
                    {
                        sendOverSign = 0;
                    }
                    uint upgradeIndex = (uint)i + 1;
                    result = DeviceBll.Single.dicpxieUpgradeFuncs[checknum].SendFileData(chunkbytes[i], (uint)chunkbytes[i].Length, sendOverSign, upgradeIndex, ref errMsg);
                    if (!result)
                    {
                        MessageBox.Show(errMsg);
                        EnableControlInvoke(true);
                        return false;
                    }
                    int k = ((i+1)*100)/chunkbytes.Length;
                    this.Invoke(new Action(() =>
                    {
                        listbar[index].Value = k;
                        listbLabels[index].Text = k + "%";
                        listtTextBoxs[index].Text ="板卡"+ checknum + "正在升级中,请勿关闭当前窗口,并保持设备正常运行!";
                    }));
                }
                return true;
            });
        }

        private bool GetFileByte(ref string Msg)
        {
            int realTxLength = 0;   //文件已发送长度
            //开始升级,每次读取2048字节文件流数据
            using (FileStream fs = new FileStream(FilePath, FileMode.Open))
            {
                //判断文件是否是当前板卡的型号
                byte[] headerBytes = new byte[Marshal.SizeOf(typeof(BinHeader))];
                fs.Read(headerBytes, 0, headerBytes.Length);
                realTxLength = realTxLength + headerBytes.Length;
                // 2. 字节数组转结构体
                BinHeader header = CommonHelper.BytesToStruct<BinHeader>(headerBytes);

                // 3. 输出解析结果
                Console.WriteLine($"产品厂商:{header.Company}");
                Console.WriteLine($"产品型号:{header.DeviceModel}");
                Console.WriteLine($"固件类型:{dicDeviceType[header.DeviceType]}");
                if (header.Company!="PSS")
                {
                    Msg = "当前bin文件厂商信息不匹配,不能升级!";
                    return false;
                }
                foreach (int j in Global.PxieAddr.Keys)
                {
                    string stridn = GetIDN(j);
                    List<string> sList = stridn.Split(',').ToList();
                    string model = sList[1];
                    if (header.DeviceModel != model)
                    {
                        Msg = $"卡槽{j}型号和bin文件中的型号不匹配,不能升级!";
                        return false;
                    }
                }
                if (header.DeviceType != cb_UpType.SelectedIndex)
                {
                    Msg = "当前bin文件固件类型不匹配,不能升级!";
                    return false;
                }
                //// 4. 可选:读取剩余数据(固件部分)
                //byte[] firmwareData = File.ReadAllBytes(outputfile).Skip(headerBytes.Length).ToArray();
                //Console.WriteLine($"固件数据长度:{firmwareData.Length}字节");

                int count = (int)Math.Ceiling((double)fileLength/2048);
                chunkbytes=new byte[count][];
                byte[] dataBuff = new byte[2048];
                int i = 0;
                while (realTxLength != fileLength)
                {
                    //读取升级文件数据
                    int readLength = fs.Read(dataBuff, 0, dataBuff.Length);
                    chunkbytes[i]=new byte[readLength];
                    for (int j = 0; j < readLength; j++)
                    {
                        chunkbytes[i][j] = dataBuff[j];
                    }
                    //更新已发送文件长度
                    realTxLength = realTxLength + readLength;
                    i++;
                }
            }
            return true;
        }
        /// <summary>
        /// 获取idn
        /// </summary>
        /// <param name="boardnum"></param>
        /// <returns></returns>
        private string GetIDN(int boardnum)
        {
            string stridn = string.Empty;
            string idn = "";
            string errMsg = "";
            LogManager.LogNetManagment.LogNet.WriteInfo("读取idn");
            bool status=DeviceBll.Single.dicfuns[boardnum].ReadIDN(ref idn, ref errMsg);
            Console.WriteLine(boardnum+"_"+idn);
            if (!status)
            {
                MessageBox.Show("读取IDN失败!"+errMsg);
                return "";
            }
            if (!string.IsNullOrEmpty(idn))
            {
                stridn = idn.Split('\n')[0];
            }
            return stridn;
        }

        private void btnSelFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog fileDialog = new OpenFileDialog())
            {
                fileDialog.Multiselect = false;
                //请选择文件
                fileDialog.Title = "请选择文件";
                //二进制文件
                fileDialog.Filter = "二进制文件(*bin*)|*.bin*";
                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    FilePath = fileDialog.FileName;//返回文件完整路径
                    tb_FilePath.Text = FilePath;
                }
            }
        }

        private void EnableControlInvoke(bool isEnable)
        {
            this.Invoke(new Action(() =>
            {
                EnableControl(isEnable);
            }));
        }

        private void EnableControl(bool isEnable)
        {
            btnUpdateVersion.Enabled = isEnable;
            ckbAll.Enabled = isEnable;
            cb_UpType.Enabled = isEnable;
            btnSelFile.Enabled = isEnable;
            if (isEnable)
            {
                btnSelFile.BackColor = Color.AliceBlue;
                btnUpdateVersion.BackColor = Color.AliceBlue;
            }
            else
            {
                btnSelFile.BackColor = Control.DefaultBackColor;
                btnUpdateVersion.BackColor = Control.DefaultBackColor;
            }
            foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls)
            {
                System.Windows.Forms.Control control2 = control.Controls[0];//0是CheckBox
                if (control2 is CheckBox)
                {
                    ((CheckBox)control2).Enabled = isEnable;
                }
            }
        }

        private void picFrmClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            LeftDown.X = e.X;
            LeftDown.Y = e.Y;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point p = MousePosition;
                p.Offset(-LeftDown.X, -LeftDown.Y);
                Location = p;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinClient.Helper
{
    /// <summary>
    /// 升级帮助类
    /// </summary>
    public class UpgradeHelper
    {
        /// <summary>
        /// 文件读取
        /// </summary>
        /// <param name="fileUrl">文件路径</param>
        /// <returns>byte形式的文件数据</returns>
        public byte[] FileToByte(string fileUrl)
        {
            try
            {
                using (FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read))
                {
                    byte[] byteArray = new byte[fs.Length];
                    fs.Read(byteArray, 0, byteArray.Length);
                    return byteArray;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// 读取文件指定长度内容
        /// </summary>
        /// <param name="fileUrl">文件路径</param>
        /// <param name="startPoint"></param>
        /// <param name="readLength">读取长度</param>
        /// <param name="byteArray">byte形式的文件数据</param>
        /// <returns>返回实际读取到的长度</returns>
        public int FileToByteByLength(string fileUrl, int startPoint, int readLength, byte[] byteArray)
        {
            int realReadLen = 0;
            try
            {
                using (FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read))
                {
                    byteArray = new byte[readLength];
                    realReadLen = fs.Read(byteArray, startPoint, readLength);
                    return realReadLen;
                }
            }
            catch (Exception)
            {
                return realReadLen;
            }
        }

        public void HoverBackColor(System.Windows.Forms.Control control, Color hoverColor)
        {
            var leaveColor = control.BackColor;
            control.MouseEnter += (sender, e) =>
            {
                control.BackColor = hoverColor;
            };
            control.MouseLeave += (sender, e) =>
            {
                control.BackColor = leaveColor;
            };
        }

        public void HoverBackColorByControl(System.Windows.Forms.Control control, System.Windows.Forms.Control control2, Color hoverColor)
        {
            var leaveColor = control2.BackColor;
            control.MouseEnter += (sender, e) =>
            {
                control2.BackColor = hoverColor;
            };
            control.MouseLeave += (sender, e) =>
            {
                control2.BackColor = leaveColor;
            };
        }

        public void ActualMethodWrapper(Action method)
        {
            try
            {
                method.Invoke();
            }
            catch (ThreadAbortException)
            {
                MessageBox.Show("请求超时,请检查通信!");
            }
        }

        public void CallTimedOutMethod(Action method, int milliseconds)
        {
            new Thread(new ThreadStart(() =>
            {
                Thread actionThread = new Thread(new ThreadStart(() =>
                {
                    ActualMethodWrapper(method);
                }));
                actionThread.Start();
                Thread.Sleep(milliseconds);
                if (actionThread.IsAlive)
                    actionThread.Abort();
            })).Start();
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PssControl.PssControlEx;
using PSS_Bert_200G_IS_SOFT.Frm;
using PSS_Bert_200G_IS_SOFT.Common;
using PSS_Bert_200G_IS_SOFT.Business;
using PSS_Bert_200G_IS_SOFT.BLL;
using Common;
using PSS_Bert_200G_IS_SOFT.Model;

namespace PSS_Bert_200G_IS_SOFT
{
    public partial class frmMain : Form
    {
        private bool isMouseDown = false;
        private Point FormLocation;
        private Point mouseOffset;
        static readonly BertHelper bertHelper = new BertHelper(DeviceBll.Single.BertFunc);
        readonly frmPPG _frmPpg=new frmPPG(bertHelper);
        readonly frmED _frmEd =new frmED(bertHelper);
        readonly frmResult _frmResult = new frmResult(bertHelper);
        readonly frmMonitor _frmMonitor = new frmMonitor();
        readonly frmClock _frmClock = new frmClock(bertHelper);
        public FormType formtype=FormType.PpgForm;
        /// <summary>
        /// 测试状态
        /// </summary>
        private bool TestStatus = false;
        public frmMain()
        {
            InitializeComponent();
            DeviceBll.EventUpdateBtnStartAll += UpdateBtnStartAll;
            #region 语言
            if (Convert.ToInt32(IniFileHelper.IniReadValue(DeviceBll.Single.ChoosesetPath, "Language", "Language", "0")) == 0)
            {
                CommonHelper.SetLang("zh-CN", this, typeof(frmMain));  //中文
            }
            else if (Convert.ToInt32(IniFileHelper.IniReadValue(DeviceBll.Single.ChoosesetPath, "Language", "Language", "0")) == 1)
            {
                CommonHelper.SetLang("en-US", this, typeof(frmMain));  //英文
            }
            UIGlobal.LoadUIData();
            #endregion

            UpdateConfig();
            InitForms();
            button_PPG.OriginalColor = Color.DeepSkyBlue;
            panel_Mode.Controls.Add(_frmPpg);
            DeviceBll.EventUpdateConfig += UpdateConfig;

            for (uint i = 0; i < 8; i++)
            {
                bertHelper.DicChannelHelper[i].DelTime = _frmResult.RefreshTime;
                bertHelper.DicChannelHelper[i].DelResult = _frmResult.ReceiveResult;
                bertHelper.DicChannelHelper[i].DelSendMonitor = _frmMonitor.ReceiveRatio1;
            }
        }

        #region 点击拖动窗体
        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = true;
                FormLocation = this.Location;
                mouseOffset = Control.MousePosition;
            }
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            int x = 0;
            int y = 0;
            if (isMouseDown)
            {
                Point pt = Control.MousePosition;
                x = mouseOffset.X - pt.X;
                y = mouseOffset.Y - pt.Y;
                this.Location = new Point(FormLocation.X - x, FormLocation.Y - y);
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;//全局变量防止鼠标没有按下左键窗体也跟着移动
        }
        #endregion

        private void RemovePanelControl()
        {
            foreach (Control control in panel_Mode.Controls)
            {
                panel_Mode.Controls.Remove(control);
            }
        }

        private void button_PPG_Click(object sender, EventArgs e)
        {
            if (formtype == FormType.PpgForm)
            {
                return;
            }
            RemovePanelControl();
            SetButtonColor();
            button_PPG.OriginalColor = Color.DeepSkyBlue;
            panel_Mode.Controls.Add(_frmPpg);
            formtype = FormType.PpgForm;
        }

        private void button_ED_Click(object sender, EventArgs e)
        {
            if (formtype == FormType.EdForm)
            {
                return;
            }
            RemovePanelControl();
            SetButtonColor();
            button_ED.OriginalColor = Color.DeepSkyBlue;
            panel_Mode.Controls.Add(_frmEd);
            formtype = FormType.EdForm;
        }

        private void button_Result_Click(object sender, EventArgs e)
        {
            ShowResult();
        }

        private void ShowResult()
        {
            if (formtype == FormType.ResultForm)
            {
                return;
            }
            RemovePanelControl();
            SetButtonColor();
            button_Result.OriginalColor = Color.DeepSkyBlue;
            panel_Mode.Controls.Add(_frmResult);
            formtype = FormType.ResultForm;
        }

        /// <summary>
        /// 初始化嵌入主窗体的界面
        /// </summary>
        private void InitForms()
        {
            //PPG界面
            _frmPpg.Dock = DockStyle.Fill;
            _frmPpg.Show();
            _frmPpg.FormBorderStyle = FormBorderStyle.None;
            _frmPpg.TopLevel = false;
            //ED界面
            _frmEd.Dock = DockStyle.Fill;
            _frmEd.Show();
            _frmEd.FormBorderStyle = FormBorderStyle.None;
            _frmEd.TopLevel = false;
            //Result界面
            _frmResult.Dock = DockStyle.Fill;
            _frmResult.Show();
            _frmResult.FormBorderStyle = FormBorderStyle.None;
            _frmResult.TopLevel = false;
            //Monitor界面
            _frmMonitor.Dock = DockStyle.Fill;
            _frmMonitor.Show();
            _frmMonitor.FormBorderStyle = FormBorderStyle.None;
            _frmMonitor.TopLevel = false;
        }

        private void SetButtonColor()
        {
            button_PPG.OriginalColor = Color.White;
            button_ED.OriginalColor = Color.White;
            button_Result.OriginalColor = Color.White;
            button_Monitor.OriginalColor = Color.White;
        }

        private void tsm_Connect_Click(object sender, EventArgs e)
        {
            using (frmConnect frmConnect = new frmConnect(UpdateConnectStatus))
            {
                frmConnect.ShowDialog();
            }
        }

        private void tsm_About_Click(object sender, EventArgs e)
        {
            using (frmAbout frmAbout = new frmAbout())
            {
                frmAbout.ShowDialog();
            }
        }

        #region 主程序最小化、最大化、关闭控制
        private void picFrmMaxMin_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                Control c = sender as Control;
                switch (c.Tag.ToString())
                {
                    case "min":
                        this.WindowState = FormWindowState.Minimized;
                        break;
                    case "max":
                        if (this.WindowState == FormWindowState.Maximized)
                        {
                            this.WindowState = FormWindowState.Normal;
                        }
                        else if (this.WindowState == FormWindowState.Normal)
                        {
                            this.WindowState = FormWindowState.Maximized;
                        }
                        break;
                    case "close":
                        Exit();
                        break;
                }
            }
            catch (Exception exp)
            {
                LogManager.LogNetManagment.LogNet.WriteError(exp.Message);
            }
        }

        private void picFrmMaxMin_MouseLeave(object sender, EventArgs e)
        {
            Control c = sender as Control;
            c.BackColor = Color.Transparent;
        }

        private void frmMain_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                //picFrmMaxMin.Image = PSS_Bert_200G_IS_SOFT.Properties.Resources.还原;
            }
            else if (this.WindowState == FormWindowState.Normal)
            {
                //picFrmMaxMin.Image = PSS_Bert_200G_IS_SOFT.Properties.Resources.最大化1;
            }
        }

        
        private void picFrmMin_MouseEnter(object sender, EventArgs e)
        {
            Control c = sender as Control;
            switch (c.Tag.ToString())
            {
                case "min":
                case "max":
                    c.BackColor = Color.SteelBlue;
                    break;
                case "close":
                    c.BackColor = Color.FromArgb(232, 17, 35);
                    break;
            }
        }

        /// <summary>
        /// 退出程序
        /// </summary>
        public void Exit()
        {
            DialogResult result = MessageBox.Show(UIGlobal.GetDicBertChannelHelperValueByKey("ExitTip"), UIGlobal.GetDicBertChannelHelperValueByKey("Exit"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification);
            if (result == DialogResult.Yes)
            {
                this.Close();
                Dispose();
            }
        }
        #endregion

        private void tsm_Save_Click(object sender, EventArgs e)
        {
            using (frmFileExportSet frmFileExportSet=new frmFileExportSet())
            {
                frmFileExportSet.ShowDialog();
            }
        }

        private void tsm_allChannelSetting_Click(object sender, EventArgs e)
        {
            using (frmConfig frmConfig = new frmConfig())
            {
                frmConfig.ShowDialog();
            }
        }

        private void tsm_ClockSwitch_Click(object sender, EventArgs e)
        {
            _frmClock.ShowDialog();
        }

        private void button_Monitor_Click(object sender, EventArgs e)
        {
            if (formtype == FormType.MonitorForm)
            {
                return;
            }
            RemovePanelControl();
            SetButtonColor();
            button_Monitor.OriginalColor = Color.DeepSkyBlue;
            panel_Mode.Controls.Add(_frmMonitor);
            formtype = FormType.MonitorForm;
        }

        public void UpdateConnectStatus(bool status)
        {
            if (status)
            {
                lbstatus.Text = "Connected";
            }
            else
            {
                lbstatus.Text = "Disconnected";
            }
        }

        /// <summary>
        /// 响应型号切换
        /// </summary>
        private void UpdateConfig()
        {
            txt_Speed.Text = DeviceBll.Single.InitConfig.ListSpeed.Find(x=>x.Id== DeviceBll.Single.MainConfigSet.Speed).Value;
            txt_Level.Text = DeviceBll.Single.InitConfig.ListLevel.Find(x => x.Id == DeviceBll.Single.MainConfigSet.Level).Value;
        }

        private void ChinaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommonHelper.SetLang("zh-CN", this, typeof(frmMain));  //中文
            IniFileHelper.IniWriteValue(DeviceBll.Single.ChoosesetPath, "Language", "Language", "0");
            DeviceBll.Single.Language = Language.Chinese;
            UIGlobal.LoadUIData();
        }

        private void englishToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommonHelper.SetLang("en-US", this, typeof(frmMain));  //英文
            IniFileHelper.IniWriteValue(DeviceBll.Single.ChoosesetPath, "Language", "Language", "1");
            DeviceBll.Single.Language = Language.English;
            UIGlobal.LoadUIData();
        }


        /// <summary>
        /// StartAll
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartAll_Click(object sender, EventArgs e)
        {
            ShowResult();
            if (!TestStatus)
            {
                //测试
                TestStatus = true;
                this.btnStartAll.UIText = "Stop All";
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        string errMsg = string.Empty;
                        for (int i = 0; i < 8; i++)
                        {
                            if (IsAllTest(i))
                            {
                                return;
                            }
                            //if (!bertHelper.DicChannelHelper[(uint)i].StartAll(ref errMsg))
                            //{
                            //    MessageBox.Show(errMsg);
                            //    return;
                            //}
                            //if (IsAllTest(i))
                            //{
                            //    return;
                            //}
                            bertHelper.DicChannelHelper[(uint) i].IsTestStatus = true;
                            ConfigPara configPara = new ConfigPara();
                            configPara.Mode = DeviceBll.Single.MainConfigSet.Mode;
                            configPara.Time = DeviceBll.Single.MainConfigSet.Time;
                            bertHelper.DicChannelHelper[(uint)i].ConfigPara = configPara;
                            bertHelper.DicChannelHelper[(uint)i].IsTestStatus = true;
                            this.Invoke(new Action(() =>
                            {
                                _frmResult.SetControlEnable((uint)i, false);
                            }));
                            bertHelper.DicChannelHelper[(uint)i].ResultTest();
                        }
                    }
                    catch (Exception exp)
                    {
                        LogManager.LogNetManagment.LogNet.WriteError(exp.ToString());
                    }
                }).ContinueWith((ta) =>
                {
                    this.Invoke(new Action(() =>
                    {
                        this.btnStartAll.Enabled = true;
                    }));
                });
            }
            else
            {
                Task.Run(() =>
                {
                    TestStatus = false;
                    for (int i = 0; i < 8; i++)
                    {
                        string errMsg = string.Empty;
                        if (!bertHelper.EDStop((uint)i, ref errMsg))
                        {
                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show(UIGlobal.GetDicBertChannelHelperValueByKey("EDClosedFailed") + errMsg);
                            }));
                        }
                        bertHelper.DicChannelHelper[(uint)i].IsTestStatus = false;
                        this.Invoke(new Action(() =>
                        {
                            _frmResult.SetControlEnable((uint)i, true);
                        }));
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.btnStartAll.UIText = "Start All";
                    }));
                });
            }
        }

        private void UpdateBtnStartAll()
        {
            btnStartAll.UIText = "Start All";
            TestStatus = false;
        }

        public bool IsAllTest(int channel)
        {
            if (bertHelper.DicChannelHelper[(uint) channel].IsTestStatus && TestStatus)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// ClearAll
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClearAll_Click(object sender, EventArgs e)
        {
            this.btnClearAll.Enabled = false;
            Task.Factory.StartNew(() =>
            {
                try
                {
                    string errMsg = string.Empty;
                    for (int i = 0; i < 8; i++)
                    {
                        if (!bertHelper.DicChannelHelper[(uint)i].Clear(ref errMsg))
                        {
                            MessageBox.Show(errMsg);
                            return;
                        }
                    }
                }
                catch (Exception exp)
                {
                    LogManager.LogNetManagment.LogNet.WriteError(exp.ToString());
                }
            }).ContinueWith((t) =>
            {
                this.Invoke(new Action(() =>
                {
                    this.btnClearAll.Enabled = true;
                }));
            });
        }

        private void tsm_Setting_Click(object sender, EventArgs e)
        {
            using (frmConfig frmConfig = new frmConfig())
            {
                frmConfig.ShowDialog();
            }
        }

        private void clockSwitchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _frmClock.ShowDialog();
        }
    }
}

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PSS_Bert_200G_IS_SOFT.Business;

namespace PSS_Bert_200G_IS_SOFT.UcControl
{
    public partial class ucResult : UserControl
    {
        public ucResult()
        {
            InitializeComponent();
            //模式
            cmbMode.DataSource = DeviceBll.Single.InitConfig.ListMode;
            cmbMode.ValueMember = "Id";
            cmbMode.DisplayMember = "Value";
        }

        /// <summary>
        /// 时间模式
        /// </summary>
        public uint Mode
        {
            get { return (cmbMode.SelectedItem as Mode).Id; }
            set { (cmbMode.SelectedItem as Mode).Id = value; }
        }

        /// <summary>
        /// 误码数
        /// </summary>
        public double Count
        {
            get { return Convert.ToDouble(txtCount.Text.Trim()); }
            set { txtCount.Text = value.ToString(); }
        }

        /// <summary>
        /// 顺时误码数
        /// </summary>
        public double InsCount
        {
            get { return Convert.ToDouble(txtInsCount.Text.Trim()); }
            set { txtInsCount.Text = value.ToString(); }
        }

        /// <summary>
        /// 总码数
        /// </summary>
        public string Total
        {
            get { return txtTotal.Text.Trim(); }
            set { txtTotal.Text = value.ToString(); }
        }

        /// <summary>
        /// 误码率
        /// </summary>
        public string Ratio
        {
            get { return txtRatio.Text.Trim(); }
            set { txtRatio.Text = value.ToString(); }
        }

        /// <summary>
        /// 顺时误码率
        /// </summary>
        public string InsRatio
        {
            get { return txtInsRatio.Text.Trim(); }
            set { txtInsRatio.Text = value.ToString(); }
        }

        /// <summary>
        /// 时间
        /// </summary>
        public string Time
        {
            get { return txtTime.Text.Trim(); }
            set { txtTime.Text = value.ToString(); }
        }

        private uint channel = 0;
        /// <summary>
        /// 控件通道号
        /// </summary>
        [Browsable(true), Category("自定义设置"), Description("控件通道号")]
        public uint Channel
        {
            get
            {
                return channel;
            }
            set
            {
                channel = value;
                pcc_ChTitle.Title = "Channel" + $"{channel}";
                Invalidate();
            }
        }

        /// <summary>
        /// 开始测试
        /// </summary>
        [Browsable(true), Category("自定义事件"), Description("开始测试")]
        public event EventHandler BtnStartClick;
        private void btnStart_Click(object sender, EventArgs e)
        {
            BtnStartClick?.Invoke(this, e);
        }

        /// <summary>
        /// 清零
        /// </summary>
        [Browsable(true), Category("自定义事件"), Description("清零")]
        public event EventHandler BtnClearClick;
        private void btnClear_Click(object sender, EventArgs e)
        {
            BtnClearClick?.Invoke(this, e);
        }

        private void cmbMode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PSS_Bert_200G_IS_SOFT.Model;
using PSS_Bert_200G_IS_SOFT.Business;
using System.IO;
using System.Threading;
using LogManager;
using System.Diagnostics;
using System.Net.Mime;
using System.Windows.Forms;
using Timer = System.Threading.Timer;

namespace PSS_Bert_200G_IS_SOFT.BLL
{
    /// <summary>
    /// 多通道帮助类
    /// </summary>
    public class BertChannelHelper
    {
        /// <summary>
        /// 通道
        /// </summary>
        public uint Channel { get; set; }
        public bool IsTestStatus { get; set; }
        public ConfigPara ConfigPara { get; set; }
        /// <summary>
        /// 发送结果数据
        /// </summary>
        public Action<ResultPara> DelResult { get; set; }
        /// <summary>
        /// 刷新时间
        /// </summary>
        public Action<int, string> DelTime { get; set; }
        /// <summary>
        /// 发送误码率结果
        /// </summary>
        public Action<int, double, double> DelSendMonitor { get; set; }
        public ResultPara ResultPara { get; set; }
        /// <summary>
        /// 运行时间
        /// </summary>
        public Stopwatch stRunTime { get; set; }
        /// <summary>
        /// 定时器
        /// </summary>
        public Timer TimerInterval { get; set; }
        public BertChannelHelper(uint channel,ConfigPara configPara, ResultPara resultPara)
        {
            Channel = channel;
            ConfigPara = configPara;
            ResultPara = resultPara;
            IsTestStatus = false;
            stRunTime = new Stopwatch();
        }

        public void ResultTest()
        {
           
            Task<bool> task = Task.Factory.StartNew(() =>
            {
                string errMsg = string.Empty;
                IsTestStatus = true;
                //测试
                if (ConfigPara.Mode == 0)
                {
                    if (!ContinueTest(Channel, ref errMsg))
                    {
                        return false;
                    }
                }
                else
                {
                    if (!FixedTimeTest(Channel, ref errMsg))
                    {
                        return false;
                    }
                }
                return true;
            }).ContinueWith((t) =>
            {
                //ResultPara.TestResult = (uint)Common.TestResultType.FixedSuccess;
                ResultPara.Channel = Channel;
                if (ResultPara.TestResult == (uint)Common.TestResultType.Success)
                {
                    ResultPara.TestResult = (uint)Common.TestResultType.FixedSuccess;
                }
                DelResult(ResultPara);
                if (TimerInterval != null)
                {
                    TimerInterval.Dispose();
                    TimerInterval = null;
                }
                stRunTime.Stop();
                return true;
            });
        }

        public bool Clear(ref string errMsg)
        {
            errMsg = string.Empty;
            if (!DeviceBll.Single.BertFunc.BertClr(Channel, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("ClearFailed") + errMsg;
                return false;
            }
            else
            {
                stRunTime.Restart();
            }
            Thread.Sleep(500);
            return true;
        }

        /// <summary>
        /// StartAll实现
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool StartAll(ref string errMsg)
        {
            #region PPG配置
            ////关闭PPG
            //if (!DeviceBll.Single.BertFunc.BertPGStop(Channel, ref errMsg))
            //{
            //    errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PPGClosedFailed");
            //    return false;
            //}
            ////关闭ED
            //if (!DeviceBll.Single.BertFunc.BertEDStop(Channel, ref errMsg))
            //{
            //    errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDClosedFailed") + errMsg;
            //    return false;
            //}
            ////配置速率
            //if (!DeviceBll.Single.BertFunc.BertSpeedSet(Channel, DeviceBll.Single.MainConfigSet.Speed, ref errMsg))
            //{
            //    errMsg= UIGlobal.GetDicBertChannelHelperValueByKey("SpeedConfigFailed") + errMsg;
            //    return false;
            //}
            //查询速率
            //uint speed = 0;
            //if (!DeviceBll.Single.BertFunc.BertSpeedGet(Channel, ref speed, ref errMsg))
            //{
            //    errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectSpeedFailed") + errMsg;
            //    return false;
            //}
            //if (DeviceBll.Single.MainConfigSet.Speed != speed)
            //{
            //    errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SpeedNoEqual");
            //    return false;
            //}
            //配置幅度
            if (!DeviceBll.Single.BertFunc.BertLevelSet(Channel, DeviceBll.Single.MainConfigSet.Level, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("LevelConfigFailed") + errMsg;
                return false;
            }
            //查询幅度
            uint level = 0;
            if (!DeviceBll.Single.BertFunc.BertLevelGet(Channel, ref level, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectLevelFailed") + errMsg;
                return false;
            }
            if (DeviceBll.Single.MainConfigSet.Level != level)
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("LevelNoEqual");
                return false;
            }
            //码型
            if (!DeviceBll.Single.BertFunc.BertSourcePatterSet(Channel, DeviceBll.Single.MainConfigSet.PpgPattern, DeviceBll.Single.MainConfigSet.UserPattern, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PatternConfigFailed") + errMsg;
                return false;
            }
            uint rtn = 0;
            if (!DeviceBll.Single.BertFunc.BertSourcePatterGet(Channel, ref rtn, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectPatternFailed") + errMsg;
                return false;
            }
            if (rtn != DeviceBll.Single.MainConfigSet.PpgPattern)
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PatternNoEqual");
                return false;
            }
            //预加重
            if (!DeviceBll.Single.BertFunc.BertAggravateSet(Channel, DeviceBll.Single.MainConfigSet.Aggravate.ToString(), ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("AggravateConfigFailed") + errMsg;
                return false;
            }
            byte[] readTapMode = new byte[100];
            if (!DeviceBll.Single.BertFunc.BertAggravateGet(Channel, readTapMode, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectAggravateFailed") + errMsg;
                return false;
            }
            if (!DeviceBll.Single.BertFunc.BertSourceInvertSet(Channel, DeviceBll.Single.MainConfigSet.PPGPolarity, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PolarityConfigFailed") + errMsg;
                return false;
            }
            uint readrtn = 0;
            if (!DeviceBll.Single.BertFunc.BertSourceInvertGet(Channel, ref readrtn, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectPolarityFailed") + errMsg;
                return false;
            }
            if (readrtn != DeviceBll.Single.MainConfigSet.PPGPolarity)
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PolarityNoEqual");
                return false;
            }
            #endregion

            #region Ed配置
            //码型
            if (!DeviceBll.Single.BertFunc.BertSensePatterSet(Channel, DeviceBll.Single.MainConfigSet.EDPattern, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PatternConfigFailed") + errMsg;
                return false;
            }
            rtn = 0;
            if (!DeviceBll.Single.BertFunc.BertSensePatterGet(Channel, ref rtn, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectPatternFailed") + errMsg;
                return false;
            }
            if (rtn != DeviceBll.Single.MainConfigSet.EDPattern)
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PatternNoEqual");
                return false;
            }
            //极性
            if (!DeviceBll.Single.BertFunc.BertSenseInvertSet(Channel, DeviceBll.Single.MainConfigSet.EDPolarity, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PolarityConfigFailed") + errMsg;
                return false;
            }
            readrtn = 0;
            if (!DeviceBll.Single.BertFunc.BertSenseInvertGet(Channel, ref readrtn, ref errMsg))
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectPolarityFailed") + errMsg;
                return false;
            }
            if (readrtn != DeviceBll.Single.MainConfigSet.EDPolarity)
            {
                errMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PolarityNoEqual");
                return false;
            }
            #endregion

            return true;
        }

        /// <summary>
        /// 连续模式测试
        /// </summary>
        /// <param name="ucResult"></param>
        public bool ContinueTest(uint channel, ref string errMsg)
        {
            //ED开启
            if (!DeviceBll.Single.BertFunc.BertEDStart(Channel, ref errMsg))
            {
                ResultPara.Channel = channel;
                ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDOpenFailed") + errMsg;
                //DelResult(ResultPara);
                return false;
            }
            double lastBer = 0;
            double lastCount = 0;
            double lastTotal = 0;
            stRunTime.Restart();
            #region 启动计时器统计时间

            TimerInterval = new Timer((a) =>
            {
                string time = $"{stRunTime.Elapsed.Hours}:{stRunTime.Elapsed.Minutes}:{stRunTime.Elapsed.Seconds}";
                DelTime((int)Channel, time);
                Application.DoEvents();
            }, null, 50, 200);
            #endregion
            while (true)
            {
                if (!IsTestStatus)
                {
                    return true;
                }
                uint SyncStatus = 0;
                uint ErrorStatus = 0;
                double ErrCnt = 0;
                double All = 0;
                double Erct = 0;
                //查询结果
                if (
                    !DeviceBll.Single.BertFunc.BertAllResult(channel, ref SyncStatus, ref ErrorStatus, ref ErrCnt, ref All, ref Erct,
                        ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectResultFailed") + errMsg;
                    //DelResult(ResultPara);
                    return false;
                }
                uint ppgPolarity = 0;
                if (!DeviceBll.Single.BertFunc.BertSourceInvertGet(channel, ref ppgPolarity, ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PPGPolaritySelectFailed") + errMsg;
                    //DelResult(ResultPara);
                    return false;
                }
                uint edPolarity = 0;
                if (!DeviceBll.Single.BertFunc.BertSenseInvertGet(channel, ref edPolarity, ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDPolaritySelectFailed") + errMsg;
                    //DelResult(ResultPara);
                    return false;
                }
                double a = stRunTime.Elapsed.TotalMilliseconds;
                ResultPara.Channel = channel;
                ResultPara.SyncStatus = SyncStatus;
                ResultPara.ErrorStatus = ErrorStatus;
                ResultPara.InsCount = ErrCnt > lastCount ? ErrCnt - lastCount : 0;
                if (SyncStatus == 1)
                {
                    ResultPara.Erct = Erct;
                    ResultPara.InsBer = All > lastTotal ? ResultPara.InsCount / (All - lastTotal) : 0;
                }
                else
                {
                    ResultPara.Erct = 1;
                    ResultPara.InsBer = 1;
                }
                ResultPara.ErrCnt = ErrCnt;
                ResultPara.All = All;
                lastCount = ErrCnt;
                lastBer = Erct;
                lastTotal = All;
                ResultPara.PpgPolarity = ppgPolarity;
                ResultPara.EdPolarity = edPolarity;
                #region Time换算
                double collecTime = stRunTime.Elapsed.TotalSeconds;
                #endregion
                ResultPara.TestResult = (uint)Common.TestResultType.Success;
                ResultPara.ErrMsg = errMsg;
                DelSendMonitor((int)channel, ResultPara.Erct, collecTime);
                DelResult(ResultPara);
                SaveFile(ResultPara.SyncStatus, ResultPara.ErrorStatus, ResultPara.ErrCnt, ResultPara.All, ResultPara.Erct);
                Thread.Sleep(200);
                Application.DoEvents();
            }
        }

        /// <summary>
        /// 连续模式测试
        /// </summary>
        /// <param name="ucResult"></param>
        public bool FixedTimeTest(uint channel, ref string errMsg)
        {
            //定时时间
            double fixedTime = 0;
            if (!Common.CommonHelper.ConvertToSeconds(ConfigPara.Time, ref fixedTime))
            {
                ResultPara.Channel = channel;
                ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("TimeStyleFalse");
                //DelResult(ResultPara);
                return false;
            }
            //ED开启
            if (!DeviceBll.Single.BertFunc.BertEDStart(Channel, ref errMsg))
            {
                ResultPara.Channel = channel;
                ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDOpenFailed") + errMsg;
                //DelResult(ResultPara);
                return false;
            }
            double lastBer = 0;
            double lastCount = 0;
            double lastTotal = 0;
            stRunTime.Restart();
            #region 启动计时器统计时间
            
            TimerInterval = new Timer((a) =>
            {
                string time = $"{stRunTime.Elapsed.Hours}:{stRunTime.Elapsed.Minutes}:{stRunTime.Elapsed.Seconds}";
                DelTime((int)Channel, time);
                if (fixedTime<= stRunTime.Elapsed.TotalSeconds)
                {
                    IsTestStatus = false;
                }
                Application.DoEvents();
            }, null, 1300, 500);
            #endregion
            while (true)
            {
                if (!IsTestStatus)
                {
                    return true;
                }
                uint SyncStatus = 0;
                uint ErrorStatus = 0;
                double ErrCnt = 0;
                double All = 0;
                double Erct = 0;
                errMsg = string.Empty;
                double collecTime = stRunTime.Elapsed.TotalSeconds;
                uint ppgPolarity = 0;
                if (!DeviceBll.Single.BertFunc.BertSourceInvertGet(channel, ref ppgPolarity, ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PPGPolaritySelectFailed") + errMsg;
                    //DelResult(ResultPara);
                    //stRunTime.Stop();
                    return false;
                }
                uint edPolarity = 0;
                if (!DeviceBll.Single.BertFunc.BertSenseInvertGet(channel, ref edPolarity, ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDPolaritySelectFailed") + errMsg;
                    //DelResult(ResultPara);
                    //stRunTime.Stop();
                    return false;
                }
                //查询结果
                if (
                    !DeviceBll.Single.BertFunc.BertAllResult(channel, ref SyncStatus, ref ErrorStatus, ref ErrCnt, ref All, ref Erct,
                        ref errMsg))
                {
                    ResultPara.Channel = channel;
                    ResultPara.TestResult = (uint)Common.TestResultType.Fail;
                    ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("SelectResultFailed") + errMsg;
                    //DelResult(ResultPara);
                    //stRunTime.Stop();
                    return false;
                }
                //double a=stRunTime.Elapsed.TotalMilliseconds;
                ResultPara.Channel = channel;
                ResultPara.SyncStatus = SyncStatus;
                ResultPara.ErrorStatus = ErrorStatus;
                ResultPara.InsCount = ErrCnt > lastCount ? ErrCnt - lastCount : 0;
                if (SyncStatus == 1)
                {
                    ResultPara.Erct = Erct;
                    ResultPara.InsBer = All > lastTotal ? ResultPara.InsCount / (All - lastTotal) : 0;
                }
                else
                {
                    ResultPara.Erct = 1;
                    ResultPara.InsBer = 1;
                }
                ResultPara.ErrCnt = ErrCnt;
                ResultPara.All = All;
                //ResultPara.Erct = Erct;
                //ResultPara.InsBer = All > lastTotal ? ResultPara.InsCount / (All - lastTotal) : 0;
                lastCount = ErrCnt;
                lastBer = Erct;
                lastTotal = All;
                ResultPara.PpgPolarity = ppgPolarity;
                ResultPara.EdPolarity = edPolarity;
                DelSendMonitor((int)channel, ResultPara.Erct, collecTime);
                #region Time换算
                #endregion
                ResultPara.ErrMsg = errMsg;
                ResultPara.TestResult = (uint)Common.TestResultType.Success;
                DelResult(ResultPara);
                SaveFile(ResultPara.SyncStatus, ResultPara.ErrorStatus, ResultPara.ErrCnt, ResultPara.All, ResultPara.Erct);
                Thread.Sleep(200);
                Application.DoEvents();
            }
        }

        /// <summary>
        /// 保存ED数据
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="sync"></param>
        /// <param name="errState"></param>
        /// <param name="count"></param>
        /// <param name="total"></param>
        /// <param name="ratio"></param>
        private void SaveFile(ulong sync, uint errState, double count, double total, double ratio)
        {
            if (!DeviceBll.Single.IsSaveData)
            {
                return;
            }
            try
            {
                string path = "";
                lock (DeviceBll.Single.LockFileObj)
                {
                    string filePath = DeviceBll.Single.SaveDataPath;
                    if (!Directory.Exists(DeviceBll.Single.SaveDataPath))
                    {
                        Directory.CreateDirectory(DeviceBll.Single.SaveDataPath);
                    }
                    filePath += $@"\{ DateTime.Now.ToString("yyyyMMdd")}.csv";
                    //创建本地文件
                    if (!File.Exists(filePath))
                    {
                        using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
                            {
                                sw.WriteLine(UIGlobal.GetDicBertChannelHelperValueByKey("ExportTitle"));
                            }
                        }
                    }

                    using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
                        {
                            sw.WriteLine($"{DateTime.Now.ToString()},{Channel},{sync},{errState},{count},{total},{ratio}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lock (DeviceBll.Single.LockFileObj)
                {
                    LogNetManagment.LogNet.WriteException("SaveFile", ex);
                }
            }

        }
    }
}

using BertSeries.Bert;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PSS_Bert_200G_IS_SOFT.Model;

namespace PSS_Bert_200G_IS_SOFT.BLL
{
    public class BertHelper
    {
        /// <summary>
        /// 设备对象
        /// </summary>
        public BertFunc BertDevice { get; set; }
        public ConfigPara ConfigPara { get; set; }
        public ResultPara ResultPara { get; set; }
        public Dictionary<uint,BertChannelHelper> DicChannelHelper { get; set; } 
        public BertHelper(BertFunc bertDevice)
        {
            this.BertDevice = bertDevice;
            this.ConfigPara=new ConfigPara();
            this.ResultPara=new ResultPara();
            DicChannelHelper =new Dictionary<uint, BertChannelHelper>();
            for (uint i = 0; i < 8; i++)
            {
                BertChannelHelper bertChannelHelper=new BertChannelHelper(i, ConfigPara, ResultPara);
                DicChannelHelper.Add(i, bertChannelHelper);
            }
        }

        /// <summary>
        /// PPG停止
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool PPGStop(uint Channel, ref string errMsg)
        {
            if (!BertDevice.BertPGStop(Channel, ref errMsg))
            {
                return false;
            }

            return true;
        }
        /// <summary>
        /// ED停止
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool EDStop(uint Channel, ref string errMsg)
        {
            if (!BertDevice.BertEDStop(Channel, ref errMsg))
            {
                return false;
            }

            return true;

        }
        /// <summary>
        /// PPG开启
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool PPGStart(uint Channel, ref string errMsg)
        {
            if (!BertDevice.BertPGStart(Channel, ref errMsg))
            {
                return false;
            }

            return true;

        }
        /// <summary>
        /// ED开启
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool EDStart(uint Channel, ref string errMsg)
        {
            if (!BertDevice.BertEDStart(Channel, ref errMsg))
            {
                return false;
            }

            return true;

        }
        /// <summary>
        /// 清除误码
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertClear(uint Channel, ref string errMsg)
        {
            if (!BertDevice.BertClr(Channel, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置极性
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SourceInvertSet(uint Channel, uint invert, ref string errMsg)
        {
            if (!BertDevice.BertSourceInvertSet(Channel, invert, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询极性
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SourceInvertGet(uint Channel, ref uint invert, ref string errMsg)
        {
            if (!BertDevice.BertSourceInvertGet(Channel, ref invert, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置极性
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SenseInvertSet(uint Channel, uint invert, ref string errMsg)
        {
            if (!BertDevice.BertSenseInvertSet(Channel, invert, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询极性
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SenseInvertGet(uint Channel, ref uint invert, ref string errMsg)
        {
            if (!BertDevice.BertSenseInvertGet(Channel, ref invert, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置预加重模式
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="aggMode"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertAggravateSet(uint Channel, string aggMode, ref string errMsg)
        {
            if (!BertDevice.BertAggravateSet(Channel, aggMode, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询预加重模式
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="aggMode"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertAggravateGet(uint Channel, byte[] aggMode, ref string errMsg)
        {
            if (!BertDevice.BertAggravateGet(Channel, aggMode, ref errMsg))
            {
                return false;
            }

            return true;

        }


        /// <summary>
        /// 设置预加重
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool AggravateSet(uint Channel, string agg, ref string errMsg)
        {
            if (!BertDevice.BertAggravateSet(Channel, agg, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询预加重
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool AggravateGet(uint Channel, byte[] agg, ref string errMsg)
        {
            if (!BertDevice.BertAggravateGet(Channel, agg, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置均衡
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool CtleEqSet(uint Channel, uint eq, ref string errMsg)
        {
            //if (!BertDevice.BertEqSet(Channel, eq, ref errMsg))
            //{
            //    return false;
            //}

            return true;

        }

        /// <summary>
        /// 查询均衡
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool CtleEqGet(uint Channel, ref uint eq, ref string errMsg)
        {
            //if (!BertDevice.BertEqGet(Channel, ref eq, ref errMsg))
            //{
            //    return false;
            //}

            return true;

        }

        /// <summary>
        /// PPG设置码型
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SourcePatterSet(uint Channel, uint patter, string userPatter, ref string errMsg)
        {
            if (!BertDevice.BertSourcePatterSet(Channel, patter, userPatter, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// PPG查询码型
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool SourcePatterGet(uint Channel, ref uint patter, ref string errMsg)
        {
            if (!BertDevice.BertSourcePatterGet(Channel, ref patter, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// ED设置码型
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertSensePatterSet(uint Channel, uint patter, ref string errMsg)
        {
            if (!BertDevice.BertSensePatterSet(Channel, patter, ref errMsg))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// ED查询码型
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertSensePatterGet(uint Channel, ref uint patter, ref string errMsg)
        {
            if (!BertDevice.BertSensePatterGet(Channel, ref patter, ref errMsg))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 设置时钟
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertRefClock(uint clockSwitch, ref string errMsg)
        {
            if (!BertDevice.BertRefClock(clockSwitch, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询时钟
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool ClockSwitchGet(ref uint clockSwitch, ref string errMsg)
        {
            if (!BertDevice.BertClockSwitchGet(ref clockSwitch, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询配置状态
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool GetConfigStatus(uint type, ref uint status, ref string errMsg)
        {
            if (!BertDevice.BertConfigStatusGet(type, ref status, ref errMsg))
            {
                return false;
            }

            return true;

        }
        /// <summary>
        /// 查询PPG开启状态
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool GetPPGStatus(uint Channel, uint[] status, ref string errMsg)
        {
            if (!BertDevice.BertPPGStatusGet(Channel, status, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询ED开启状态
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool GetEDStatus(uint Channel, uint[] status, ref string errMsg)
        {
            if (!BertDevice.BertEDStatusGet(Channel, status, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置时间模式 测试时间 0为连续模式 其他数字为定时测试时间,目前最大65535,若需更大定时时间,建议使用上位机定时功能
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertTimeSet(uint Channel, uint TestTime, ref string errMsg)
        {
            if (!BertDevice.BertTimeSet(Channel, TestTime, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询时间模式 测试时间 0为连续模式 其他数字为定时测试时间,目前最大65535,若需更大定时时间,建议使用上位机定时功能
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertTimeGet(uint Channel, ref uint TestTime, ref string errMsg)
        {
            if (!BertDevice.BertTimeGet(Channel, ref TestTime, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 查询时间模式 测试时间 0为连续模式 其他数字为定时测试时间,目前最大65535,若需更大定时时间,建议使用上位机定时功能
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BertResult(uint Channel, ref uint SyncStatus, ref uint ErrorStatus, ref double ErrCnt, ref double All, ref double Erct, ref string errMsg)
        {
            if (!BertDevice.BertAllResult(Channel, ref SyncStatus, ref ErrorStatus, ref ErrCnt, ref All, ref Erct, ref errMsg))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// 设置速率 channel为8设置全通道
        /// </summary>
        /// <param name="Channel"></param>
        /// <param name="Speed"></param>
        /// <param name="ErrMsg"></param>
        /// <returns></returns>
        public bool BertSpeedSet(uint Channel, uint Speed, ref string ErrMsg)
        {
            if (!BertDevice.BertSpeedSet(Channel, Speed, ref ErrMsg))
            {
                return false;
            }
            return true;
        }

        public bool ClosePpgEd(uint Channel, ref string ErrMsg)
        {
            //关闭PPG
            if (!BertDevice.BertPGStop(Channel, ref ErrMsg))
            {
                ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PPGClosedFailed") + ErrMsg;
                return false;
            }
            //关闭ED
            if (!BertDevice.BertEDStop(Channel, ref ErrMsg))
            {
                ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDClosedFailed") + ErrMsg;
                return false;
            }
            return true;
        }
    }
}


网站公告

今日签到

点亮在社区的每一天
去签到