-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettingsEditor.cs
69 lines (55 loc) · 1.83 KB
/
SettingsEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.IO.Ports;
using System.Windows.Forms;
using UCNLDrivers;
namespace uWAVE_Host
{
public partial class SettingsEditor : Form
{
#region Properties
public SettingsContainer Value
{
get
{
SettingsContainer result = new SettingsContainer();
result.SetDefaults();
if (portNameCbx.SelectedItem != null)
result.PortName = portNameCbx.SelectedItem.ToString();
if (baudRateCbx.SelectedItem != null)
result.PortBaudrate = (BaudRate)Enum.Parse(typeof(BaudRate), baudRateCbx.SelectedItem.ToString());
return result;
}
set
{
int idx = -1;
idx = portNameCbx.Items.IndexOf(value.PortName);
if (idx >= 0)
portNameCbx.SelectedIndex = idx;
idx = baudRateCbx.Items.IndexOf(value.PortBaudrate.ToString());
if (idx >= 0)
baudRateCbx.SelectedIndex = idx;
}
}
#endregion
#region Constructor
public SettingsEditor()
{
InitializeComponent();
baudRateCbx.Items.AddRange(Enum.GetNames(typeof(BaudRate)));
baudRateCbx.SelectedIndex = 0;
portNameCbx.Items.AddRange(SerialPort.GetPortNames());
if (portNameCbx.Items.Count > 0)
{
portNameCbx.SelectedIndex = 0;
portNameCbx.Enabled = true;
okBtn.Enabled = true;
}
else
{
okBtn.Enabled = false;
portNameCbx.Enabled = false;
}
}
#endregion
}
}