리크 테스트 gui
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
3.8 KiB

using System;
using System.IO.Ports;
using System.Windows;
using System.Windows.Controls;
using leak_test_project.Utils;
using leak_test_project.Models;
namespace leak_test_project.Views
{
public partial class CommunicationWindow : Window
{
public CommunicationWindow()
{
InitializeComponent();
LoadSettings();
}
private void LoadSettings()
{
var config = ConfigManager.Current;
// ID 센서 타입 선택
cbIdSensorType.SelectedIndex = (int)config.SelectedIdSensor;
// 사용 가능한 시리얼 포트 목록 조회
string[] ports = SerialPort.GetPortNames();
cbLeftPort.ItemsSource = ports;
cbRightPort.ItemsSource = ports;
cbSensorPort.ItemsSource = ports;
cbBoard4253Port.ItemsSource = ports;
// 기존 설정 포트 자동 선택
cbLeftPort.SelectedItem = config.LeftPort;
cbRightPort.SelectedItem = config.RightPort;
cbSensorPort.SelectedItem = config.SensorPort;
cbBoard4253Port.SelectedItem = config.Board4253Port;
foreach (ComboBoxItem item in cbZmdiBaudRate.Items)
{
if (item.Content.ToString() == config.ZmdiBaudRate.ToString())
{
cbZmdiBaudRate.SelectedItem = item;
break;
}
}
foreach (ComboBoxItem item in cbSensorBaudRate.Items)
{
if (item.Content.ToString() == config.SensorBaudRate.ToString())
{
cbSensorBaudRate.SelectedItem = item;
break;
}
}
foreach (ComboBoxItem item in cbBoard4253BaudRate.Items)
{
if (item.Content.ToString() == config.Board4253BaudRate.ToString())
{
cbBoard4253BaudRate.SelectedItem = item;
break;
}
}
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
var config = ConfigManager.Current;
if (cbIdSensorType.SelectedIndex >= 0)
config.SelectedIdSensor = (IdSensorType)cbIdSensorType.SelectedIndex;
if (cbLeftPort.SelectedItem != null)
config.LeftPort = cbLeftPort.SelectedItem.ToString();
if (cbRightPort.SelectedItem != null)
config.RightPort = cbRightPort.SelectedItem.ToString();
if (cbSensorPort.SelectedItem != null)
config.SensorPort = cbSensorPort.SelectedItem.ToString();
if (cbBoard4253Port.SelectedItem != null)
config.Board4253Port = cbBoard4253Port.SelectedItem.ToString();
if (cbZmdiBaudRate.SelectedItem is ComboBoxItem zmdiBaud)
{
if (int.TryParse(zmdiBaud.Content.ToString(), out int baud))
config.ZmdiBaudRate = baud;
}
if (cbSensorBaudRate.SelectedItem is ComboBoxItem sensorBaud)
{
if (int.TryParse(sensorBaud.Content.ToString(), out int baud))
config.SensorBaudRate = baud;
}
if (cbBoard4253BaudRate.SelectedItem is ComboBoxItem boardBaud)
{
if (int.TryParse(boardBaud.Content.ToString(), out int baud))
config.Board4253BaudRate = baud;
}
ConfigManager.Save();
MessageBox.Show("통신 설정이 저장되었습니다.");
this.DialogResult = true;
this.Close();
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}