123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using CliWrap;
- using DevExpress.XtraEditors;
- using Ips.Library.Basic;
- using Ips.Library.DxpLib;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Ips.Adc.WadTool
- {
- public partial class MainWin : DevExpress.XtraEditors.XtraForm
- {
- public MainWin()
- {
- InitializeComponent();
- txtZqTime.UseTimeEdit();
- txtResZqTime.UseTimeEdit();
- btnStopAd.Enabled = false;
- //58 20230329171753 133439000
- txtZqs.Value = 58;
- txtZqTime.DateTime = new DateTime(2023, 03, 29, 17, 17, 53);
- txtZqTimeNs.Value = 133439000;
- }
- const long smallZq = 300810240L;
- static readonly string CliFile = Path.Combine(Application.StartupPath, "ipscli", "wgsadg", "wgsadg.exe");
- CancellationTokenSource _cts;
- private async void btnStartAd_Click(object sender, EventArgs e)
- {
- _cts?.Dispose();
- _cts = new CancellationTokenSource();
- int mutil = (int)txtMutil.Value;
- DateTime startTime = txtResZqTime.DateTime;
- int startNs = (int)txtResZqTimeNs.Value;
- int startPos = (int)(startNs * 1e-9m * (1001e6m / mutil));
- txtStartPos.Text = startPos.ToString();
- var cmd = Cli.Wrap(CliFile).WithArguments($"-s {DateTimeUtil.To1970s(startTime)} -n {startNs} -m {mutil}")
- .WithStandardOutputPipe(PipeTarget.ToDelegate(line => IpsLogger.Info(line)))
- .WithStandardErrorPipe(PipeTarget.ToDelegate(line => IpsLogger.Error(line)));
- btnStartAd.Enabled = false;
- btnStopAd.Enabled = true;
- try
- {
- await cmd.ExecuteAsync(_cts.Token);
- }
- catch (Exception ex)
- {
- ex.HandleCancelEx(normalEx =>
- {
- IpsLogger.Error("启用采集出错", normalEx);
- }, cancelEx =>
- {
- IpsLogger.Info("采集已停止!");
- });
- }
- finally
- {
- btnStartAd.Enabled = true;
- btnStopAd.Enabled = false;
- }
- }
- private void txtResZqs_EditValueChanged(object sender, EventArgs e)
- {
- int zqs = (int)txtZqs.Value;
- DateTime zqTime = txtZqTime.DateTime;
- long zqns = long.Parse(txtZqTimeNs.Text);
- int resZqs = (int)txtResZqs.Value;
- var tns1 = (resZqs - zqs) * smallZq;
- var tns2 = zqns + tns1;
- var sec = (int)Math.Floor(tns2 / 1e9);
- var resZqTime = zqTime.AddSeconds(sec);
- var resZqNs = tns2 - (long)(sec * 1e9);
- txtResZqTime.DateTime = resZqTime;
- txtResZqTimeNs.Value = resZqNs;
- }
- private void MainWin_Load(object sender, EventArgs e)
- {
- EditorHelper.LoadEditorFromAppConfig(this);
- }
- private void MainWin_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- EditorHelper.SaveEditorToAppConfig(this);
- }
- catch (Exception ex)
- {
- MsgHelper.ShowMsg("保存界面参数出错," + ex.Message);
- }
- }
- private void btnStopAd_Click(object sender, EventArgs e)
- {
- _cts?.Cancel();
- }
- }
- }
|