WaveViewer.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing.Imaging;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.IO;
  7. using System.Text.Json;
  8. using System.Text.Encodings.Web;
  9. using System.Text.Json.Serialization;
  10. using System.Text.Unicode;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using Uestc.Auto6.Dso.ComModel;
  17. using Uestc.Auto6.Dso.Hardware.Calibration.Data.Base;
  18. namespace Uestc.Auto6.Dso.Hardware.Calibration.Tool
  19. {
  20. public partial class WaveViewer : UserControl
  21. {
  22. public WaveViewer()
  23. {
  24. InitializeComponent();
  25. Wave_ViewInit();
  26. }
  27. public IInstrumentSession CurrInstrument = null;
  28. public WaveDisplayParam[] DisplayParam_Channel
  29. {
  30. get => displayParam_Channel;
  31. }
  32. public WaveDisplayParam[,] DisplayParam_Adc
  33. {
  34. get => displayParam_Adc;
  35. }
  36. private string jsonFileName
  37. {
  38. get => Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".waveparam";
  39. }
  40. public void Run(bool bRun)
  41. {
  42. if (bRun)
  43. timer1.Start();
  44. else
  45. timer1.Stop();
  46. }
  47. public void SaveSetting()
  48. {
  49. List<WaveDisplayParam> waveDisplayParamList = new List<WaveDisplayParam>();
  50. foreach (var param in DisplayParam_Channel)
  51. waveDisplayParamList.Add(param);
  52. for (int adcIndex = 0; adcIndex < Constants.ADC_NUM; adcIndex++)
  53. {
  54. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  55. waveDisplayParamList.Add(DisplayParam_Adc[adcIndex, coreIndex]);
  56. }
  57. if (File.Exists(jsonFileName))
  58. File.Delete(jsonFileName);
  59. JsonSerializerOptions options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) };
  60. File.WriteAllText(jsonFileName, JsonSerializer.Serialize<List<WaveDisplayParam>>(waveDisplayParamList, options), Encoding.UTF8);
  61. }
  62. WaveDisplayParam[] displayParam_Channel;
  63. WaveDisplayParam[,] displayParam_Adc;
  64. void Wave_ViewInit()
  65. {
  66. List<WaveDisplayParam> waveDisplayParamList = new List<WaveDisplayParam>();
  67. if (File.Exists(jsonFileName))
  68. waveDisplayParamList = JsonSerializer.Deserialize<List<WaveDisplayParam>>(File.ReadAllText(jsonFileName, Encoding.UTF8));
  69. int needAddCount = CaliConstants.Fixed_MaxPhysicsChannelCount + CaliConstants.Fixed_PerChannelMergeAdcMaxCount * ServerDomainConstants.PerAdcCoreCount - waveDisplayParamList.Count;
  70. while (needAddCount > 0)
  71. {
  72. waveDisplayParamList.Add(new WaveDisplayParam());
  73. needAddCount--;
  74. }
  75. dataGridViewWaveDataView_Channel.RowCount = CaliConstants.Fixed_MaxPhysicsChannelCount;
  76. displayParam_Channel = new WaveDisplayParam[CaliConstants.Fixed_MaxPhysicsChannelCount];
  77. int displayParamIndex = 0;
  78. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  79. {
  80. displayParam_Channel[channelIndex] = waveDisplayParamList[displayParamIndex++];
  81. dataGridViewWaveDataView_Channel.Rows[channelIndex].Cells[0].Value = $"CH{channelIndex + 1}";
  82. dataGridViewWaveDataView_Channel.Rows[channelIndex].Cells[1].Value = displayParam_Channel[channelIndex].bDisplay;
  83. dataGridViewWaveDataView_Channel.Rows[channelIndex].Cells[2].Style.BackColor = displayParam_Channel[channelIndex].GetColor();
  84. }
  85. dataGridViewWaveDataView_Adc.RowCount = CaliConstants.Fixed_PerChannelMergeAdcMaxCount * ServerDomainConstants.PerAdcCoreCount;
  86. int rowIndex = 0;
  87. displayParam_Adc = new WaveDisplayParam[CaliConstants.Fixed_PerChannelMergeAdcMaxCount, ServerDomainConstants.PerAdcCoreCount];
  88. for (int adcIndex = 0; adcIndex < CaliConstants.Fixed_PerChannelMergeAdcMaxCount; adcIndex++)
  89. {
  90. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  91. {
  92. displayParam_Adc[adcIndex, coreIndex] = waveDisplayParamList[displayParamIndex++];
  93. dataGridViewWaveDataView_Adc.Rows[rowIndex].Cells[0].Value = $"Adc{adcIndex + 1}-Core[{coreIndex + 1}]";
  94. dataGridViewWaveDataView_Adc.Rows[rowIndex].Cells[1].Value = displayParam_Adc[adcIndex, coreIndex].bDisplay;
  95. dataGridViewWaveDataView_Adc.Rows[rowIndex].Cells[2].Style.BackColor = displayParam_Adc[adcIndex, coreIndex].GetColor();
  96. rowIndex++;
  97. }
  98. }
  99. CalcNeedDisplayCount();
  100. comboBoxAdcDotLineMode.SelectedIndex = 0;
  101. buttonADCRunStop.Tag = "stop";
  102. timer1.Start();
  103. }
  104. private void dataGridViewWaveDataView_Channel_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  105. {
  106. if (dataGridViewWaveDataView_Channel.CurrentCell is DataGridViewCheckBoxCell)
  107. {
  108. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  109. {
  110. DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridViewWaveDataView_Channel.Rows[channelIndex].Cells[1];
  111. displayParam_Channel[channelIndex].bDisplay = (bool)cell.FormattedValue;
  112. CalcNeedDisplayCount();
  113. }
  114. dataGridViewWaveDataView_Channel.CurrentCell = dataGridViewWaveDataView_Channel.Rows[dataGridViewWaveDataView_Channel.CurrentCell.RowIndex].Cells[2];
  115. }
  116. }
  117. int channelNeedDisplayCount = 0;
  118. int adcNeedDisplayCount = 0;
  119. private void CalcNeedDisplayCount()
  120. {
  121. bool bChanged = false;
  122. int _channelNeedDisplayCount = displayParam_Channel.Sum<WaveDisplayParam>((o) => o.bDisplay ? 1 : 0);
  123. if (_channelNeedDisplayCount != channelNeedDisplayCount)
  124. {
  125. bChanged = true;
  126. channelNeedDisplayCount = _channelNeedDisplayCount;
  127. }
  128. int _adcNeedDisplayCount = 0;
  129. for (int adcIndex = 0; adcIndex < CaliConstants.Fixed_PerChannelMergeAdcMaxCount; adcIndex++)
  130. {
  131. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  132. {
  133. _adcNeedDisplayCount += displayParam_Adc[adcIndex, coreIndex].bDisplay ? 1 : 0;
  134. }
  135. }
  136. if (_adcNeedDisplayCount != adcNeedDisplayCount)
  137. {
  138. bChanged = true;
  139. adcNeedDisplayCount = _adcNeedDisplayCount;
  140. }
  141. if (bChanged && bAtStopMode)
  142. RedrawAtStopMode();
  143. }
  144. private void dataGridViewWaveDataView_Adc_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  145. {
  146. if (dataGridViewWaveDataView_Adc.CurrentCell is DataGridViewCheckBoxCell)
  147. {
  148. for (int adcIndex = 0; adcIndex < CaliConstants.Fixed_PerChannelMergeAdcMaxCount; adcIndex++)
  149. {
  150. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  151. {
  152. DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridViewWaveDataView_Adc.Rows[adcIndex * ServerDomainConstants.PerAdcCoreCount + coreIndex].Cells[1];
  153. displayParam_Adc[adcIndex, coreIndex].bDisplay = (bool)cell.FormattedValue;
  154. CalcNeedDisplayCount();
  155. }
  156. }
  157. dataGridViewWaveDataView_Adc.CurrentCell = dataGridViewWaveDataView_Adc.Rows[dataGridViewWaveDataView_Adc.CurrentCell.RowIndex].Cells[2];
  158. }
  159. }
  160. int lastNeedDisplayCount = 0;
  161. List<ushort[]> lastAllChannelData = null;
  162. List<ushort[]> lastAllAdcCoreData = null;
  163. private void timer1_Tick(object sender, EventArgs e)
  164. {
  165. if (bAtStopMode || CurrInstrument == null)
  166. return;
  167. timer1.Stop();
  168. int totalSelectCount = channelNeedDisplayCount + adcNeedDisplayCount;
  169. if (totalSelectCount > 0)
  170. {
  171. lastNeedDisplayCount = totalSelectCount;
  172. Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, PixelFormat.Format24bppRgb);
  173. Graphics g = Graphics.FromImage(bitmap);
  174. g.Clear(Color.Black);
  175. if (channelNeedDisplayCount > 0)
  176. {
  177. List<ushort[]> allChannelData = InstrumentInteract.Factory_WaveData_Channel(CurrInstrument);
  178. DrawChannelWaveMain(allChannelData, bitmap);
  179. lastAllChannelData = allChannelData;
  180. }
  181. if (adcNeedDisplayCount > 0)
  182. {
  183. List<ushort[]> allAdcCoreData = InstrumentInteract.Factory_WaveData_Adc(CurrInstrument);
  184. DrawAdcCoreWaveMain(allAdcCoreData, bitmap);
  185. lastAllAdcCoreData = allAdcCoreData;
  186. }
  187. pictureBox1.Image = bitmap;
  188. }
  189. else if (lastNeedDisplayCount != totalSelectCount)
  190. {
  191. pictureBox1.Image = null;
  192. lastNeedDisplayCount = 0;
  193. }
  194. timer1.Start();
  195. }
  196. private int AdcResolution = (int)(Math.Pow(2, ServerDomainConstants.AdcBits));
  197. #region DrawWave
  198. private void DrawChannelWaveMain(List<ushort[]> allChannelData, Bitmap bitmap)
  199. {
  200. if (allChannelData == null)
  201. return;
  202. Graphics g = Graphics.FromImage(bitmap);
  203. g.TranslateTransform(0, pictureBox1.Height / 2);
  204. Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
  205. bool bTopNeedDisplay = false;
  206. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  207. {
  208. if (displayParam_Channel[channelIndex].bDisplay)
  209. {
  210. if (channelIndex != currTopRowIndexofChannel)
  211. DrawChannelWave(allChannelData, bitmap, rect, channelIndex);
  212. else
  213. bTopNeedDisplay = true;
  214. }
  215. }
  216. if (bTopNeedDisplay)
  217. DrawChannelWave(allChannelData, bitmap, rect, currTopRowIndexofChannel);
  218. }
  219. private void DrawAdcCoreWaveMain(List<ushort[]> allAdcCoreData, Bitmap bitmap)
  220. {
  221. if (allAdcCoreData == null)
  222. return;
  223. Graphics g = Graphics.FromImage(bitmap);
  224. g.TranslateTransform(0, pictureBox1.Height / 2);
  225. Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
  226. int topAdcIndex = currTopRowIndexofAdc / ServerDomainConstants.PerAdcCoreCount;
  227. int topCoreIndex = currTopRowIndexofAdc % ServerDomainConstants.PerAdcCoreCount;
  228. bool bTopAdcNeedDisplay = false;
  229. bool bDisplayByDotMode = comboBoxAdcDotLineMode.SelectedIndex != 0;
  230. for (int adcIndex = 0; adcIndex < CaliConstants.Fixed_PerChannelMergeAdcMaxCount; adcIndex++)
  231. {
  232. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  233. {
  234. if (displayParam_Adc[adcIndex, coreIndex].bDisplay)
  235. {
  236. if (topAdcIndex == adcIndex && topCoreIndex == coreIndex)
  237. bTopAdcNeedDisplay = true;
  238. else
  239. {
  240. if (bDisplayByDotMode)
  241. DrawAdcDataByDotMode(allAdcCoreData, bitmap, rect, adcIndex, coreIndex);
  242. else
  243. DrawAdcDataByLineMode(allAdcCoreData, g, rect, adcIndex, coreIndex);
  244. }
  245. }
  246. }
  247. }
  248. if (bTopAdcNeedDisplay)
  249. {
  250. if (bDisplayByDotMode)
  251. DrawAdcDataByDotMode(allAdcCoreData, bitmap, rect, topAdcIndex, topCoreIndex);
  252. else
  253. DrawAdcDataByLineMode(allAdcCoreData, g, rect, topAdcIndex, topCoreIndex);
  254. }
  255. }
  256. private void DrawChannelWave(List<ushort[]> dataList, Bitmap bitmap, Rectangle rect, int channelID)
  257. {
  258. Graphics g = Graphics.FromImage(bitmap);
  259. g.TranslateTransform(0, pictureBox1.Height / 2);
  260. Color waveColor = displayParam_Channel[channelID].GetColor();
  261. int extractNum = (int)numericUpDownWaveChannelExtractNum.Value;
  262. short[] currData = Array.ConvertAll<ushort, short>(dataList[channelID], (y) => (short)((AdcResolution / 2 - y) * rect.Height / AdcResolution));
  263. if (extractNum <= 1)
  264. {
  265. List<Point> points = new List<Point>();
  266. Pen pen = new Pen(waveColor);
  267. int x = 0;
  268. foreach (short y in currData)
  269. {
  270. points.Add(new Point(x, y));
  271. x++;
  272. if (x >= rect.Width)
  273. break;
  274. }
  275. g.DrawLines(pen, points.ToArray());
  276. }
  277. else
  278. {
  279. Brush brush = new SolidBrush(waveColor);
  280. int dataIndex = 0;
  281. int x = 0;
  282. short max = short.MinValue;
  283. short min = short.MaxValue;
  284. for (; ; )
  285. {
  286. max = short.MinValue;
  287. min = short.MaxValue;
  288. for (int i = 0; i < extractNum; i++)
  289. {
  290. if (currData[dataIndex + i] < min)
  291. min = currData[dataIndex + i];
  292. if (currData[dataIndex + i] > max)
  293. max = currData[dataIndex + i];
  294. }
  295. dataIndex += extractNum;
  296. g.FillRectangle(brush, x, min, 1, max - min);
  297. if (dataIndex > currData.Length - extractNum)
  298. break;
  299. x++;
  300. if (x >= rect.Width)
  301. break;
  302. }
  303. }
  304. }
  305. private void DrawAdcDataByDotMode(List<ushort[]> dataList, Bitmap bitmap, Rectangle rect, int adcIndex, int coreIndex)
  306. {
  307. Color color = displayParam_Adc[adcIndex, coreIndex].GetColor();
  308. ushort[] currData_source = dataList[adcIndex * ServerDomainConstants.PerAdcCoreCount + coreIndex];
  309. List<Point> points = new List<Point>();
  310. int height = rect.Height;
  311. short[] currData = Array.ConvertAll<ushort, short>(currData_source, (y) => (short)((AdcResolution / 2 - y) * height / AdcResolution - 1));
  312. int x = 0;
  313. int step = (int)numericUpDownAdcZoomCount.Value;
  314. Pen pen = new Pen(color);
  315. foreach (short y in currData)
  316. {
  317. bitmap.SetPixel(x, y + height / 2, color);
  318. x += step;
  319. if (x >= bitmap.Width)
  320. break;
  321. }
  322. }
  323. private void DrawAdcDataByLineMode(List<ushort[]> dataList, Graphics g, Rectangle rect, int adcIndex, int coreIndex)
  324. {
  325. Color color = displayParam_Adc[adcIndex, coreIndex].GetColor();
  326. ushort[] currData_source = dataList[adcIndex * ServerDomainConstants.PerAdcCoreCount + coreIndex];
  327. List<Point> points = new List<Point>();
  328. int height = rect.Height;
  329. short[] currData = Array.ConvertAll<ushort, short>(currData_source, (y) => (short)((AdcResolution / 2 - y) * height / AdcResolution - 1));
  330. int x = 0;
  331. int step = (int)numericUpDownAdcZoomCount.Value;
  332. foreach (short y in currData)
  333. {
  334. points.Add(new Point(x, y));
  335. x += step;
  336. if (x >= rect.Width)
  337. break;
  338. }
  339. g.DrawLines(new Pen(color), points.ToArray());
  340. }
  341. private void RedrawAtStopMode()
  342. {
  343. if (!bAtStopMode)
  344. return;
  345. if (channelNeedDisplayCount + adcNeedDisplayCount == 0)
  346. return;
  347. if (pictureBox1.Width == 0 || pictureBox1.Height == 0)
  348. return;
  349. Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, PixelFormat.Format24bppRgb);
  350. using (Graphics g = Graphics.FromImage(bitmap))
  351. {
  352. g.Clear(Color.Black);
  353. DrawChannelWaveMain(lastAllChannelData, bitmap);
  354. DrawAdcCoreWaveMain(lastAllAdcCoreData, bitmap);
  355. }
  356. pictureBox1.Image = bitmap;
  357. }
  358. #endregion
  359. public class WaveDisplayParam
  360. {
  361. [JsonPropertyName("color")]
  362. public int IntColor
  363. {
  364. get;
  365. set;
  366. } = Color.White.ToArgb();
  367. public Color GetColor() => Color.FromArgb(IntColor);
  368. [JsonPropertyName("display")]
  369. public bool bDisplay
  370. {
  371. get; set;
  372. } = false;
  373. }
  374. private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
  375. {
  376. }
  377. private void onAdcSelectCtrl(object sender, EventArgs e)
  378. {
  379. bool bSelectAll = bool.Parse((sender as Button).Tag.ToString());
  380. for (int adcIndex = 0; adcIndex < CaliConstants.Fixed_PerChannelMergeAdcMaxCount; adcIndex++)
  381. {
  382. for (int coreIndex = 0; coreIndex < ServerDomainConstants.PerAdcCoreCount; coreIndex++)
  383. {
  384. displayParam_Adc[adcIndex, coreIndex].bDisplay = bSelectAll;
  385. int rowIndex = adcIndex * ServerDomainConstants.PerAdcCoreCount + coreIndex;
  386. dataGridViewWaveDataView_Adc.Rows[rowIndex].Cells[1].Value = displayParam_Adc[adcIndex, coreIndex].bDisplay;
  387. }
  388. }
  389. CalcNeedDisplayCount();
  390. }
  391. private void onChannelSelectCtrl(object sender, EventArgs e)
  392. {
  393. bool bSelectAll = bool.Parse((sender as Button).Tag.ToString());
  394. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  395. {
  396. displayParam_Channel[channelIndex].bDisplay = bSelectAll;
  397. dataGridViewWaveDataView_Channel.Rows[channelIndex].Cells[1].Value = displayParam_Channel[channelIndex].bDisplay;
  398. }
  399. CalcNeedDisplayCount();
  400. }
  401. private void dataGridViewWaveDataView_Channel_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  402. {
  403. if (e.ColumnIndex != 2)
  404. return;
  405. if (colorDialog1.ShowDialog() == DialogResult.OK)
  406. {
  407. displayParam_Channel[e.RowIndex].IntColor = colorDialog1.Color.ToArgb();
  408. dataGridViewWaveDataView_Channel.Rows[e.RowIndex].Cells[2].Style.BackColor = displayParam_Channel[e.RowIndex].GetColor();
  409. dataGridViewWaveDataView_Channel.CurrentCell = dataGridViewWaveDataView_Channel.Rows[dataGridViewWaveDataView_Channel.CurrentCell.RowIndex].Cells[0];
  410. }
  411. }
  412. private void dataGridViewWaveDataView_Adc_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  413. {
  414. if (e.ColumnIndex != 2)
  415. return;
  416. if (colorDialog1.ShowDialog() == DialogResult.OK)
  417. {
  418. int adcIndex = e.RowIndex / ServerDomainConstants.PerAdcCoreCount;
  419. int coreIndex = e.RowIndex % ServerDomainConstants.PerAdcCoreCount;
  420. displayParam_Adc[adcIndex, coreIndex].IntColor = colorDialog1.Color.ToArgb();
  421. dataGridViewWaveDataView_Adc.Rows[e.RowIndex].Cells[2].Style.BackColor = displayParam_Adc[adcIndex, coreIndex].GetColor();
  422. dataGridViewWaveDataView_Adc.CurrentCell = dataGridViewWaveDataView_Adc.Rows[dataGridViewWaveDataView_Adc.CurrentCell.RowIndex].Cells[0];
  423. }
  424. }
  425. private int currTopRowIndexofChannel = 0;
  426. private int currTopRowIndexofAdc = 0;
  427. private void dataGridViewWaveDataView_Adc_RowEnter(object sender, DataGridViewCellEventArgs e)
  428. {
  429. currTopRowIndexofAdc = e.RowIndex;
  430. RedrawAtStopMode();
  431. }
  432. private bool bAtStopMode => buttonADCRunStop.Tag.ToString() == "stop";
  433. private void dataGridViewWaveDataView_Channel_RowEnter(object sender, DataGridViewCellEventArgs e)
  434. {
  435. currTopRowIndexofChannel = e.RowIndex;
  436. RedrawAtStopMode();
  437. }
  438. private void buttonADCRunStop_Click(object sender, EventArgs e)
  439. {
  440. if (buttonADCRunStop.Tag.ToString() == "stop")
  441. {
  442. buttonADCRunStop.Text = "Running";
  443. buttonADCRunStop.Tag = "run";
  444. buttonADCRunStop.BackColor = Color.Green;
  445. }
  446. else
  447. {
  448. buttonADCRunStop.Text = "Stopped";
  449. buttonADCRunStop.Tag = "stop";
  450. buttonADCRunStop.BackColor = Color.Tomato;
  451. }
  452. }
  453. private void ReadrawAtStopMode(object sender, EventArgs e)
  454. {
  455. RedrawAtStopMode();
  456. }
  457. private void buttonSaveChannelData_Click(object sender, EventArgs e)
  458. {
  459. if (CurrInstrument == null)
  460. {
  461. MessageBox.Show("请先连接目标示波器!");
  462. return;
  463. }
  464. int selectCount = 0;
  465. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  466. {
  467. if (displayParam_Channel[channelIndex].bDisplay)
  468. selectCount++;
  469. }
  470. if (selectCount==0)
  471. {
  472. MessageBox.Show("请先钩选需要保存的通道!");
  473. return;
  474. }
  475. if (this.folderBrowserDialog1.ShowDialog() != DialogResult.OK)
  476. return;
  477. string nowTimeStr = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
  478. string path = this.folderBrowserDialog1.SelectedPath;
  479. if (path[path.Length - 1] != '\\')
  480. path = path + '\\';
  481. List<ushort[]> allChannelData = InstrumentInteract.Factory_WaveData_Channel(CurrInstrument);
  482. for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
  483. {
  484. if (displayParam_Channel[channelIndex].bDisplay)
  485. {
  486. using (StreamWriter sw = new StreamWriter($"{path}CH{channelIndex + 1}_{nowTimeStr}.txt", false, Encoding.UTF8))
  487. {
  488. int len = allChannelData[channelIndex].Length;
  489. for (int i = 0; i < len; i++)
  490. sw.WriteLine(allChannelData[channelIndex][i]);
  491. }
  492. }
  493. }
  494. }
  495. }
  496. }