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.
87 lines
2.7 KiB
87 lines
2.7 KiB
using System;
|
|
using System.IO.Ports;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using leak_test_project.Utils;
|
|
|
|
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();
|
|
cbLeftPort.ItemsSource = ports;
|
|
cbRightPort.ItemsSource = ports;
|
|
cbSensorPort.ItemsSource = ports;
|
|
|
|
// 기존 설정 포트 자동 선택
|
|
cbLeftPort.SelectedItem = config.LeftPort;
|
|
cbRightPort.SelectedItem = config.RightPort;
|
|
cbSensorPort.SelectedItem = config.SensorPort;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BtnSave_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var config = ConfigManager.Current;
|
|
|
|
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 (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;
|
|
}
|
|
|
|
ConfigManager.Save();
|
|
MessageBox.Show("통신 설정이 저장되었습니다.");
|
|
this.DialogResult = true;
|
|
this.Close();
|
|
}
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
|