|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// 사용 가능한 시리얼 포트 목록 조회
|
|
|
|
|
string[] ports = SerialPort.GetPortNames();
|
|
|
|
|
cbSensorPort.ItemsSource = ports;
|
|
|
|
|
cbBoard4251Port.ItemsSource = ports;
|
|
|
|
|
|
|
|
|
|
// 기존 설정 포트 자동 선택
|
|
|
|
|
cbSensorPort.SelectedItem = config.SensorPort;
|
|
|
|
|
cbBoard4251Port.SelectedItem = config.Board4251Port;
|
|
|
|
|
|
|
|
|
|
foreach (ComboBoxItem item in cbSensorBaudRate.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item.Content.ToString() == config.SensorBaudRate.ToString())
|
|
|
|
|
{
|
|
|
|
|
cbSensorBaudRate.SelectedItem = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (ComboBoxItem item in cbBoard4251BaudRate.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item.Content.ToString() == config.Board4251BaudRate.ToString())
|
|
|
|
|
{
|
|
|
|
|
cbBoard4251BaudRate.SelectedItem = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnSave_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var config = ConfigManager.Current;
|
|
|
|
|
|
|
|
|
|
if (cbSensorPort.SelectedItem != null)
|
|
|
|
|
config.SensorPort = cbSensorPort.SelectedItem.ToString();
|
|
|
|
|
|
|
|
|
|
if (cbBoard4251Port.SelectedItem != null)
|
|
|
|
|
config.Board4251Port = cbBoard4251Port.SelectedItem.ToString();
|
|
|
|
|
if (cbSensorBaudRate.SelectedItem is ComboBoxItem sensorBaud)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(sensorBaud.Content.ToString(), out int baud))
|
|
|
|
|
config.SensorBaudRate = baud;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbBoard4251BaudRate.SelectedItem is ComboBoxItem boardBaud)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(boardBaud.Content.ToString(), out int baud))
|
|
|
|
|
config.Board4251BaudRate = baud;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConfigManager.Save();
|
|
|
|
|
MessageBox.Show("통신 설정이 저장되었습니다.");
|
|
|
|
|
this.DialogResult = true;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|