| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296 |
- using ivf_tl_CustomControls;
- using ivf_tl_Entity.CameraEntitys;
- using ivf_tl_Entity.GlobalEnums;
- using ivf_tl_Operate.Debug;
- using ivf_tl_Operate.ViewModel;
- using ivf_tl_Operate.Windows;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net.Sockets;
- using System.Runtime.ConstrainedExecution;
- using System.Security.Cryptography;
- using System.Security.Policy;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Media.Media3D;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ivf_tl_Operate.View
- {
- /// <summary>
- /// HouseDebugPageView.xaml 的交互逻辑
- /// </summary>
- public partial class HouseDebugPageView : UserControl
- {
- //private HouseDebugPageViewModel vm { get { return (HouseDebugPageViewModel)DataContext; } }
- private HouseDebugPageViewModel vm = null;
- /// <summary>
- /// 实时图像打开状态
- /// </summary>
- private bool isOpen = false;
- /// <summary>D2-02 第二阶段:MJPEG 预览客户端(一次性,每次开预览 new 新实例)。</summary>
- private MjpegStreamClient _mjpeg;
- private object locker = new object();
- //#bdbdbd #bfd87d
- public HouseDebugPageView(HouseDebugPageViewModel houseDebugPageViewModel)
- {
- try
- {
- InitializeComponent();
- vm = houseDebugPageViewModel;
- this.DataContext = vm;
- Loaded += HouseDebugPageView_Loaded;
- }
- catch (Exception ex)
- {
- ExLog(ex, "HouseDebugPageView");
- }
- }
- #region 通用设置
- private void HouseDebugPageView_Loaded(object sender, RoutedEventArgs e)
- {
- vm.MessageEvent += AddMessageInfo;
- vm.OpenVideoEvent += OpenVideo;
- vm.AddPicEvent += AddPic;
- foreach (var item in vm.HouseList)
- {
- switch (item.houseSn)
- {
- case 1:
- this._houseCCD1.Text = item.ccdId.ToString();
- break;
- case 2:
- this._houseCCD2.Text = item.ccdId.ToString();
- break;
- case 3:
- this._houseCCD3.Text = item.ccdId.ToString();
- break;
- case 4:
- this._houseCCD4.Text = item.ccdId.ToString();
- break;
- case 5:
- this._houseCCD5.Text = item.ccdId.ToString();
- break;
- case 6:
- this._houseCCD6.Text = item.ccdId.ToString();
- break;
- case 7:
- this._houseCCD7.Text = item.ccdId.ToString();
- break;
- case 8:
- this._houseCCD8.Text = item.ccdId.ToString();
- break;
- case 9:
- this._houseCCD9.Text = item.ccdId.ToString();
- break;
- case 10:
- this._houseCCD10.Text = item.ccdId.ToString();
- break;
- }
- }
- }
- private void RefshInfo()
- {
- Dispatcher.Invoke(() =>
- {
- var aa = vm.houseWellSettingList.FirstOrDefault(x => x.houseSn == vm.CurrentHouseId && x.wellSn == vm.CurrentWell);
- if (aa == null)
- {
- this._well_TextBlock.Text = "0";
- this._eepromPosition.Text = "0";
- }
- else
- {
- this._well_TextBlock.Text = aa.horizontalMotorPosition.ToString();
- this._eepromPosition.Text = aa.eepromClearPosition.ToString();
- }
- var bb = vm.ccdPhoto.FirstOrDefault(x => x.houseSn == vm.CurrentHouseId && x.wellSn == vm.CurrentWell);
- if (bb == null)
- {
- this._autoFocus.Text = "0";
- this._ccdOne.Text = "0";
- }
- else
- {
- this._autoFocus.Text = bb.autoFocusPosition.ToString();
- this._ccdOne.Text = bb.clearestPosition.ToString();
- }
- });
- }
- DateTime logTime = DateTime.Now;
- private void AddMessageInfo(string message)
- {
- lock (locker)
- {
- logTime = DateTime.Now;
- message = $"{logTime.ToString("yyyy-MM-dd HH:mm:ss")}.{logTime.Millisecond}{message}";
- Dispatcher.Invoke(() =>
- {
- vm.MessageInfoList.Add(message);
- _messageList.ScrollIntoView(message);
- });
- }
- }
- private void AddPic(string fileName, int well, int focal)
- {
- Dispatcher.Invoke(() =>
- {
- if (!File.Exists(fileName))
- {
- AddMessageInfo($"图片不存在:{fileName}");
- return;
- }
- string imageUrl = $"file:\\{fileName}";
- var imageSource = AppData.Instance.ConvertHelper.StringToBitmapImage(imageUrl);
- if (imageSource == null)
- {
- AddMessageInfo($"图片加载失败:{fileName}");
- return;
- }
- Canvas canvas = new Canvas();
- _warpPanelPictures.Children.Add(canvas);
- TextBlock text = new TextBlock();
- Image image = new Image();
- canvas.Children.Add(image);
- canvas.Children.Add(text);
- canvas.Margin = new Thickness(20, 5, 20, 0);
- canvas.Width = 300;
- canvas.Height = 330;
- text.Text = $"well{well} - {focal}";
- text.FontSize = 22;
- text.Foreground = new SolidColorBrush(Color.FromRgb(181, 184, 189));
- Canvas.SetLeft(text, 80);
- Canvas.SetTop(text, 302);
- image.Width = 300;
- image.Height = 300;
- image.Source = imageSource;
- image.Tag = imageUrl;
- //image.MouseUp += (s, arg) =>
- //{
- // text.Foreground = new SolidColorBrush(Colors.Red);
- // PhotoListWindow win2 = new PhotoListWindow(_warpPanelPictures.Children, image, text);
- // win2.ShowDialog();
- //};
- });
- }
- /// <summary>
- /// 打开图像
- /// </summary>
- private void OpenVideo()
- {
- try
- {
- if (isOpen) { AddMessageInfo($"图像已打开"); return; }
- string sessionId = vm.CurrentSessionId;
- if (string.IsNullOrEmpty(sessionId)) { AddMessageInfo("未借用会话,无法预览(请先初始化)"); return; }
- // 每次开预览 new 新实例(MjpegStreamClient 一次性,不可复用)
- var client = new MjpegStreamClient(ivf_tl_Operate.Helpers.ControlClient.BaseUrl);
- _mjpeg = client;
- client.FrameReceived += img => Dispatcher.Invoke(() =>
- {
- if (_mjpeg != client) return; // 已被 CloseVideo 换/清,丢弃残帧(避免关画面后残帧写回)
- _previewImage.Source = img;
- });
- client.Stopped += reason => Dispatcher.Invoke(() =>
- {
- if (_mjpeg != client) return; // 旧实例的 Stopped 不串台到新会话
- isOpen = false;
- AddMessageInfo($"⚠ {reason}"); // 明确提示操作人员手动重开(不自动重连)
- });
- client.Start(sessionId);
- isOpen = true;
- AddMessageInfo("图像已打开(MJPEG 实时预览)");
- }
- catch (Exception ex)
- {
- ExLog(ex, "OpenVideo");
- AddMessageInfo($"图像打开异常:{ex.Message}");
- }
- }
- private void CloseVideo()
- {
- try
- {
- if (!isOpen) { AddMessageInfo($"图像未打开,无需关闭"); return; }
- _mjpeg?.Stop();
- _mjpeg = null; // 丢弃实例(一次性,下次开预览 new 新的)
- Dispatcher.Invoke(() => { _previewImage.Source = null; });
- isOpen = false;
- AddMessageInfo("图像已关闭");
- }
- catch (Exception ex)
- {
- ExLog(ex, "CloseVideo");
- AddMessageInfo($"图像关闭异常:{ex.Message}");
- }
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"HouseDebugPageView.{name}", LogEnum.RunException);
- }
- private void ShowMessageDefeat(string mess)
- {
- Dispatcher.Invoke(() =>
- {
- MessageBox.Show(mess);
- });
- //AddMessageInfo(mess);
- //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, mess);
- }
- private void ShowMessage(string mess)
- {
- }
- private void ShowMessageSuccess(string mess)
- {
- new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, mess);
- }
- #endregion
- private void Return_Click(object sender, RoutedEventArgs e)
- {
- CloseVideo();
- vm.ComHouseUnit();
- SettingPageView settingPageView = new SettingPageView();
- AppData.Instance.MainWindow.LoadPage(settingPageView);
- }
- private void House_Checked(object sender, RoutedEventArgs e)
- {
- if (vm == null) return;
- if (!(sender is RadioButtonNoFrame radioButtonNoFrame)) return;
- vm.CurrentHouseId = int.Parse(radioButtonNoFrame.Tag.ToString());
- vm.CurrentHouse = vm.HouseList.First(x => x.houseSn == vm.CurrentHouseId);
- }
- private void CCD_Checked(object sender, RoutedEventArgs e)
- {
- if (vm == null) return;
- if (!(sender is RadioButtonNoFrame radioButtonNoFrame)) return;
- string ccdidString = radioButtonNoFrame.Tag.ToString();
- vm.CurrentCCDId = int.Parse(ccdidString);
- this._ccdId_TextBlock.Text = ccdidString;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private async void Start_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- this._house_StackPanel.IsEnabled = false;
- this._ccd_StackPanel.IsEnabled = false;
- this._startButton.IsEnabled = false;
- //await Task.Delay(3000 * 5);
- //return;
- await vm.ComHouseInit();
- RefshInfo();
- OpenVideo();
- this._button1.IsEnabled = true;
- this._button2.IsEnabled = true;
- this._button3.IsEnabled = true;
- this._button4.IsEnabled = true;
- this._button5.IsEnabled = true;
- this._button6.IsEnabled = true;
- this._button7.IsEnabled = true;
- this._button90.IsEnabled = true;
- this._button100.IsEnabled = true;
- this._stackPanel1.IsEnabled = true;
- this._stackPanel2.IsEnabled = true;
- this._stackPanel3.IsEnabled = true;
- this._stackPanel4.IsEnabled = true;
- }
- catch (Exception ex)
- {
- ExLog(ex, "Start_Click");
- }
- }
- /// <summary>
- /// 读E方
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RedE_Click(object sender, RoutedEventArgs e)
- {
- }
- /// <summary>
- /// 读温度
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RedTem_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.RedTem();
- });
- }
- /// <summary>
- /// 读压力
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RedPre_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.RedPre();
- });
- }
- /// <summary>
- /// 读舱门
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RedDoor_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.RedDoor();
- });
- }
- /// <summary>
- /// 开灯
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OpenLed_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.OpenLed();
- });
- }
- /// <summary>
- /// 关灯
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CloseLed_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.CloseLed();
- });
- }
- /// <summary>
- /// 卸载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End_Click(object sender, RoutedEventArgs e)
- {
- if (isOpen)
- {
- CloseVideo();
- }
- vm.IsStop = true;
- vm.ComHouseUnit();
- this._house_StackPanel.IsEnabled = true;
- this._ccd_StackPanel.IsEnabled = true;
- this._startButton.IsEnabled = true;
- this._button1.IsEnabled = false;
- this._button2.IsEnabled = false;
- this._button3.IsEnabled = false;
- this._button4.IsEnabled = false;
- this._button5.IsEnabled = false;
- this._button6.IsEnabled = false;
- this._button7.IsEnabled = false;
- this._button90.IsEnabled = false;
- this._button100.IsEnabled = false;
- this._stackPanel1.IsEnabled = false;
- this._stackPanel2.IsEnabled = false;
- this._stackPanel3.IsEnabled = false;
- this._stackPanel4.IsEnabled = false;
- }
- /// <summary>
- /// 打开进气阀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OpenIntake_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.OpenIntake();
- });
- }
- /// <summary>
- /// 关闭进气阀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CloseIntake_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.CloseIntake();
- });
- }
- /// <summary>
- /// 打开排气阀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OpenExhaust_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.OpenExhaust();
- });
- }
- /// <summary>
- /// 关闭排气阀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CloseExhaust_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.CloseExhaust();
- });
- }
- private void Aeration_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.HouseAeration();
- });
- }
- /// <summary>
- /// 写舱室进气阀时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void WriteOpenIntakeTime_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("未获取到对应的舱室信息");
- return;
- }
- string timeString = this._openIntakeTime_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(timeString))
- {
- ShowMessageDefeat("请输入进气阀打开时间");
- return;
- }
- if (int.TryParse(timeString, out int value) && value >= 0)
- {
- Task.Run(() =>
- {
- vm.WriteOpenIntakeTime(value);
- if (vm.CurrentHouse != null)
- {
- vm.CurrentHouse.inletValveOpeningTime = value;
- vm.SetHouseInfo();
- }
- });
- }
- else
- {
- ShowMessageDefeat("进气阀打开时间只能输入大于等于0数字");
- return;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "WriteOpenIntakeTime_Click");
- }
- }
- /// <summary>
- /// 写曝光时间
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SetExposure_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("未获取到对应的舱室信息");
- return;
- }
- if (int.TryParse(this._exposure_TextBox.Text.Trim(), out int newExposure) && newExposure >= 0)
- {
- vm.SetExposure(newExposure);
- if (vm.CurrentHouse != null)
- {
- vm.CurrentHouse.ccdExposure = newExposure;
- vm.SetHouseInfo();
- }
- return;
- }
- ShowMessageDefeat("曝光值只能输入大于等于0数字");
- return;
- }
- catch (Exception ex)
- {
- ExLog(ex, "SetExposure_Click");
- }
- }
- /// <summary>
- /// 水平电机复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void HorizontalMotorReset_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.HorizontalMotorReset();
- RefshInfo();
- });
- }
- /// <summary>
- /// 保存当前well水平电机位置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveWellHorizontalMotor_Click(object sender, RoutedEventArgs e)
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("未获取到对应的舱室信息");
- return;
- }
- Task.Run(() =>
- {
- try
- {
- vm.SaveWellHor();
- if (!vm.SetWellMotorPosition())
- {
- ShowMessageDefeat("数据库保存失败");
- return;
- }
- var aa = vm.houseWellSettingList.FirstOrDefault(x => x.houseSn == vm.CurrentHouseId && x.wellSn == vm.CurrentWell);
- if (aa != null)
- {
- aa.horizontalMotorPosition = vm.CurrentHor;
- Dispatcher.Invoke(() =>
- {
- this._well_TextBlock.Text = aa.horizontalMotorPosition.ToString();
- });
- }
- else
- {
- ShowMessageDefeat("未获取到well位置");
- return;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "SaveWellHorizontalMotor_Click");
- }
- });
- }
- /// <summary>
- /// 水平电机正向移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void HorizontalMotorForward_Click(object sender, RoutedEventArgs e)
- {
- string forwardString = this._horizontalMotorForward_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(forwardString))
- {
- MessageBox.Show("请输入正向移动脉冲");
- return;
- }
- if (int.TryParse(forwardString, out int value))
- {
- Task.Run(() =>
- {
- vm.HorizontalMotorForward(value);
- });
- }
- else
- {
- MessageBox.Show("正向移动脉冲只能输入数字");
- return;
- }
- }
- /// <summary>
- /// 水平电机反向运动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void HorizontalMotorBackward_Click(object sender, RoutedEventArgs e)
- {
- string backwardString = this._horizontalMotorBackward_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(backwardString))
- {
- MessageBox.Show("请输入反向移动脉冲");
- return;
- }
- if (int.TryParse(backwardString, out int value))
- {
- Task.Run(() =>
- {
- vm.HorizontalMotorBackward(value);
- });
- }
- else
- {
- MessageBox.Show("反向移动脉冲只能输入数字");
- return;
- }
- }
- /// <summary>
- /// 水平电机移动到指定Well
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void HorizontalMotorToWell_Click(object sender, RoutedEventArgs e)
- {
- string wellString = this._horizontalMotorToWell_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(wellString))
- {
- ShowMessageDefeat("请输入目标well");
- return;
- }
- if (int.TryParse(wellString, out int value) && value >= 1 && value <= 16)
- {
- Task.Run(() =>
- {
- vm.HorizontalMotorToWell(value);
- RefshInfo();
- });
- }
- else
- {
- ShowMessageDefeat("目标well只能输入1-16的数字");
- return;
- }
- }
- /// <summary>
- /// 下一well
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void HorizontalMotorNextWell_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.HorizontalMotorToWell(vm.CurrentWell + 1);
- RefshInfo();
- });
- }
- /// <summary>
- /// 垂直电机复位
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void VerticalMotorResetWait_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.VerticalMotorReset();
- vm.CurrentFocal = 0;
- });
- }
- /// <summary>
- /// 垂直电机正向移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void VerticalMotorForward_Click(object sender, RoutedEventArgs e)
- {
- string forwardString = this._verticalMotorForward_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(forwardString))
- {
- MessageBox.Show("请输入正向移动脉冲");
- return;
- }
- if (int.TryParse(forwardString, out int value))
- {
- Task.Run(() =>
- {
- vm.VerticalMotorForward(value);
- });
- }
- else
- {
- MessageBox.Show("正向移动脉冲只能输入数字");
- return;
- }
- }
- /// <summary>
- /// 垂直电机反向运动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void VerticalMotorBackward_Click(object sender, RoutedEventArgs e)
- {
- string backwardString = this._verticalMotorBackward_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(backwardString))
- {
- MessageBox.Show("请输入反向移动脉冲");
- return;
- }
- if (int.TryParse(backwardString, out int value))
- {
- Task.Run(() =>
- {
- vm.VerticalMotorBackward(value);
- });
- }
- else
- {
- MessageBox.Show("反向移动脉冲只能输入数字");
- return;
- }
- }
- /// <summary>
- /// 垂直电机绝对运动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void VerticalMotorAbsolute_Click(object sender, RoutedEventArgs e)
- {
- string absoluteString = this._verticalMotorAbsolute_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(absoluteString))
- {
- MessageBox.Show("请输入目标脉冲");
- return;
- }
- if (int.TryParse(absoluteString, out int value) && value >= 0 && value <= vm.tLSetting.verticalMotorPulseMax)
- {
- Task.Run(() =>
- {
- vm.VerticalMotorAbsolute(value);
- });
- }
- else
- {
- MessageBox.Show($"目标脉冲只能输入0-{vm.tLSetting.verticalMotorPulseMax}的数字");
- return;
- }
- }
- /// <summary>
- /// 保存垂直电机间隔脉冲
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveVerSpacePulse_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("未获取到对应的舱室信息");
- return;
- }
- if (int.TryParse(this._verticalMotorForward_TextBox.Text.Trim(), out int newValue) && newValue > 0 && newValue <= vm.tLSetting.verticalMotorPulseMax)
- {
- Task.Run(() =>
- {
- vm.WriteOVerSpace(newValue);
- vm.CurrentHouse.verticalMotorSpacePulse = newValue;
- vm.SetHouseInfo();
- });
- }
- else
- {
- AddMessageInfo($"垂直电机间隔脉冲只能输入0-{vm.tLSetting.verticalMotorPulseMax}的数字");
- }
- }
- catch (Exception ex)
- {
- AddMessageInfo($"保存垂直电机间隔脉冲异常:{ex.Message}");
- ExLog(ex, "SaveVerSpacePulse_Click");
- }
- }
- /// <summary>
- /// 清空
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Clear_Click(object sender, RoutedEventArgs e)
- {
- vm.MessageInfoList.Clear();
- this._warpPanelPictures.Children.Clear();
- }
- /// <summary>
- /// 一键电机准备
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Motor_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.MototReady();
- });
- }
- /// <summary>
- /// 单张抓拍
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GetPic_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!isOpen)
- {
- AddMessageInfo("开启实时图像以后才可以拍照");
- return;
- }
- if (vm.CurrentHouse == null)
- {
- AddMessageInfo("获取舱室信息失败");
- return;
- }
- string path = AppData.Instance.LogHelper.GetDeBugDanZhangDirectory(vm.CurrentHouse.houseSn, vm.CurrentWell);
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- string fullName = $"{path}house{vm.CurrentHouse.houseSn}_{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff")}_{vm.CurrentHor}-{vm.CurrentVer}.jpg";
- if (!vm.SavePic(fullName)) return;
- AddPic(fullName, vm.CurrentWell, vm.CurrentFocal);
- }
- catch (Exception ex)
- {
- ExLog(ex, "GetPic_Click");
- AddMessageInfo($"单张抓拍异常:{ex.Message}");
- }
- }
- /// <summary>
- /// 水平抓拍
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ShuiPingPic_Click(object sender, RoutedEventArgs e)
- {
- if (vm.CurrentHouse == null)
- {
- AddMessageInfo("获取舱室信息失败");
- return;
- }
- if (!isOpen)
- {
- AddMessageInfo("开启实时图像以后才可以拍照");
- return;
- }
- Task.Run(() =>
- {
- vm.ShuiPingZhuaPai();
- });
- }
- /// <summary>
- /// 结束抓图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EndPic_Click(object sender, RoutedEventArgs e)
- {
- vm.IsStop = true;
- }
- /// <summary>
- /// 清晰图层抓图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private async void AutoFocus_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败");
- return;
- }
- if (int.TryParse(this._autoFocusNum_TextBox.Text.Trim(), out int autoFocusNum) && autoFocusNum > 0 && int.TryParse(this._autoFocus_TextBox.Text.Trim(), out int xun) && xun > 0)
- {
- this._auto_Button.IsEnabled = false;
- await vm.AutoFocusPic(autoFocusNum, xun);
- this._auto_Button.IsEnabled = true;
- }
- else
- {
- ShowMessageDefeat($"请输入正确的拍摄次数以及循环次数");
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "AutoFocus_Click");
- AddMessageInfo($"清晰图层抓图异常:{ex.Message}");
- }
- }
- private void CloseVideo_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- CloseVideo();
- }
- catch (Exception ex)
- {
- ExLog(ex, "CloseVideo_Click");
- AddMessageInfo($"图像关闭异常:{ex.Message}");
- }
- }
- /// <summary>
- /// M2-05 场景A 一键全自动标定(沙盒)。对选中 well(默认 16 well)逐个跑四步标定,
- /// 合格绿/伪峰红实时显示,结果作出厂基准 scene=0 存档 + 写 calibration.json。
- /// 硬件复用调试页已借用并打开的 comBin/camera(经适配器暴露为 HAL 接口),不二次 Open/Init。
- /// </summary>
- private async void OneClickCalibrate_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败,请先初始化舱室");
- return;
- }
- if (vm.IsCalibrating)
- {
- AddMessageInfo("[一键标定]已在标定中");
- return;
- }
- this._oneClickCalib_Button.IsEnabled = false;
- try
- {
- // 沙盒默认全 16 well 逐个跑(如需勾选子集,传入选中 well 列表即可)。
- await vm.OneClickCalibrate(null);
- }
- finally
- {
- this._oneClickCalib_Button.IsEnabled = true;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "OneClickCalibrate_Click");
- AddMessageInfo($"一键标定异常:{ex.Message}");
- }
- }
- /// <summary>M2-05 中止一键标定(当前 well 结束后停止,已完成结果保留)。</summary>
- private void StopCalibrate_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- vm.StopCalibrate();
- }
- catch (Exception ex)
- {
- ExLog(ex, "StopCalibrate_Click");
- }
- }
- /// <summary>
- /// M2-07 载入选定 well 当前生效的拍摄层配置(well 级覆盖优先,空则显示继承的设备级值占位),
- /// 回填三个手调框并触发一次预览。
- /// </summary>
- private void LoadManualTune_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败,请先初始化舱室");
- return;
- }
- if (vm.ManualTuneWell < 1 || vm.ManualTuneWell > 16)
- {
- ShowMessageDefeat("well 只能为 1-16");
- return;
- }
- vm.LoadManualLayerSetting(vm.ManualTuneWell);
- }
- catch (Exception ex)
- {
- ExLog(ex, "LoadManualTune_Click");
- }
- }
- /// <summary>
- /// M2-07 实时预览:用该 well 标定 FocusZ + 当前手调值调 M2-02 ComputeLayerPositions 算各层 Z(关联 V-045)。
- /// </summary>
- private void PreviewManualTune_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败,请先初始化舱室");
- return;
- }
- vm.PreviewManualLayers();
- }
- catch (Exception ex)
- {
- ExLog(ex, "PreviewManualTune_Click");
- }
- }
- /// <summary>
- /// M2-07 存为该 well 默认:校验通过后写 house_well_setting well 级覆盖
- /// (focus_layer_spacing_pulse/focus_layer_count + 复用 move_down_layer),留空继承设备级。
- /// </summary>
- private void SaveManualTune_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败,请先初始化舱室");
- return;
- }
- if (vm.SaveManualLayerTune())
- {
- ShowMessageSuccess("手调拍摄层已存为该 well 默认");
- }
- else
- {
- ShowMessageDefeat("手调拍摄层保存失败(见日志,可能为非法值或接口失败)");
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "SaveManualTune_Click");
- }
- }
- private void OpenVideo_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- OpenVideo();
- }
- catch (Exception ex)
- {
- ExLog(ex, "OpenVideo_Click");
- AddMessageInfo($"图像打开异常:{ex.Message}");
- }
- }
- /// <summary>
- /// 保存自动对焦起点
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveAutoFocus_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.SetWellAutoFocus())
- {
- var bb = vm.ccdPhoto.FirstOrDefault(x => x.houseSn == vm.CurrentHouseId && x.wellSn == vm.CurrentWell);
- if (bb != null) bb.autoFocusPosition = vm.CurrentVer;
- this._autoFocus.Text = vm.CurrentVer.ToString();
- AddMessageInfo($"自动对焦起点保存成功");
- }
- else
- {
- AddMessageInfo($"自动对焦起点保存失败");
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "SaveAutoFocus_Click");
- AddMessageInfo($"保存自动对焦起点异常:{ex.Message}");
- }
- }
- private void _autoFocusNum_TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- TextBox passwordBox = sender as TextBox;
- if (passwordBox == null) return;
- string ss = passwordBox.Text.Trim();
- if (string.IsNullOrEmpty(ss))
- {
- passwordBox.Background = (VisualBrush)this.FindResource("HelpBrush2");
- }
- else
- {
- passwordBox.Background = new SolidColorBrush(Colors.White);
- }
- }
- private void _autoFocus_TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- TextBox passwordBox = sender as TextBox;
- if (passwordBox == null) return;
- string ss = passwordBox.Text.Trim();
- if (string.IsNullOrEmpty(ss))
- {
- passwordBox.Background = (VisualBrush)this.FindResource("HelpBrush3");
- }
- else
- {
- passwordBox.Background = new SolidColorBrush(Colors.White);
- }
- }
- private void Paiqi_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.HouseVent();
- });
- }
- private void WriteOpenVentTime_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("未获取到对应的舱室信息");
- return;
- }
- string timeString = this._openVentTime_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(timeString))
- {
- ShowMessageDefeat("请输入排气阀打开时间");
- return;
- }
- if (int.TryParse(timeString, out int value) && value >= 0)
- {
- Task.Run(() =>
- {
- vm.WriteOpenVentTime(value);
- //if (vm.CurrentHouse != null)
- //{
- // vm.CurrentHouse.inletValveOpeningTime = value;
- // vm.SetHouseInfo();
- //}
- });
- }
- else
- {
- ShowMessageDefeat("排气阀打开时间只能输入大于等于0数字");
- return;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "WriteOpenVentTime_Click");
- }
- }
- private void ReadOpenVentTime_Click(object sender, RoutedEventArgs e)
- {
- Task.Run(() =>
- {
- vm.RedVentTime();
- });
- }
- }
- }
|