| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- using ivf_tl_CustomControls;
- using ivf_tl_Entity.CameraEntitys;
- using ivf_tl_Entity.GlobalEnums;
- 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;
- 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;
- }
- IntPtr hwnd = ((System.Windows.Interop.HwndSource)PresentationSource.FromVisual(AppData.Instance.MainWindow)).Handle;
- //var a = vm.camera.Usb2Start(hwnd, 328, 865, 800, 600);
- var a = vm.StartPreview(hwnd, 328, 805, 800, 600);
- AddMessageInfo($"图像打开结果:{a}[注:0表示成功]");
- if (a == 0)
- {
- isOpen = true;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "OpenVideo");
- AddMessageInfo($"图像打开异常:{ex.Message}");
- }
- }
- private void CloseVideo()
- {
- try
- {
- if (!isOpen)
- {
- AddMessageInfo($"图像未打开,无需关闭");
- return;
- }
- var a = vm.StopPreview();
- AddMessageInfo($"图像关闭结果:{a}[注:0表示成功]");
- if (a == 0)
- {
- isOpen = false;
- }
- }
- 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();
- });
- }
- }
- }
|