| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360 |
- 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");
- }
- }
- /// <summary>D2-02-T3.5 载入选定 well 当前 well 级对焦半幅覆盖值(空=继承设备级)。</summary>
- private void LoadFocusRange_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.LoadWellFocusRange(vm.ManualTuneWell);
- }
- catch (Exception ex)
- {
- ExLog(ex, "LoadFocusRange_Click");
- }
- }
- /// <summary>D2-02-T3.5 保存该 well 对焦搜索半幅(写 house_well_setting well 级覆盖,留空继承设备级)。</summary>
- private void SaveFocusRange_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm.CurrentHouse == null)
- {
- ShowMessageDefeat("获取舱室信息失败,请先初始化舱室");
- return;
- }
- if (vm.SaveWellFocusRange())
- {
- ShowMessageSuccess("对焦搜索半幅已保存为该 well 覆盖");
- }
- else
- {
- ShowMessageDefeat("对焦半幅保存失败(见日志,可能为非法值或接口失败)");
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "SaveFocusRange_Click");
- }
- }
- /// <summary>D2-02-T3.4 逐孔微调:对该格 well 经 control 协作单孔重标。</summary>
- private async void RecalibrateWell_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!(sender is FrameworkElement fe) || fe.Tag == null) return;
- if (!int.TryParse(fe.Tag.ToString(), out int well)) return;
- await vm.RecalibrateWell(well);
- }
- catch (Exception ex)
- {
- ExLog(ex, "RecalibrateWell_Click");
- AddMessageInfo($"单孔重标异常:{ex.Message}");
- }
- }
- 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();
- });
- }
- }
- }
|