
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));
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));
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);
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));
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);
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));
int xCenter3 = (xCenter + xCenter2) / 2;
int yCenter3 = yCenter2 - radius2 / 2;
g.FillEllipse(new SolidBrush(fillColor1), new Rectangle(xCenter3 - 2, yCenter3 - 2, 4, 4));
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));
int xCenter4 = (xCenter + xCenter2) / 2;
int yCenter4 = yCenter2 + radius2 / 2;
g.FillEllipse(new SolidBrush(fillColor2), new Rectangle(xCenter4 - 2, yCenter4 - 2, 4, 4));
}
}
}
}

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)
{
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);
}
}
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];
if (control2 is CheckBox)
{
if (ckbAll.Checked)
{
((CheckBox)control2).Checked = true;
}
else
{
((CheckBox)control2).Checked = false;
}
}
}
}
private int GetCheckBoardNo(string checkedcontrol)
{
int no = Convert.ToInt32(checkedcontrol.Substring(2, 1));
return no;
}
private void ClearCOntrolList()
{
checkednums.Clear();
foreach (System.Windows.Forms.Control control in flowLayoutPanel1.Controls)
{
System.Windows.Forms.Control control2 = control.Controls[0];
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];
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];
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];
if (control4 is TextBox && checkednums.FindAll(x => x == Convert.ToInt32(control4.Tag)).Count > 0)
{
listtTextBoxs.Add((TextBox)control4);
}
}
}
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);
}
}
private void UpdateVersion(int index, int checknum)
{
tasks[index] = Task.Run(() =>
{
string errMsg = string.Empty;
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;
}
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;
}
for (int i = 0; i < chunkbytes.Length; i++)
{
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;
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;
BinHeader header = CommonHelper.BytesToStruct<BinHeader>(headerBytes);
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;
}
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;
}
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];
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
{
public class UpgradeHelper
{
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;
}
}
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;
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;
}
private void InitForms()
{
_frmPpg.Dock = DockStyle.Fill;
_frmPpg.Show();
_frmPpg.FormBorderStyle = FormBorderStyle.None;
_frmPpg.TopLevel = false;
_frmEd.Dock = DockStyle.Fill;
_frmEd.Show();
_frmEd.FormBorderStyle = FormBorderStyle.None;
_frmEd.TopLevel = false;
_frmResult.Dock = DockStyle.Fill;
_frmResult.Show();
_frmResult.FormBorderStyle = FormBorderStyle.None;
_frmResult.TopLevel = false;
_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)
{
}
else if (this.WindowState == FormWindowState.Normal)
{
}
}
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;
}
}
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";
}
}
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();
}
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;
}
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;
}
}
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";
}
public uint Mode
{
get { return (cmbMode.SelectedItem as Mode).Id; }
set { (cmbMode.SelectedItem as Mode).Id = value; }
}
public double Count
{
get { return Convert.ToDouble(txtCount.Text.Trim()); }
set { txtCount.Text = value.ToString(); }
}
public double InsCount
{
get { return Convert.ToDouble(txtInsCount.Text.Trim()); }
set { txtInsCount.Text = value.ToString(); }
}
public string Total
{
get { return txtTotal.Text.Trim(); }
set { txtTotal.Text = value.ToString(); }
}
public string Ratio
{
get { return txtRatio.Text.Trim(); }
set { txtRatio.Text = value.ToString(); }
}
public string InsRatio
{
get { return txtInsRatio.Text.Trim(); }
set { txtInsRatio.Text = value.ToString(); }
}
public string Time
{
get { return txtTime.Text.Trim(); }
set { txtTime.Text = value.ToString(); }
}
private uint channel = 0;
[Browsable(true), Category("自定义设置"), Description("控件通道号")]
public uint Channel
{
get
{
return channel;
}
set
{
channel = value;
pcc_ChTitle.Title = "Channel" + $"{channel}";
Invalidate();
}
}
[Browsable(true), Category("自定义事件"), Description("开始测试")]
public event EventHandler BtnStartClick;
private void btnStart_Click(object sender, EventArgs e)
{
BtnStartClick?.Invoke(this, e);
}
[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
{
public class BertChannelHelper
{
public uint Channel { get; set; }
public bool IsTestStatus { get; set; }
public ConfigPara ConfigPara { get; set; }
public Action<ResultPara> DelResult { get; set; }
public Action<int, string> DelTime { get; set; }
public Action<int, double, double> DelSendMonitor { get; set; }
public ResultPara ResultPara { get; set; }
public Stopwatch stRunTime { get; set; }
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.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;
}
public bool StartAll(ref string errMsg)
{
#region PPG配置
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;
}
public bool ContinueTest(uint channel, ref string errMsg)
{
if (!DeviceBll.Single.BertFunc.BertEDStart(Channel, ref errMsg))
{
ResultPara.Channel = channel;
ResultPara.TestResult = (uint)Common.TestResultType.Fail;
ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDOpenFailed") + errMsg;
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;
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;
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;
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();
}
}
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");
return false;
}
if (!DeviceBll.Single.BertFunc.BertEDStart(Channel, ref errMsg))
{
ResultPara.Channel = channel;
ResultPara.TestResult = (uint)Common.TestResultType.Fail;
ResultPara.ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDOpenFailed") + errMsg;
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;
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;
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;
return false;
}
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;
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();
}
}
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
{
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);
}
}
public bool PPGStop(uint Channel, ref string errMsg)
{
if (!BertDevice.BertPGStop(Channel, ref errMsg))
{
return false;
}
return true;
}
public bool EDStop(uint Channel, ref string errMsg)
{
if (!BertDevice.BertEDStop(Channel, ref errMsg))
{
return false;
}
return true;
}
public bool PPGStart(uint Channel, ref string errMsg)
{
if (!BertDevice.BertPGStart(Channel, ref errMsg))
{
return false;
}
return true;
}
public bool EDStart(uint Channel, ref string errMsg)
{
if (!BertDevice.BertEDStart(Channel, ref errMsg))
{
return false;
}
return true;
}
public bool BertClear(uint Channel, ref string errMsg)
{
if (!BertDevice.BertClr(Channel, ref errMsg))
{
return false;
}
return true;
}
public bool SourceInvertSet(uint Channel, uint invert, ref string errMsg)
{
if (!BertDevice.BertSourceInvertSet(Channel, invert, ref errMsg))
{
return false;
}
return true;
}
public bool SourceInvertGet(uint Channel, ref uint invert, ref string errMsg)
{
if (!BertDevice.BertSourceInvertGet(Channel, ref invert, ref errMsg))
{
return false;
}
return true;
}
public bool SenseInvertSet(uint Channel, uint invert, ref string errMsg)
{
if (!BertDevice.BertSenseInvertSet(Channel, invert, ref errMsg))
{
return false;
}
return true;
}
public bool SenseInvertGet(uint Channel, ref uint invert, ref string errMsg)
{
if (!BertDevice.BertSenseInvertGet(Channel, ref invert, ref errMsg))
{
return false;
}
return true;
}
public bool BertAggravateSet(uint Channel, string aggMode, ref string errMsg)
{
if (!BertDevice.BertAggravateSet(Channel, aggMode, ref errMsg))
{
return false;
}
return true;
}
public bool BertAggravateGet(uint Channel, byte[] aggMode, ref string errMsg)
{
if (!BertDevice.BertAggravateGet(Channel, aggMode, ref errMsg))
{
return false;
}
return true;
}
public bool AggravateSet(uint Channel, string agg, ref string errMsg)
{
if (!BertDevice.BertAggravateSet(Channel, agg, ref errMsg))
{
return false;
}
return true;
}
public bool AggravateGet(uint Channel, byte[] agg, ref string errMsg)
{
if (!BertDevice.BertAggravateGet(Channel, agg, ref errMsg))
{
return false;
}
return true;
}
public bool CtleEqSet(uint Channel, uint eq, ref string errMsg)
{
return true;
}
public bool CtleEqGet(uint Channel, ref uint eq, ref string errMsg)
{
return true;
}
public bool SourcePatterSet(uint Channel, uint patter, string userPatter, ref string errMsg)
{
if (!BertDevice.BertSourcePatterSet(Channel, patter, userPatter, ref errMsg))
{
return false;
}
return true;
}
public bool SourcePatterGet(uint Channel, ref uint patter, ref string errMsg)
{
if (!BertDevice.BertSourcePatterGet(Channel, ref patter, ref errMsg))
{
return false;
}
return true;
}
public bool BertSensePatterSet(uint Channel, uint patter, ref string errMsg)
{
if (!BertDevice.BertSensePatterSet(Channel, patter, ref errMsg))
{
return false;
}
return true;
}
public bool BertSensePatterGet(uint Channel, ref uint patter, ref string errMsg)
{
if (!BertDevice.BertSensePatterGet(Channel, ref patter, ref errMsg))
{
return false;
}
return true;
}
public bool BertRefClock(uint clockSwitch, ref string errMsg)
{
if (!BertDevice.BertRefClock(clockSwitch, ref errMsg))
{
return false;
}
return true;
}
public bool ClockSwitchGet(ref uint clockSwitch, ref string errMsg)
{
if (!BertDevice.BertClockSwitchGet(ref clockSwitch, ref errMsg))
{
return false;
}
return true;
}
public bool GetConfigStatus(uint type, ref uint status, ref string errMsg)
{
if (!BertDevice.BertConfigStatusGet(type, ref status, ref errMsg))
{
return false;
}
return true;
}
public bool GetPPGStatus(uint Channel, uint[] status, ref string errMsg)
{
if (!BertDevice.BertPPGStatusGet(Channel, status, ref errMsg))
{
return false;
}
return true;
}
public bool GetEDStatus(uint Channel, uint[] status, ref string errMsg)
{
if (!BertDevice.BertEDStatusGet(Channel, status, ref errMsg))
{
return false;
}
return true;
}
public bool BertTimeSet(uint Channel, uint TestTime, ref string errMsg)
{
if (!BertDevice.BertTimeSet(Channel, TestTime, ref errMsg))
{
return false;
}
return true;
}
public bool BertTimeGet(uint Channel, ref uint TestTime, ref string errMsg)
{
if (!BertDevice.BertTimeGet(Channel, ref TestTime, ref errMsg))
{
return false;
}
return true;
}
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;
}
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)
{
if (!BertDevice.BertPGStop(Channel, ref ErrMsg))
{
ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("PPGClosedFailed") + ErrMsg;
return false;
}
if (!BertDevice.BertEDStop(Channel, ref ErrMsg))
{
ErrMsg = UIGlobal.GetDicBertChannelHelperValueByKey("EDClosedFailed") + ErrMsg;
return false;
}
return true;
}
}
}