using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ZedGraph; using System.IO; using System.Threading; using CommonLib.IO.File; using CommonLib.LOG; using CommonLib.DAQ; using System.Threading.Tasks; namespace DataCollectionSystem { public partial class NewShow_FIFO_Line_Form : Form { private PointPairList list1 = new PointPairList(); private PointPairList list2 = new PointPairList(); private PointPairList list3 = new PointPairList(); double x = 2000; LineItem curve1; LineItem curve2; LineItem curve3; private int maxPoint = 1000; private static string currentFile = string.Empty; private static string currentFileName = string.Empty; private static TreeNode selectNode; FIFO_IO_FILE fifoRead = new FIFO_IO_FILE(); FIFO_IO_FILE fifoRead2 = new FIFO_IO_FILE(); //FIFO_IO_BaseClass fifoRead = new FIFO_IO_BaseClass(); // FIFO_IO_BaseClass fifoRead2 = new FIFO_IO_BaseClass(); public NewShow_FIFO_Line_Form() { InitializeComponent(); this.WindowState = FormWindowState.Maximized; } private void NewShow_FIFO_Line_Form_Load(object sender, EventArgs e) { ShowZedLine(); LoadTreeFile(); comboBox3.SelectedIndex = 6; } private void LoadTreeFile() { try { string filePatch = Environment.CurrentDirectory + "\\FIFO_Data\\"; DirectoryInfo dir = new DirectoryInfo(filePatch); DirectoryInfo[] dicInfo = dir.GetDirectories(); //返回目录中所有文件和子目录 foreach (DirectoryInfo dic in dicInfo) { TreeNode node = new TreeNode(); node.Text = dic.Name; filePatch = Environment.CurrentDirectory + "\\FIFO_Data\\" + dic.Name+"\\"; dir = new DirectoryInfo(filePatch); DirectoryInfo[] subdicInfos = dir.GetDirectories(); foreach (DirectoryInfo subDic in subdicInfos) { TreeNode sbnode = new TreeNode(); sbnode.Text = subDic.Name; node.Nodes.Add(sbnode); filePatch = Environment.CurrentDirectory + "\\FIFO_Data\\" + dic.Name + "\\" + subDic.Name+"\\"; dir = new DirectoryInfo(filePatch); FileInfo[] subFileInfos = dir.GetFiles(); foreach (FileInfo subFile in subFileInfos) { string[] itemName = subFile.Name.Split('.'); if (itemName[1] == "cap") { if (itemName.Length > 0) { TreeNode sfilnode = new TreeNode(); sfilnode.Text = itemName[0]; sbnode.Nodes.Add(sfilnode); } } } } treeView1.Nodes.Add(node); } } catch (Exception et) { MessageBox.Show(et.Message); } } private int countPoint = 0; private void ShowSearchData() { try { treeView1.Enabled = false; button1.Enabled = false; while (true) { byte[] bytebuffer = fifoRead.Read_FIFO_Data();//.Read_FIFO_Data(); if (bytebuffer == null) { treeView1.Enabled = true; button1.Enabled = true; fifoRead.CloseFile(); return; } if (bytebuffer.Length == 0) { button1.Enabled = true; treeView1.Enabled = true; fifoRead.CloseFile(); return; } for (int i = 0; i < bytebuffer.Length / 4; i=i+20) { byte[] tmpBuffer = new byte[2]; tmpBuffer[0] = bytebuffer[i * 4]; tmpBuffer[1] = bytebuffer[i * 4+1]; short a = BitConverter.ToInt16(tmpBuffer, 0); tmpBuffer[0] = bytebuffer[i * 4+2]; tmpBuffer[1] = bytebuffer[i * 4 + 3]; short b = BitConverter.ToInt16(tmpBuffer, 0); DrawLineByData(a/1000, b, 0); } } } catch { MessageBox.Show("加载文件出错"); } } int addX = 0; private void DrawLineByData(double _vol, double _curr, double _pwr) { if (zedGraphControl1.GraphPane.CurveList.Count <= 0) { return; } //取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem; if (curve == null) { return; } //第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据 IPointListEdit list = curve.Points as IPointListEdit; if (list == null) { return; } // double x = (double)new XDate(DateTime.Now); //if (xtag == 0) //{ // startTime = DateTime.Now; // xtag++; //} //else //{ // xtag = Convert.ToInt32((dtNow - startTime).TotalMilliseconds); //} //double x = xtag; //if (x >= this.zedGraphControl1.GraphPane.XAxis.Scale.Max + 1) //{ // this.zedGraphControl1.GraphPane.XAxis.Scale.Max = this.zedGraphControl1.GraphPane.XAxis.Scale.Max * 2; //} if (list1.Count == 1) { list1[0].X = maxPoint - 1; x = maxPoint; } list1.Add(x, _vol, "V"); if (list1.Count >= maxPoint) { list1.RemoveAt(0); for (int k = 0; k < maxPoint - 1; k++) { list1[k].X = k; list1[k].Y = list1[k].Y; } x = maxPoint; } else { if (list1.Count > 1) { for (int k = 0; k < list1.Count; k++) { list1[k].X = list1[k].X - 100; } x = maxPoint; } } LineAutoFromSystem(_vol, _curr, _pwr); // Console.WriteLine("绘点时间:[{0}],绘点数据--时间[{1}:{4}]-电压[{2}],电流[{3}]", DateTime.Now, dtNow, _vol, _curr, dtNow.Millisecond); //string outMsg = string.Format("绘点时间:[{0}],绘点数据--时间[{1}:{4}]-电压[{2}],电流[{3}]", DateTime.Now, dtNow, _vol, _curr, dtNow.Millisecond); ///SetrichTextBox(outMsg + Environment.NewLine); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); // x--; //System.Threading.Thread.Sleep(waitTime); // } private void LineAutoFromSystem(double t_volt, double t_current, double t_power) { try { double maxPower = 0.00; double maxVolt = 0.00; string[] tmpArray = "10000/10000/100000".Split('/'); double maxCurrent = Convert.ToDouble(tmpArray[1].Substring(0, tmpArray[1].Length - 1)); maxPower = Convert.ToDouble(tmpArray[2].Substring(0, tmpArray[2].Length - 1)); maxVolt = Convert.ToDouble(tmpArray[0].Substring(0, tmpArray[0].Length - 1)); zedGraphControl1.GraphPane.YAxis.Title.Text = " 采样物理值"; if (zedGraphControl1.GraphPane.YAxis.Scale.Max * 0.9 < t_volt) { if (maxVolt > t_volt * 1.1) { zedGraphControl1.GraphPane.YAxis.Scale.Min = 0; zedGraphControl1.GraphPane.YAxis.Scale.Max = GetNearInt(t_volt * 1.2); //左边刻度最大值 zedGraphControl1.GraphPane.YAxis.Scale.MajorStep = GetNearInt(t_volt * 1.2) / 10; } else { zedGraphControl1.GraphPane.YAxis.Scale.Min = 0; zedGraphControl1.GraphPane.YAxis.Scale.Max = maxVolt + 10; //左边刻度最大值 zedGraphControl1.GraphPane.YAxis.Scale.MajorStep = (maxVolt + 10) / 10; } zedGraphControl1.GraphPane.YAxis.Title.Text = " 采样物理值"; } } catch { } } private int GetNearInt(double number) { int tempNumber = Int32.Parse(Math.Truncate(number * 1.2).ToString()); int result = 0; for (int i = 0; i < 10; i++) { if ((tempNumber + i) % 10 == 0) { result = tempNumber + i; break; } } return result; } void zedGraphControl1_ContextMenuBuilder(ZedGraphControl sender, ContextMenuStrip menuStrip, Point mousePt) { foreach (ToolStripMenuItem item in menuStrip.Items) { switch (item.Name) { case "copied_to_clip": item.Text = @"复制到剪贴板"; break; case "copy": item.Text = @"复制"; break; case "page_setup": item.Text = @"页面设置..."; break; case "print": item.Text = @"打印..."; break; case "save_as": item.Text = @"另存图表..."; break; case "set_default": item.Text = @"恢复默认大小"; break; case "show_val": item.Text = @"显示节点数值"; break; case "title_def": item.Text = @"标题"; break; case "undo_all": item.Text = @"还原缩放/移动"; break; case "unpan": item.Text = @"还原移动"; break; case "unzoom": item.Text = @"还原缩放"; break; case "x_title_def": item.Text = @"X 轴"; break; case "y_title_def": item.Text = @"Y 轴"; break; } } } private void ShowZedLine() { try { //获取引用 GraphPane myPane = zedGraphControl1.GraphPane; curve1 = myPane.AddCurve("", list1, Color.LimeGreen, SymbolType.None); curve1.Line.Width = 1.8f; myPane.IsPenWidthScaled = true; curve2 = myPane.AddCurve("", list2, Color.Blue, SymbolType.None); curve2.IsY2Axis = true; curve3 = myPane.AddCurve("", list3, Color.Tomato, SymbolType.None); curve3.Line.Width = 1.8f; curve2.Line.Width = 1.8f; myPane.Fill = new Fill(Color.White); this.zedGraphControl1.MasterPane.Fill.IsVisible = false; this.zedGraphControl1.GraphPane.Chart.Fill.IsVisible = false; myPane.Title.Text = "历史音频"; myPane.Title.IsVisible = false; myPane.YAxis.Title.Text = " 音频物理值"; myPane.Chart.Fill = new Fill(Color.White, Color.White, 45.0f); myPane.YAxis.IsVisible = true; myPane.YAxis.CrossAuto = true; myPane.YAxis.Scale.FontSpec.Size = 9; // myPane.XAxis.Scale.FontSpec.Size = 9; myPane.Y2Axis.Scale.FontSpec.Size = 9; myPane.YAxis.Scale.MajorStep = 1; //左边刻度步长 myPane.YAxis.Scale.Min = -10; myPane.YAxis.Scale.Max = 10; //左边刻度最大值 myPane.YAxis.Scale.MinorStepAuto = true; myPane.Y2Axis.Scale.MajorStep = 1; //左边刻度步长 myPane.Y2Axis.Scale.Min = 0; myPane.Y2Axis.Scale.Max = 10; //左边刻度最大值 myPane.Y2Axis.Scale.MinorStepAuto = true; myPane.Y2Axis.IsVisible = true; myPane.Y2Axis.Scale.MinorStep = 1; myPane.YAxis.Scale.MinorStep = 1; myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.YAxis.MajorTic.IsOpposite = false; // myPane.XAxis.Scale.Format = "HH:mm:ss"; //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // myPane.XAxis.Type = ZedGraph.AxisType.; myPane.XAxis.Title.Text = "1S/格"; //myPane.XAxis.IsVisible = false; myPane.Y2Axis.MinorGrid.IsVisible = true; myPane.XAxis.Scale.Min = 0; //X轴最小值0 myPane.XAxis.Scale.Max = 10; //X轴最大30 myPane.XAxis.Scale.MinorStep = 1;//X轴小步长1,也就是小间隔 myPane.XAxis.MinorTic.IsInside = true; myPane.XAxis.MajorGrid.DashOff = 3.0f; myPane.XAxis.Scale.MajorStep = 1; myPane.XAxis.Scale.IsVisible = false; // myPane.XAxis.Scale.MajorStep = 1;//X轴大步长为5,也就是显示文字的大间隔 myPane.XAxis.MajorGrid.IsVisible = true;//设置X虚线 myPane.XAxis.MajorGrid.Color = Color.Black; myPane.YAxis.MajorGrid.IsVisible = true;//设置Y虚线 myPane.YAxis.MajorGrid.Color = Color.Black; myPane.YAxis.MajorGrid.DashOff = 3.0f; myPane.Y2Axis.MajorGrid.DashOff = 3.0f; double x = (double)new XDate(DateTime.Now); zedGraphControl1.AxisChange(); curve3.IsVisible = false; zedGraphControl1.IsShowPointValues = true; // zedGraphControl1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); } catch (Exception et) { //Logger.WriteLog("初始化图形错误" + et.Message); } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { try { selectNode = e.Node; fifoRead.CloseFile(); ClearLine(); //ShowZedLine(); currentFileName = e.Node.Text; string dateFileName = currentFileName.Split('.')[0].Replace("FIFO",""); string beginTimeString = dateFileName.Split('-')[0] + "-" + dateFileName.Split('-')[1] + "-" + dateFileName.Split('-')[2]; dateTimePickerStart.Value = DateTime.Parse(beginTimeString); dateTimePickerEnd.Value = DateTime.Parse(beginTimeString); numericUpDownHourStart.Value = decimal.Parse(dateFileName.Split('-')[3].Substring(0,2)); numericUpDownMinutsStart.Value = decimal.Parse(dateFileName.Split('-')[3].Substring(2, 2)); numericUpDownSecondStart.Value = decimal.Parse(dateFileName.Split('-')[3].Substring(4, 2)); numericUpDownHour.Value = numericUpDownHourStart.Value; numericUpDownMinutsEnd.Value = numericUpDownMinutsStart.Value; numericUpDownSecondEnd.Value = numericUpDownSecondStart.Value+1; } catch { //MessageBox.Show("请等待文件加载完成"); } } private void ClearLine() { if (list1.Count > 0) { while (list1.Count > 0) { list1.RemoveAt(0); } } if (list2.Count > 0) { while (list2.Count > 0) { list2.RemoveAt(0); } } if (list3.Count > 0) { while (list3.Count > 0) { list3.RemoveAt(0); } } x = 0; zedGraphControl1.Invalidate(); } private void CheckChangeState(CheckBox ck) { } private double GetMaxVolt() { double maxNumber = 0.0; for (int i = 0; i < list1.Count; i++) { if (maxNumber < list1[i].Y) { maxNumber = list1[i].Y; } } return maxNumber; } private double GetMaxCurrent() { double maxNumber = 0.0; for (int i = 0; i < list2.Count; i++) { if (maxNumber < list2[i].Y) { maxNumber = list2[i].Y; } } return maxNumber; } private double GetMaxPower() { double maxNumber = 0.0; for (int i = 0; i < list3.Count; i++) { if (maxNumber < list3[i].Y) { maxNumber = list3[i].Y; } } return maxNumber; } private void SetY2Off() { curve1.IsY2Axis = false; curve2.IsY2Axis = false; curve3.IsY2Axis = false; } private void NewShow_FIFO_Line_Form_SizeChanged(object sender, EventArgs e) { treeView1.Height = this.Height - 40; // groupBox1.Location = new Point(this.groupBox1.Location.X, this.Height - this.groupBox1.Height - 40); // groupBox2.Location = new Point(this.groupBox2.Location.X, this.Height - this.groupBox2.Height - 40 - 50); groupBox3.Location = new Point(this.groupBox3.Location.X, this.Height - this.groupBox3.Height - 40 ); this.zedGraphControl1.Width = this.Width - treeView1.Width - 40; this.zedGraphControl1.Height = this.Height - groupBox3.Height - 50 - 100; } private static int _pageId = 1; private void button2_Click(object sender, EventArgs e) { string fileName = Environment.CurrentDirectory + "\\FIFO_Data\\" + this.treeView1.SelectedNode.Parent.Text + "\\" + this.treeView1.SelectedNode.Text + ".cap"; currentFile = fileName; fifoRead.CloseFile(); if (fifoRead.Init_Read_Stream(fileName)) { byte[] bytebuffer = fifoRead.Read_FIFO_Data(); if (bytebuffer == null) { fifoRead.CloseFile(); return; } if (bytebuffer.Length == 0) { fifoRead.CloseFile(); return; } for (int i = 0; i < bytebuffer.Length / 4; i ++) { byte[] tmpBuffer = new byte[2]; tmpBuffer[0] = bytebuffer[i * 4]; tmpBuffer[1] = bytebuffer[i * 4 + 1]; short a = BitConverter.ToInt16(tmpBuffer, 0); tmpBuffer[0] = bytebuffer[i * 4 + 2]; tmpBuffer[1] = bytebuffer[i * 4 + 3]; short b = BitConverter.ToInt16(tmpBuffer, 0); ListViewItem item = new ListViewItem(); item.SubItems[0].Text = _pageId.ToString(); item.SubItems.Add(DateTime.Now.ToLongTimeString()); item.SubItems.Add(a.ToString()); item.SubItems.Add(b.ToString()); _pageId++; } } } private static int recordCount = 0; private static int fileCount = 1; private void BtnExport_Click(object sender, EventArgs e) { stopReadFile = true; Thread t = new Thread(ExportDataToExcel); t.Start(); } static public void ExportOneFile(string fullFileName,ref int lastrow) { FIFO_IO_FILE fifoRead2 = new FIFO_IO_FILE(); List line1Datas = new List(1000); try { recordCount = 0; fifoRead2.CloseFile(); string FileName = Path.GetFileNameWithoutExtension(fullFileName); string[] subs = FileName.Split('-'); string strTime = subs[subs.Length - 1]; if (fifoRead2.Init_Read_Stream(fullFileName)) { int SampleRate = VK70xNMC.SAMPLING_RATE; // 设置采样率 while (true) { byte[] bytebuffer = null; bytebuffer = fifoRead2.Read_FIFO_Data(); if (bytebuffer == null) { fifoRead2.CloseFile(); break; } if (bytebuffer.Length == 0) { fifoRead2.CloseFile(); break; } for (int i = 0; i < bytebuffer.Length / 8; i++) { byte[] tmpBuffer = new byte[8]; tmpBuffer[0] = bytebuffer[i * 8]; tmpBuffer[1] = bytebuffer[i * 8 + 1]; tmpBuffer[2] = bytebuffer[i * 8 + 2]; tmpBuffer[3] = bytebuffer[i * 8 + 3]; tmpBuffer[4] = bytebuffer[i * 8 + 4]; tmpBuffer[5] = bytebuffer[i * 8 + 5]; tmpBuffer[6] = bytebuffer[i * 8 + 6]; tmpBuffer[7] = bytebuffer[i * 8 + 7]; double a = BitConverter.ToDouble(tmpBuffer, 0); line1Datas.Add(a); } } } else { MessageBox.Show("打开文件失败,文件正在被使用!"); } } catch (Exception ex) { fifoRead2.CloseFile(); LogStorage.Logs.Add(LogLevel.Error, $" {ex.Message} \n{ex.StackTrace} "); } finally { ExcelHelper.WriteCSV(line1Datas.ToArray(), fullFileName, ref lastrow); } } //public delegate void ParameterizedThreadStart(object obj); static public void BatchExportDataToExcel(object obj ) { List files = obj as List; if (files.Count > 0) { int lastRow = 0; foreach (var fileInfo in files) { ExportOneFile(fileInfo.FullName, ref lastRow); } } } private void ExportDataToExcel() { double[] line1Datas = null; double[] line2Datas = null; try { Thread.Sleep(10); recordCount = 0; fileCount = 1; string dateTime1 = string.Format("{0} {1}:{2}:{3}", dateTimePickerStart.Text, numericUpDownHourStart.Value, numericUpDownMinutsStart.Value, numericUpDownSecondStart.Value); string datetime2 = string.Format("{0} {1}:{2}:{3}", dateTimePickerEnd.Text, numericUpDownHour.Value, numericUpDownMinutsEnd.Value, numericUpDownSecondEnd.Value); //没有包含采样率的情况下会出现点数不匹配 DateTime dtBegin = DateTime.Parse(dateTime1); DateTime dtEnd = DateTime.Parse(datetime2); int addTime = (int)((dtEnd - dtBegin).TotalMilliseconds) / 1000; ; //时间多少s string fileName = Environment.CurrentDirectory + "\\FIFO_Data\\" + this.treeView1.SelectedNode.Parent.Parent.Text + "\\" + this.treeView1.SelectedNode.Parent.Text + "\\" + this.treeView1.SelectedNode.Text + ".cap"; currentFile = fileName; fifoRead2.CloseFile(); string dateFileName = currentFileName.Split('.')[0].Replace("FIFO", ""); string beginTimeString = dateFileName.Split('-')[0] + "-" + dateFileName.Split('-')[1] + "-" + dateFileName.Split('-')[2] + " " + dateFileName.Split('-')[3].Substring(0, 2) + ":" + dateFileName.Split('-')[3].Substring(2, 2) + ":" + dateFileName.Split('-')[3].Substring(4, 2); DateTime dtFileTime= DateTime.Parse(beginTimeString); int loopTime = (dtBegin - dtFileTime).Seconds; if (fifoRead2.Init_Read_Stream(fileName)) { int SampleRate = VK70xNMC.SAMPLING_RATE; // 设置采样率 addTime *= SampleRate; line1Datas = new double[addTime]; line2Datas = new double[addTime]; while (true) { byte[] bytebuffer = null; if (loopTime > 0) { bytebuffer = fifoRead2.Read_FIFO_Data(); loopTime--; continue; } bytebuffer = fifoRead2.Read_FIFO_Data(); if (bytebuffer == null) { fifoRead2.CloseFile(); break; } if (bytebuffer.Length == 0) { fifoRead2.CloseFile(); break; } for (int i = 0; i < bytebuffer.Length / 8; i++) { byte[] tmpBuffer = new byte[8]; tmpBuffer[0] = bytebuffer[i * 8]; tmpBuffer[1] = bytebuffer[i * 8 + 1]; tmpBuffer[2] = bytebuffer[i * 8 + 2]; tmpBuffer[3] = bytebuffer[i * 8 + 3]; tmpBuffer[4] = bytebuffer[i * 8 + 4]; tmpBuffer[5] = bytebuffer[i * 8 + 5]; tmpBuffer[6] = bytebuffer[i * 8 + 6]; tmpBuffer[7] = bytebuffer[i * 8 + 7]; double a = BitConverter.ToDouble(tmpBuffer, 0); if (recordCount < line1Datas.Length) { line1Datas[recordCount] = a; line2Datas[recordCount] = a; } else { LogStorage.Logs.Add(LogLevel.Error, $"recordCount={recordCount} 超范围"); } recordCount++; fileCount++; if (recordCount >= addTime) { fifoRead2.CloseFile(); stopReadFile = false; break; } } } } else { stopReadFile = false; MessageBox.Show("打开文件失败,文件正在被使用!"); } } catch(Exception ex) { stopReadFile = false; fifoRead2.CloseFile(); LogStorage.Logs.Add(LogLevel.Error, $" {ex.Message} \n{ex.StackTrace} "); //MessageBox.Show(ex.Message); } finally { ExcelHelper.WriteCVS(line1Datas, DateTime.Now, recordCount); } } private void button1_Click(object sender, EventArgs e) { try { int speedTime = 0; int selectTime = Int32.Parse(comboBox3.Text); double stepPoint = selectTime / 10.0; if (speedTime == 0) { maxPoint = selectTime * 2 * 100; stepPoint = (selectTime / 5.0) * 100; } else if (speedTime == 1) { maxPoint = selectTime * 2 * 5; stepPoint = (selectTime / 10.0) * 5; } else if (speedTime == 2) { maxPoint = selectTime * 2 * 2; stepPoint = (selectTime / 10.0) * 2; } else if (speedTime == 3) { maxPoint = selectTime * 2; } else { maxPoint = selectTime * 2 / 10; stepPoint = (selectTime / 10.0) * 0.1; } GraphPane myPane = zedGraphControl1.GraphPane; if (selectTime < 1000) myPane.XAxis.Title.Text = string.Format("{0}ms/格", selectTime); else myPane.XAxis.Title.Text = string.Format("{0}s/格", selectTime / 1000); //myPane.XAxis.IsVisible = false; myPane.XAxis.Scale.Min = 0; //X轴最小值0 myPane.XAxis.Scale.Max = maxPoint; //X轴最大30 myPane.XAxis.Scale.MinorStep = stepPoint;//X轴小步长1,也就是小间隔 myPane.XAxis.MinorTic.IsInside = true; myPane.XAxis.MajorGrid.DashOff = 1.0f; myPane.XAxis.Scale.MajorStep = stepPoint; myPane.XAxis.Scale.Mag = 0; ClearLine(); Thread t = new Thread(ShowLine); t.Start(); } catch (Exception et) { MessageBox.Show(et.Message); } } private bool stopReadFile = false; private void ShowLine() { try { recordCount = 0; fileCount = 1; string dateTimeStart = string.Format("{0} {1}:{2}:{3}", dateTimePickerStart.Text, numericUpDownHourStart.Value, numericUpDownMinutsStart.Value, numericUpDownSecondStart.Value); string datetimeEnd = string.Format("{0} {1}:{2}:{3}", dateTimePickerEnd.Text, numericUpDownHour.Value, numericUpDownMinutsEnd.Value, numericUpDownSecondEnd.Value); DateTime dtBegin = DateTime.Parse(dateTimeStart); DateTime dtEnd = DateTime.Parse(datetimeEnd); int addTime = (int)((dtEnd - dtBegin).TotalMilliseconds)/1000; string fileName = Environment.CurrentDirectory + "\\FIFO_Data\\" + this.treeView1.SelectedNode.Parent.Parent.Text + "\\" + this.treeView1.SelectedNode.Parent.Text + "\\" + this.treeView1.SelectedNode.Text + ".cap"; //TODO:查找板卡文件名,如果是,重新初始化板块文件名 reNewCaptureFile(fileName); currentFile = fileName; fifoRead.CloseFile(); if (fifoRead.Init_Read_Stream(fileName)) { int SampleRate = VK70xNMC.SAMPLING_RATE; // 设置采样率 addTime *= SampleRate; double[] line1Datas = new double[addTime]; double[] line2Datas = new double[addTime]; while (true) { if (stopReadFile) { fifoRead.CloseFile(); return; } byte[] bytebuffer = fifoRead.Read_FIFO_Data(); if (bytebuffer == null) { fifoRead.CloseFile(); break; } if (bytebuffer.Length == 0) { fifoRead.CloseFile(); break; } for (int i = 0; i < bytebuffer.Length / 8; i++) { if (stopReadFile) { fifoRead.CloseFile(); return; } byte[] tmpBuffer = new byte[8]; /* tmpBuffer[0] = bytebuffer[i * 8]; tmpBuffer[1] = bytebuffer[i * 8 + 1]; tmpBuffer[2] = bytebuffer[i * 8 + 2]; tmpBuffer[3] = bytebuffer[i * 8 + 3]; tmpBuffer[4] = bytebuffer[i * 8 + 4]; tmpBuffer[5] = bytebuffer[i * 8 + 5]; tmpBuffer[6] = bytebuffer[i * 8 + 6]; tmpBuffer[7] = bytebuffer[i * 8 + 7]; */ Array.Copy(bytebuffer, i * 8, tmpBuffer, 0, tmpBuffer.Length); double a = BitConverter.ToDouble(tmpBuffer, 0); if (recordCount % 100 == 0) { DrawLineByData(a, a, a); Console.WriteLine(a); } recordCount++; if (recordCount == addTime) { fifoRead.CloseFile(); break; } } } } } catch(Exception ex) { //fifoRead.CloseFile(); LogStorage.Logs.Add(LogLevel.Error, ex.Message + "\n" + ex.StackTrace); } finally { } } /// /// 如果保存文件没有关闭,将该文件截断 /// /// private void reNewCaptureFile(string fileName) { List ListDAQCards = MainForm.ListDAQCards; foreach(var card in ListDAQCards) { foreach (var fifoFile in card.ListFIFOFile) { if(fifoFile.SaveFileName== fileName) { card.reInitFIFOFiles(); card.reInitWaveFiles(); break; } } } } private void groupBox4_Enter(object sender, EventArgs e) { } private void radioButton8_CheckedChanged(object sender, EventArgs e) { } private void BtnBatchExport_Click(object sender, EventArgs e) { //批量导出 using (DlgBatchExportForm dlgForm = new DlgBatchExportForm()) { TreeNode selectNode = this.treeView1.SelectedNode; if((selectNode==null)||(selectNode.Level!=2)) { MessageBox.Show("请选中需要导出的起始文件"); return; } BtnBatchExport.Enabled = false; TreeNode nodeParent = selectNode.Parent; TreeNode nodeParentGrand = nodeParent.Parent; string FullFileName = Environment.CurrentDirectory + "\\FIFO_Data\\" + nodeParentGrand.Text + "\\" + nodeParent.Text + "\\" + selectNode.Text + ".cap"; dlgForm.FileDirectory = Path.GetDirectoryName(FullFileName); dlgForm.StartFileName = Path.GetFileNameWithoutExtension(FullFileName); if (dlgForm.ShowDialog()==DialogResult.OK) { stopReadFile = true; string StartFileName = dlgForm.StartFileName; string EndFileName = dlgForm.EndFileName; string[] times = { StartFileName, EndFileName }; var files = dlgForm.fileinfos; //Thread t = new Thread(new ParameterizedThreadStart(BatchExportDataToExcel)); //t.Start(files); // 创建一个导出的任务 Task task = new Task(() => { BatchExportDataToExcel(files); }); task.Start(); task.Wait(); MessageBox.Show("导出完毕!"); BtnBatchExport.Enabled = true; } } } } }